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

Unified Diff: lib/utils.js

Issue 5173395171835904: Issue 2264 - Remove deprecated logic from Utils.runAsync() on Chrome/Opera/Safari (Closed)
Patch Set: Created April 2, 2015, 10:26 a.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 | « lib/storage/io.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/utils.js
===================================================================
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -15,8 +15,6 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-let runAsyncQueue;
-
var Utils = exports.Utils = {
systemPrincipal: null,
getString: function(id)
@@ -26,47 +24,23 @@
else
return id;
},
-
- // This function can take additional parameters. Second paramater will be
- // passed as this variable to the callback and any additional parameters as
- // callback parameters.
runAsync: function(callback)
{
- callback = callback.bind.apply(callback, Array.prototype.slice.call(arguments, 1));
-
- if (typeof runAsyncQueue == "undefined")
+ if (document.readyState == "loading")
{
- runAsyncQueue = (document.readyState == "loading" ? [] : null);
- if (runAsyncQueue)
+ // Make sure to not run asynchronous actions before all
+ // scripts loaded. This caused issues on Opera in the past.
+ let onDOMContentLoaded = function()
{
- // Hack: Opera will happily run asynchronous actions while scripts are
- // loading, queue them until the document is ready.
- let loadHandler = function()
- {
- document.removeEventListener("DOMContentLoaded", loadHandler, false);
-
- let queue = runAsyncQueue;
- runAsyncQueue = null;
- for (let callback of queue)
- {
- try
- {
- callback();
- }
- catch(e)
- {
- Cu.reportError(e);
- }
- }
- };
- document.addEventListener("DOMContentLoaded", loadHandler, false);
- }
+ document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
+ callback();
+ };
+ document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
}
-
- if (runAsyncQueue)
- runAsyncQueue.push(callback);
else
- window.setTimeout(callback, 0);
+ {
+ setTimeout(callback, 0);
+ }
},
get appLocale()
{
« no previous file with comments | « lib/storage/io.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld