Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/adblockplus_compat.js

Issue 8893047: adblockplusopera: Fix loading race condition (Closed)
Patch Set: Created Nov. 21, 2012, 3:56 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld