From ca3fd808251a0ffd1dfab2385c35e2eb1899bf07 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 21 Feb 2022 15:45:50 -0500 Subject: [PATCH] Remove use of Promise.tap() from Bluebird and our own Promise.check() --- .../content/zotero/bindings/attachmentbox.xml | 19 +++++++++++-------- chrome/content/zotero/xpcom/zotero.js | 19 ------------------- resource/bluebird.js | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/chrome/content/zotero/bindings/attachmentbox.xml b/chrome/content/zotero/bindings/attachmentbox.xml index b605238163..b959b6720c 100644 --- a/chrome/content/zotero/bindings/attachmentbox.xml +++ b/chrome/content/zotero/bindings/attachmentbox.xml @@ -306,8 +306,9 @@ // Page count if (this.displayPages) { Zotero.Fulltext.getPages(this.item.id) - .tap(() => Zotero.Promise.check(this.item)) .then(function (pages) { + if (!this.item) return; + pages = pages ? pages.total : null; if (pages) { this._id("pages-label").value = Zotero.getString('itemFields.pages') @@ -337,8 +338,9 @@ } else { this.item.attachmentModificationTime - .tap(() => Zotero.Promise.check(this._id)) .then(function (mtime) { + if (!this._id) return; + if (mtime) { this._id("dateModified").value = new Date(mtime).toLocaleString(); } @@ -353,10 +355,10 @@ // Full-text index information if (this.displayIndexed) { this.updateItemIndexedState() - .tap(() => Zotero.Promise.check(this.item)) .then(function () { + if (!this.item) return; indexStatusRow.hidden = false; - }); + }.bind(this)); } else { indexStatusRow.hidden = true; @@ -533,8 +535,9 @@ var indexStatus = this._id('index-status'); var reindexButton = this._id('reindex'); - var status = yield Zotero.Fulltext.getIndexedState(this.item) - .tap(() => Zotero.Promise.check(this.item)); + var status = yield Zotero.Fulltext.getIndexedState(this.item); + if (!this.item) return; + var str = 'fulltext.indexState.'; switch (status) { case Zotero.Fulltext.INDEX_STATE_UNAVAILABLE: @@ -563,8 +566,8 @@ var show = false; if (this.editable) { - show = yield Zotero.Fulltext.canReindex(this.item) - .tap(() => Zotero.Promise.check(this.item)); + show = yield Zotero.Fulltext.canReindex(this.item); + if (!this.item) return; } if (show) { diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 47b17866ee..86780a02d6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -172,25 +172,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); this.uiReadyDeferred = Zotero.Promise.defer(); this.uiReadyPromise = this.uiReadyDeferred.promise; - // Add a function to Zotero.Promise to check whether a value is still defined, and if not - // to throw a specific error that's ignored by the unhandled rejection handler in - // bluebird.js. This allows for easily cancelling promises when they're no longer - // needed, for example after a binding is destroyed. - // - // Example usage: - // - // getAsync.tap(() => Zotero.Promise.check(this.mode)) - // - // If the binding is destroyed while getAsync() is being resolved and this.mode no longer - // exists, subsequent lines won't be run, and nothing will be logged to the console. - this.Promise.check = function (val) { - if (!val && val !== 0) { - let e = new Error; - e.name = "ZoteroPromiseInterrupt"; - throw e; - } - }; - if (options) { let opts = [ 'openPane', diff --git a/resource/bluebird.js b/resource/bluebird.js index 5c01e08086..4c22816cbd 100644 --- a/resource/bluebird.js +++ b/resource/bluebird.js @@ -21,7 +21,7 @@ Promise.defer = function() { } // TEMP: Only turn on if debug logging enabled? Promise.onPossiblyUnhandledRejection((e, promise) => { - if (e.name == 'ZoteroPromiseInterrupt' || e.handledRejection) { + if (e.handledRejection) { return; }