Skip to content

Commit

Permalink
Fixes race conditions when translator eval fails during detection
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Oct 26, 2023
1 parent de2e270 commit d7299a7
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/translation/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,22 +1788,22 @@ Zotero.Translate.Base.prototype = {
var parse = function(code) {
Zotero.debug("Translate: Parsing code for " + translator.label + " "
+ "(" + translator.translatorID + ", " + translator.lastUpdated + ")", 4);
try {
this._sandboxManager.eval(
"var exports = {}, ZOTERO_TRANSLATOR_INFO = " + code,
[
"detect" + this._entryFunctionSuffix,
"do" + this._entryFunctionSuffix,
"exports",
"ZOTERO_TRANSLATOR_INFO"
],
(translator.file ? translator.file.path : translator.label)
);
}
catch (e) {
this.complete(false, e);
return;
}
// This might throw but it's better than catching and calling complete(false) here
// since then other execution paths are not aware of this failing and continue running
// at least in Import translation detection, causing weird race conditions.
// The code that calls this function (which is really only code in this file)
// should expect a throw and call complete(false) after catching.
this._sandboxManager.eval(
"var exports = {}, ZOTERO_TRANSLATOR_INFO = " + code,
[
"detect" + this._entryFunctionSuffix,
"do" + this._entryFunctionSuffix,
"exports",
"ZOTERO_TRANSLATOR_INFO"
],
(translator.file ? translator.file.path : translator.label)
);

this._translatorInfo = this._sandboxManager.sandbox.ZOTERO_TRANSLATOR_INFO;
}.bind(this);

Expand Down

0 comments on commit d7299a7

Please sign in to comment.