Index: lib/utils.js |
=================================================================== |
--- a/lib/utils.js |
+++ b/lib/utils.js |
@@ -10,29 +10,31 @@ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+let runAsyncQueue = []; |
+ |
var Utils = exports.Utils = { |
systemPrincipal: null, |
getString: function(id) |
{ |
return id; |
}, |
runAsync: function(callback, thisPtr) |
{ |
- var params = Array.prototype.slice.call(arguments, 2); |
- window.setTimeout(function() |
- { |
- callback.apply(thisPtr, params); |
- }, 0); |
+ callback = callback.bind.apply(callback, Array.prototype.slice.call(arguments, 1)); |
+ if (runAsyncQueue) |
+ runAsyncQueue.push(callback); |
+ else |
+ window.setTimeout(callback, 0); |
}, |
get appLocale() |
{ |
var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); |
this.__defineGetter__("appLocale", function() {return locale}); |
return this.appLocale; |
}, |
generateChecksum: function(lines) |
@@ -99,8 +101,30 @@ var Utils = exports.Utils = { |
getDocLink: function(linkID) |
{ |
var Prefs = require("prefs").Prefs; |
var docLink = Prefs.documentation_link; |
return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale); |
} |
}; |
+ |
+Utils.runAsync.enable = function() |
+{ |
+ // Hack: Opera will happily run asynchronous actions while scripts are |
+ // loading, queue them until Utils.runAsync.enable() is called. |
+ if (!runAsyncQueue) |
+ return; |
+ |
+ let queue = runAsyncQueue; |
+ runAsyncQueue = null; |
+ for each (let callback in queue) |
+ { |
+ try |
+ { |
+ callback(); |
+ } |
+ catch(e) |
+ { |
+ Cu.reportError(e); |
+ } |
+ } |
+} |