Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 } | 78 } |
| 79 if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this); | 79 if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this); |
| 80 if (!IS_CALLABLE(resolver)) { | 80 if (!IS_CALLABLE(resolver)) { |
| 81 throw MakeTypeError(kResolverNotAFunction, resolver); | 81 throw MakeTypeError(kResolverNotAFunction, resolver); |
| 82 } | 82 } |
| 83 | 83 |
| 84 var promise = PromiseInit(%_NewObject(GlobalPromise, new.target)); | 84 var promise = PromiseInit(%_NewObject(GlobalPromise, new.target)); |
| 85 var callbacks = CreateResolvingFunctions(promise); | 85 var callbacks = CreateResolvingFunctions(promise); |
| 86 | 86 |
| 87 try { | 87 try { |
| 88 %DebugPushPromise(promise, Promise); | 88 if (DEBUG_IS_ACTIVE) %DebugPushPromise(promise, Promise); |
|
Dan Ehrenberg
2016/05/18 00:34:46
Other functions in this file store DEBUG_IS_ACTIVE
gsathya
2016/05/18 00:50:06
I've used a local var called "debug_is_active" whi
| |
| 89 resolver(callbacks.resolve, callbacks.reject); | 89 resolver(callbacks.resolve, callbacks.reject); |
| 90 } catch (e) { | 90 } catch (e) { |
| 91 %_Call(callbacks.reject, UNDEFINED, e); | 91 %_Call(callbacks.reject, UNDEFINED, e); |
| 92 } finally { | 92 } finally { |
| 93 %DebugPopPromise(); | 93 if (DEBUG_IS_ACTIVE) %DebugPopPromise(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 return promise; | 96 return promise; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Core functionality. | 99 // Core functionality. |
| 100 | 100 |
| 101 function PromiseSet(promise, status, value, onResolve, onReject) { | 101 function PromiseSet(promise, status, value, onResolve, onReject) { |
| 102 SET_PRIVATE(promise, promiseStateSymbol, status); | 102 SET_PRIVATE(promise, promiseStateSymbol, status); |
| 103 SET_PRIVATE(promise, promiseResultSymbol, value); | 103 SET_PRIVATE(promise, promiseResultSymbol, value); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 121 function PromiseDone(promise, status, value, promiseQueue) { | 121 function PromiseDone(promise, status, value, promiseQueue) { |
| 122 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { | 122 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { |
| 123 var tasks = GET_PRIVATE(promise, promiseQueue); | 123 var tasks = GET_PRIVATE(promise, promiseQueue); |
| 124 if (tasks.length) PromiseEnqueue(value, tasks, status); | 124 if (tasks.length) PromiseEnqueue(value, tasks, status); |
| 125 PromiseSet(promise, status, value); | 125 PromiseSet(promise, status, value); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 function PromiseHandle(value, handler, deferred) { | 129 function PromiseHandle(value, handler, deferred) { |
| 130 try { | 130 try { |
| 131 %DebugPushPromise(deferred.promise, PromiseHandle); | 131 if (DEBUG_IS_ACTIVE) %DebugPushPromise(deferred.promise, PromiseHandle); |
| 132 var result = handler(value); | 132 var result = handler(value); |
| 133 deferred.resolve(result); | 133 deferred.resolve(result); |
| 134 } catch (exception) { | 134 } catch (exception) { |
| 135 try { deferred.reject(exception); } catch (e) { } | 135 try { deferred.reject(exception); } catch (e) { } |
| 136 } finally { | 136 } finally { |
| 137 %DebugPopPromise(); | 137 if (DEBUG_IS_ACTIVE) %DebugPopPromise(); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 function PromiseEnqueue(value, tasks, status) { | 141 function PromiseEnqueue(value, tasks, status) { |
| 142 var id, name, instrumenting = DEBUG_IS_ACTIVE; | 142 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
| 143 %EnqueueMicrotask(function() { | 143 %EnqueueMicrotask(function() { |
| 144 if (instrumenting) { | 144 if (instrumenting) { |
| 145 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | 145 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
| 146 } | 146 } |
| 147 for (var i = 0; i < tasks.length; i += 2) { | 147 for (var i = 0; i < tasks.length; i += 2) { |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 to.PromiseChain = PromiseChain; | 518 to.PromiseChain = PromiseChain; |
| 519 to.PromiseDefer = PromiseDefer; | 519 to.PromiseDefer = PromiseDefer; |
| 520 to.PromiseAccept = PromiseAccept; | 520 to.PromiseAccept = PromiseAccept; |
| 521 | 521 |
| 522 to.PromiseCreateRejected = PromiseCreateRejected; | 522 to.PromiseCreateRejected = PromiseCreateRejected; |
| 523 to.PromiseCreateResolved = PromiseCreateResolved; | 523 to.PromiseCreateResolved = PromiseCreateResolved; |
| 524 to.PromiseThen = PromiseThen; | 524 to.PromiseThen = PromiseThen; |
| 525 }); | 525 }); |
| 526 | 526 |
| 527 }) | 527 }) |
| OLD | NEW |