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); + } }; } }