Don't allow functions queued with setTimeout() to execute during Zotero.wait()
Fixes fatal error during import
This commit is contained in:
parent
58a3680ca5
commit
3f69b8b9c0
|
@ -176,6 +176,11 @@ var Zotero = new function(){
|
||||||
var _progressMeters;
|
var _progressMeters;
|
||||||
var _lastPercentage;
|
var _lastPercentage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of nsITimerCallbacks to be executed when Zotero.wait() completes
|
||||||
|
*/
|
||||||
|
var _waitTimerCallbacks = [];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the extension
|
* Initialize the extension
|
||||||
*/
|
*/
|
||||||
|
@ -1365,10 +1370,39 @@ var Zotero = new function(){
|
||||||
|
|
||||||
_waiting = false;
|
_waiting = false;
|
||||||
|
|
||||||
|
// requeue nsITimerCallbacks that came up during Zotero.wait() but couldn't execute
|
||||||
|
for each(var timerCallback in _waitTimerCallbacks) {
|
||||||
|
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||||
|
createInstance(Components.interfaces.nsITimer);
|
||||||
|
timer.initWithCallback(timerCallback, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||||
|
}
|
||||||
|
|
||||||
//Zotero.debug("Waited " + cycles + " cycles");
|
//Zotero.debug("Waited " + cycles + " cycles");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emulates the behavior of window.setTimeout, but ensures that timeouts do not get called
|
||||||
|
* during Zotero.wait()
|
||||||
|
*
|
||||||
|
* @param {Function} func The function to be called
|
||||||
|
* @param {Integer} ms The number of milliseconds to wait before calling func
|
||||||
|
*/
|
||||||
|
this.setTimeout = function(func, ms) {
|
||||||
|
var timer = Components.classes["@mozilla.org/timer;1"].
|
||||||
|
createInstance(Components.interfaces.nsITimer);
|
||||||
|
var timerCallback = {"notify":function() {
|
||||||
|
if(_waiting) {
|
||||||
|
// if our callback gets called during Zotero.wait(), queue it to be set again
|
||||||
|
// when Zotero.wait() complets
|
||||||
|
_waitTimerCallbacks.push(timerCallback);
|
||||||
|
} else {
|
||||||
|
// otherwise, execute callback function
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
timer.initWithCallback(timerCallback, ms, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show Zotero pane overlay and progress bar in all windows
|
* Show Zotero pane overlay and progress bar in all windows
|
||||||
|
|
|
@ -214,14 +214,8 @@ function confirm(msg){
|
||||||
/**
|
/**
|
||||||
* Convenience method to replicate window.setTimeout()
|
* Convenience method to replicate window.setTimeout()
|
||||||
**/
|
**/
|
||||||
// TODO: is this still used? if so, move to zotero.js
|
function setTimeout(func, ms) {
|
||||||
function setTimeout(func, ms){
|
Zotero.setTimeout(func, ms);
|
||||||
var timer = Components.classes["@mozilla.org/timer;1"].
|
|
||||||
createInstance(Components.interfaces.nsITimer);
|
|
||||||
// {} implements nsITimerCallback
|
|
||||||
timer.initWithCallback({notify:func}, ms,
|
|
||||||
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
|
||||||
return timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user