From d035c94ae327505ced01ec7c141f61ca91ff44a0 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 1 Jul 2025 16:51:37 -0400 Subject: [PATCH] Add functional shim for Zotero.Promise.method() For translation. --- chrome/content/zotero/xpcom/bluebirdShim.mjs | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/bluebirdShim.mjs b/chrome/content/zotero/xpcom/bluebirdShim.mjs index 88a82c2b26..9e9d3c48b6 100644 --- a/chrome/content/zotero/xpcom/bluebirdShim.mjs +++ b/chrome/content/zotero/xpcom/bluebirdShim.mjs @@ -13,10 +13,29 @@ export class BluebirdShimPromise extends Promise { } static method(fn) { - // TEMP: "Implement" this with a stub until we update zotero/translate - // Don't bother with synchronous resolution - this is just enough to get the client to load + // ONLY exists for translator code that needs synchronous resolution. + // Please don't use this anywhere else. It's a bad idea! return function (...args) { - return Promise.resolve(fn.apply(this, args)); + try { + let returnValue = fn.apply(this, args); + let promise; + let isResolved = false; + if (returnValue && returnValue.then) { + promise = returnValue; + } + else { + promise = Promise.resolve(returnValue); + isResolved = true; + } + if (typeof promise.isResolved === 'undefined') { + promise.then(() => isResolved = true, () => {}); + promise.isResolved = () => isResolved; + } + return promise; + } + catch (e) { + return Promise.reject(e); + } }; } }