From 0a9fad41246f098c3dad1cc72bdaaf634350e371 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 23 Jul 2012 21:22:17 -0400 Subject: [PATCH] Use setTimeout() on hidden window instead of firing an nsITimer to prevent our JS from getting interpreted instead of JITed. Still need to make sure this doesn't break things on other platforms. Closes #149, Fix JITing for initial pane load --- chrome/content/zotero/xpcom/zotero.js | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 8ed06fe1d8..511b3a3da6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1473,10 +1473,8 @@ Components.utils.import("resource://gre/modules/Services.jsm"); this.pumpGenerator = function(generator, ms, errorHandler, doneHandler) { _waiting++; - var timer = Components.classes["@mozilla.org/timer;1"]. - createInstance(Components.interfaces.nsITimer), - yielded; - var timerCallback = {"notify":function() { + var win = Services.appShell.hiddenDOMWindow; + var intervalID = win.setInterval(function() { var err = false; _waiting--; try { @@ -1490,8 +1488,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); err = e; } - timer.cancel(); - _runningTimers.splice(_runningTimers.indexOf(timer), 1); + win.clearInterval(intervalID); // requeue nsITimerCallbacks that came up during generator pumping but couldn't execute for(var i in _waitTimers) { @@ -1509,10 +1506,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); } else if(doneHandler) { doneHandler(yielded); } - }} - 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); + }, ms); }; /** @@ -1536,9 +1530,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); * is executing */ this.setTimeout = function(func, ms, runWhenWaiting) { - var timer = Components.classes["@mozilla.org/timer;1"]. - createInstance(Components.interfaces.nsITimer); - var timerCallback = {"notify":function() { + Services.appShell.hiddenDOMWindow.setTimeout(function() { if(_waiting && !runWhenWaiting) { // if our callback gets called during Zotero.wait(), queue it to be set again // when Zotero.wait() completes @@ -1547,13 +1539,8 @@ 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); } - }} - 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); + }, ms); } /**