Make setZeroTimeout use window.setTimeout

This commit is contained in:
Anthony Ramine 2018-08-27 17:54:24 +02:00
parent cb2f83cf8e
commit 6089e45b7d
21 changed files with 335 additions and 98 deletions

View file

@ -0,0 +1,40 @@
--- js/webgl-test-utils.js
+++ js/webgl-test-utils.js
@@ -2876,34 +2876,9 @@ var waitForComposite = function(callback) {
countDown();
};
-var setZeroTimeout = (function() {
- // See https://dbaron.org/log/20100309-faster-timeouts
-
- var timeouts = [];
- var messageName = "zero-timeout-message";
-
- // Like setTimeout, but only takes a function argument. There's
- // no time argument (always zero) and no arguments (you have to
- // use a closure).
- function setZeroTimeout(fn) {
- timeouts.push(fn);
- window.postMessage(messageName, "*");
- }
-
- function handleMessage(event) {
- if (event.source == window && event.data == messageName) {
- event.stopPropagation();
- if (timeouts.length > 0) {
- var fn = timeouts.shift();
- fn();
- }
- }
- }
-
- window.addEventListener("message", handleMessage, true);
-
- return setZeroTimeout;
-})();
+var setZeroTimeout = function(handler) {
+ window.setTimeout(handler, 0);
+}
/**
* Runs an array of functions, yielding to the browser between each step.