Revert "Use setTimeout() on hidden window instead of firing an nsITimer to prevent our JS from getting interpreted instead of JITed."
This reverts commit 0a9fad4124
.
This commit is contained in:
parent
6f86d85f89
commit
344bd1fb74
|
@ -1473,8 +1473,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
this.pumpGenerator = function(generator, ms, errorHandler, doneHandler) {
|
||||
_waiting++;
|
||||
|
||||
var win = Services.appShell.hiddenDOMWindow;
|
||||
var intervalID = win.setInterval(function() {
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||
createInstance(Components.interfaces.nsITimer),
|
||||
yielded;
|
||||
var timerCallback = {"notify":function() {
|
||||
var err = false;
|
||||
_waiting--;
|
||||
try {
|
||||
|
@ -1488,7 +1490,8 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
err = e;
|
||||
}
|
||||
|
||||
win.clearInterval(intervalID);
|
||||
timer.cancel();
|
||||
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
||||
|
||||
// requeue nsITimerCallbacks that came up during generator pumping but couldn't execute
|
||||
for(var i in _waitTimers) {
|
||||
|
@ -1506,7 +1509,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
} else if(doneHandler) {
|
||||
doneHandler(yielded);
|
||||
}
|
||||
}, ms);
|
||||
}}
|
||||
timer.initWithCallback(timerCallback, ms ? ms : 0, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
||||
// add timer to global scope so that it doesn't get garbage collected before it completes
|
||||
_runningTimers.push(timer);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1530,7 +1536,9 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
* is executing
|
||||
*/
|
||||
this.setTimeout = function(func, ms, runWhenWaiting) {
|
||||
Services.appShell.hiddenDOMWindow.setTimeout(function() {
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||
createInstance(Components.interfaces.nsITimer);
|
||||
var timerCallback = {"notify":function() {
|
||||
if(_waiting && !runWhenWaiting) {
|
||||
// if our callback gets called during Zotero.wait(), queue it to be set again
|
||||
// when Zotero.wait() completes
|
||||
|
@ -1539,8 +1547,13 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
} else {
|
||||
// execute callback function
|
||||
func();
|
||||
// remove timer from global scope, so it can be garbage collected
|
||||
_runningTimers.splice(_runningTimers.indexOf(timer), 1);
|
||||
}
|
||||
}, ms);
|
||||
}}
|
||||
timer.initWithCallback(timerCallback, ms, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||
// add timer to global scope so that it doesn't get garbage collected before it completes
|
||||
_runningTimers.push(timer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user