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, 2:47 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)
@@ -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);
Wladimir Palant 2012/11/21 15:47:58 setTimeout(..., 0)?
Felix Dahlke 2012/11/21 15:56:56 You're right. This only worked because the readySt
+ 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