Index: lib/adblockplus_compat.js |
=================================================================== |
--- a/lib/adblockplus_compat.js |
+++ b/lib/adblockplus_compat.js |
@@ -147,8 +147,8 @@ |
readFromFile: function(file, decode, listener, callback, timeLineID) |
{ |
- // Fake asynchronous execution |
- setTimeout(function() |
+ var Utils = require("utils").Utils; |
+ Utils.runAsync(function() |
{ |
if ("spec" in file && /^defaults\b/.test(file.spec)) |
{ |
@@ -173,7 +173,7 @@ |
listener.process(lines[i]); |
listener.process(null); |
callback(null); |
- }.bind(this), 0); |
+ }.bind(this)); |
}, |
writeToFile: function(file, encode, data, callback, timeLineID) |
@@ -181,8 +181,8 @@ |
var path = this._getFilePath(file); |
this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Date.now()); |
- // Fake asynchronous execution |
- setTimeout(callback.bind(null, null), 0); |
+ var Utils = require("utils").Utils; |
+ Utils.runAsync(callback, null, null); |
}, |
copyFile: function(fromFile, toFile, callback) |
@@ -308,10 +308,16 @@ |
runAsync: function(callback, thisPtr) |
{ |
var params = Array.prototype.slice.call(arguments, 2); |
- window.setTimeout(function() |
+ |
+ function invokeCallback() |
{ |
callback.apply(thisPtr, params); |
- }, 0); |
+ } |
+ |
+ if (document.readyState === "complete") |
+ window.setTimeout(invokeCallback, 0); |
+ else |
+ window.addEventListener("load", invokeCallback); |
}, |
get appLocale() |
{ |