Index: src/promise.js |
diff --git a/src/promise.js b/src/promise.js |
index db7863f8098f686cab2fc4545eab1429165797fc..82aa99027a1305ac8bf6b95672cccd89504173cd 100644 |
--- a/src/promise.js |
+++ b/src/promise.js |
@@ -173,37 +173,29 @@ function PromiseCatch(onReject) { |
} |
function PromiseEnqueue(value, tasks) { |
- promiseEvents.push(value, tasks); |
+ GetMicrotaskQueue().push(function() { |
+ for (var i = 0; i < tasks.length; i += 2) { |
+ PromiseHandle(value, tasks[i], tasks[i + 1]) |
+ } |
+ }); |
+ |
%SetMicrotaskPending(true); |
} |
-function PromiseMicrotaskRunner() { |
- var events = promiseEvents; |
- if (events.length > 0) { |
- promiseEvents = new InternalArray; |
- for (var i = 0; i < events.length; i += 2) { |
- var value = events[i]; |
- var tasks = events[i + 1]; |
- for (var j = 0; j < tasks.length; j += 2) { |
- var handler = tasks[j]; |
- var deferred = tasks[j + 1]; |
- try { |
- var result = handler(value); |
- if (result === deferred.promise) |
- throw MakeTypeError('promise_cyclic', [result]); |
- else if (IsPromise(result)) |
- result.chain(deferred.resolve, deferred.reject); |
- else |
- deferred.resolve(result); |
- } catch(e) { |
- // TODO(rossberg): perhaps log uncaught exceptions below. |
- try { deferred.reject(e) } catch(e) {} |
- } |
- } |
- } |
+function PromiseHandle(value, handler, deferred) { |
+ try { |
+ var result = handler(value); |
+ if (result === deferred.promise) |
+ throw MakeTypeError('promise_cyclic', [result]); |
+ else if (IsPromise(result)) |
+ result.chain(deferred.resolve, deferred.reject); |
+ else |
+ deferred.resolve(result); |
+ } catch(e) { |
+ // TODO(rossberg): perhaps log uncaught exceptions below. |
+ try { deferred.reject(e) } catch(e) {} |
} |
} |
-RunMicrotasks.runners.push(PromiseMicrotaskRunner); |
// Multi-unwrapped chaining with thenable coercion. |