Index: src/v8natives.js |
diff --git a/src/v8natives.js b/src/v8natives.js |
index df663c025e927a79222e031ab8eee14d004f67a8..e4f0a3b8600acd10e51fa09f44ad371438066806 100644 |
--- a/src/v8natives.js |
+++ b/src/v8natives.js |
@@ -1889,10 +1889,30 @@ SetUpFunction(); |
// Eventually, we should move to a real event queue that allows to maintain |
// relative ordering of different kinds of tasks. |
-RunMicrotasks.runners = new InternalArray; |
+function GetMicrotaskQueue() { |
+ var microtaskState = %GetMicrotaskState(); |
+ if (IS_UNDEFINED(microtaskState.queue)) { |
+ microtaskState.queue = new InternalArray; |
+ } |
+ return microtaskState.queue; |
+} |
function RunMicrotasks() { |
while (%SetMicrotaskPending(false)) { |
- for (var i in RunMicrotasks.runners) RunMicrotasks.runners[i](); |
+ var microtaskState = %GetMicrotaskState(); |
+ if (IS_UNDEFINED(microtaskState.queue)) |
+ return; |
+ |
+ var microtasks = microtaskState.queue; |
+ microtaskState.queue = new InternalArray; |
+ |
+ for (var i = 0; i < microtasks.length; i++) { |
+ microtasks[i](); |
+ } |
} |
} |
+ |
+function EnqueueExternalMicrotask(fn) { |
+ GetMicrotaskQueue().push(fn); |
+ %SetMicrotaskPending(true); |
+} |