From ca833f54fc9b9371e4e76e73ffb9c92a5e249705 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 6 Sep 2016 02:17:20 -0400 Subject: [PATCH] Fix noWait translation mode (broken by e3a9c6779bc) --- .../zotero/xpcom/translation/translate.js | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 9f1d966c35..b6b8550760 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1262,25 +1262,29 @@ Zotero.Translate.Base.prototype = { this.translator[0] = Zotero.Translators.get(this.translator[0]); } - // Zotero.Translators.get() returns a promise in the connectors - if (this.noWait && this.translator[0].then && !this.translator[0].isResolved()) { - throw new Error("Translator promise is not resolved in noWait mode"); + // Zotero.Translators.get() returns a promise in the connectors, but we don't expect it to + // otherwise + if (!this.isConnector && this.translator[0].then) { + throw new Error("Translator should not be a promise in non-connector mode"); } - Zotero.Promise.resolve(this.translator[0]) - .then(function (translator) { - this.translator[0] = translator; - var loadPromise = this._loadTranslator(translator); - if (this.noWait) { - if (!loadPromise.isResolved()) { - return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode")); - } - this._translateTranslatorLoaded(); + if (this.noWait) { + var loadPromise = this._loadTranslator(this.translator[0]); + if (!loadPromise.isResolved()) { + return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode")); } - else { - loadPromise.then(() => this._translateTranslatorLoaded()); - } - }.bind(this)); + this._translateTranslatorLoaded(); + } + else if (this.translator[0].then) { + Zotero.Promise.resolve(this.translator[0]) + .then(function (translator) { + this.translator[0] = translator; + this._loadTranslator(translator).then(() => this._translateTranslatorLoaded()); + }.bind(this)); + } + else { + this._loadTranslator(this.translator[0]).then(() => this._translateTranslatorLoaded()); + } return deferred.promise; }),