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() |
{ |