From d797c7a4d8026357f2d7ab79b04bec254ce10f42 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 29 Jul 2025 00:47:33 -0400 Subject: [PATCH] BluebirdShimPromise: Add value() and fix isResolved() semantics - value() is used in noWait export translation - isResolved() technically means fulfilled or rejected -- unclear if we ever depended on that, but it might as well be correct --- chrome/content/zotero/xpcom/bluebirdShim.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/bluebirdShim.mjs b/chrome/content/zotero/xpcom/bluebirdShim.mjs index 9e9d3c48b6..1ea22ed5a7 100644 --- a/chrome/content/zotero/xpcom/bluebirdShim.mjs +++ b/chrome/content/zotero/xpcom/bluebirdShim.mjs @@ -20,17 +20,33 @@ export class BluebirdShimPromise extends Promise { let returnValue = fn.apply(this, args); let promise; let isResolved = false; + let isFulfilled = false; if (returnValue && returnValue.then) { promise = returnValue; } else { promise = Promise.resolve(returnValue); isResolved = true; + isFulfilled = true; } if (typeof promise.isResolved === 'undefined') { - promise.then(() => isResolved = true, () => {}); + promise.then( + () => { + isResolved = true; + isFulfilled = true; + }, + () => isResolved = true + ); promise.isResolved = () => isResolved; } + if (promise.value === undefined) { + promise.value = () => { + if (!isFulfilled) { + throw new Error("value() called on unfulfilled promise"); + } + return returnValue; + }; + } return promise; } catch (e) {