From 6ef9a061f3770932a46b965bf79fd097a8aeb3fb Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 6 Jun 2013 19:38:48 -0400 Subject: [PATCH] Only use Components.utils.methodjit when supported As Boris Zbarsky pointed out in https://bugzilla.mozilla.org/show_bug.cgi?id=878679, the setTimeout() hack doesn't help in Firefox 23 and later. For now we use the useMethodjit hack when available, so that performance won't regress for Firefox 23, and cross our fingers that https://bugzilla.mozilla.org/show_bug.cgi?id=776798 is fixed for Firefox 24. --- chrome/content/zotero/xpcom/http.js | 27 ++++++++++++++++++--------- chrome/content/zotero/xpcom/zotero.js | 6 ++++-- resource/q.js | 3 ++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index fec534de7..2ae32769f 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -249,7 +249,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, onDone, responseCharset); }; @@ -337,7 +338,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, onDone, responseCharset); }; @@ -401,7 +403,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, onDone); }; @@ -440,7 +443,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, callback); }; xmlhttp.send(null); @@ -482,7 +486,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, function (xmlhttp) { Zotero.debug("Proxy auth request completed with status " + xmlhttp.status + ": " + xmlhttp.responseText); @@ -561,7 +566,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, callback); }; @@ -597,7 +603,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, callback); }; xmlhttp.send(null); @@ -642,7 +649,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, callback); }; xmlhttp.send(body); @@ -681,7 +689,8 @@ Zotero.HTTP = new function() { var useMethodjit = Components.utils.methodjit; /** @ignore */ xmlhttp.onreadystatechange = function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; _stateChange(xmlhttp, callback); }; xmlhttp.send(null); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 70c786e17..4497229dd 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1545,7 +1545,8 @@ Components.utils.import("resource://gre/modules/Services.jsm"); yielded, useJIT = Components.utils.methodjit; var timerCallback = {"notify":function() { - Components.utils.methodjit = useJIT; + // XXX Remove when we drop support for Fx <24 + if(useJIT !== undefined) Components.utils.methodjit = useJIT; var err = false; _waiting--; @@ -1610,7 +1611,8 @@ Components.utils.import("resource://gre/modules/Services.jsm"); createInstance(Components.interfaces.nsITimer), useJIT = Components.utils.methodjit; var timerCallback = {"notify":function() { - Components.utils.methodjit = useJIT; + // XXX Remove when we drop support for Fx <24 + if(useJIT !== undefined) Components.utils.methodjit = useJIT; if(_waiting && !runWhenWaiting) { // if our callback gets called during Zotero.wait(), queue it to be set again diff --git a/resource/q.js b/resource/q.js index 029b5bedd..f73a91336 100644 --- a/resource/q.js +++ b/resource/q.js @@ -70,7 +70,8 @@ timer = Components.classes["@mozilla.org/timer;1"]. createInstance(Components.interfaces.nsITimer); timer.initWithCallback({"notify":function() { - Components.utils.methodjit = useMethodjit; + // XXX Remove when we drop support for Fx <24 + if(useMethodjit !== undefined) Components.utils.methodjit = useMethodjit; // Remove timer from array so it can be garbage collected _runningTimers.splice(_runningTimers.indexOf(timer), 1);