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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return promise; | 82 return promise; |
83 } | 83 } |
84 | 84 |
85 // Core functionality. | 85 // Core functionality. |
86 | 86 |
87 function PromiseSet(promise, status, value, onResolve, onReject) { | 87 function PromiseSet(promise, status, value, onResolve, onReject) { |
88 SET_PRIVATE(promise, promiseStatusSymbol, status); | 88 SET_PRIVATE(promise, promiseStatusSymbol, status); |
89 SET_PRIVATE(promise, promiseValueSymbol, value); | 89 SET_PRIVATE(promise, promiseValueSymbol, value); |
90 SET_PRIVATE(promise, promiseOnResolveSymbol, onResolve); | 90 SET_PRIVATE(promise, promiseOnResolveSymbol, onResolve); |
91 SET_PRIVATE(promise, promiseOnRejectSymbol, onReject); | 91 SET_PRIVATE(promise, promiseOnRejectSymbol, onReject); |
92 if (DEBUG_IS_ACTIVE) { | |
93 %DebugPromiseEvent({ promise: promise, status: status, value: value }); | |
94 } | |
95 return promise; | 92 return promise; |
96 } | 93 } |
97 | 94 |
98 function PromiseCreateAndSet(status, value) { | 95 function PromiseCreateAndSet(status, value) { |
99 var promise = new GlobalPromise(promiseRawSymbol); | 96 var promise = new GlobalPromise(promiseRawSymbol); |
100 // If debug is active, notify about the newly created promise first. | 97 // If debug is active, notify about the newly created promise first. |
101 if (DEBUG_IS_ACTIVE) PromiseSet(promise, 0, UNDEFINED); | 98 if (DEBUG_IS_ACTIVE) PromiseSet(promise, 0, UNDEFINED); |
102 return PromiseSet(promise, status, value); | 99 return PromiseSet(promise, status, value); |
103 } | 100 } |
104 | 101 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // Revoke previously triggered reject event. | 296 // Revoke previously triggered reject event. |
300 %PromiseRevokeReject(this); | 297 %PromiseRevokeReject(this); |
301 } | 298 } |
302 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol), | 299 PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol), |
303 [onReject, deferred], | 300 [onReject, deferred], |
304 -1); | 301 -1); |
305 break; | 302 break; |
306 } | 303 } |
307 // Mark this promise as having handler. | 304 // Mark this promise as having handler. |
308 SET_PRIVATE(this, promiseHasHandlerSymbol, true); | 305 SET_PRIVATE(this, promiseHasHandlerSymbol, true); |
309 if (DEBUG_IS_ACTIVE) { | |
310 %DebugPromiseEvent({ promise: deferred.promise, parentPromise: this }); | |
311 } | |
312 return deferred.promise; | 306 return deferred.promise; |
313 } | 307 } |
314 | 308 |
315 // Chain is left around for now as an alias for then | 309 // Chain is left around for now as an alias for then |
316 function PromiseChain(onResolve, onReject) { | 310 function PromiseChain(onResolve, onReject) { |
317 %IncrementUseCounter(kPromiseChain); | 311 %IncrementUseCounter(kPromiseChain); |
318 return %_Call(PromiseThen, this, onResolve, onReject); | 312 return %_Call(PromiseThen, this, onResolve, onReject); |
319 } | 313 } |
320 | 314 |
321 function PromiseCatch(onReject) { | 315 function PromiseCatch(onReject) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 466 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
473 fn => %FunctionRemovePrototype(fn)); | 467 fn => %FunctionRemovePrototype(fn)); |
474 | 468 |
475 utils.Export(function(to) { | 469 utils.Export(function(to) { |
476 to.PromiseChain = PromiseChain; | 470 to.PromiseChain = PromiseChain; |
477 to.PromiseDeferred = PromiseDeferred; | 471 to.PromiseDeferred = PromiseDeferred; |
478 to.PromiseResolved = PromiseResolved; | 472 to.PromiseResolved = PromiseResolved; |
479 }); | 473 }); |
480 | 474 |
481 }) | 475 }) |
OLD | NEW |