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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 if (debug_is_active) %DebugPushPromise(deferred.promise); | 125 if (debug_is_active) %DebugPushPromise(deferred.promise); |
126 var result = handler(value); | 126 var result = handler(value); |
127 if (IS_UNDEFINED(deferred.resolve)) { | 127 if (IS_UNDEFINED(deferred.resolve)) { |
128 ResolvePromise(deferred.promise, result); | 128 ResolvePromise(deferred.promise, result); |
129 } else { | 129 } else { |
130 %_Call(deferred.resolve, UNDEFINED, result); | 130 %_Call(deferred.resolve, UNDEFINED, result); |
131 } | 131 } |
132 } %catch (exception) { // Natives syntax to mark this catch block. | 132 } %catch (exception) { // Natives syntax to mark this catch block. |
133 try { | 133 try { |
134 if (IS_UNDEFINED(deferred.reject)) { | 134 if (IS_UNDEFINED(deferred.reject)) { |
135 // Pass false for debugEvent so .then chaining does not trigger | 135 // Pass false for debugEvent so .then chaining does not trigger |
Dan Ehrenberg
2016/11/18 12:54:52
Note: this undefined case also includes async/awai
gsathya
2016/11/18 15:39:48
Done.
| |
136 // redundant ExceptionEvents. | 136 // redundant ExceptionEvents. |
137 %PromiseReject(deferred.promise, exception, false); | 137 %PromiseReject(deferred.promise, exception, false); |
138 PromiseSet(deferred.promise, kRejected, exception); | 138 PromiseSet(deferred.promise, kRejected, exception); |
139 } else { | 139 } else { |
140 %_Call(deferred.reject, UNDEFINED, exception); | 140 %_Call(deferred.reject, UNDEFINED, exception); |
141 } | 141 } |
142 } catch (e) { } | 142 } catch (e) { } |
143 } finally { | 143 } finally { |
144 if (debug_is_active) %DebugPopPromise(); | 144 if (debug_is_active) %DebugPopPromise(); |
145 } | 145 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 %PromiseReject(promise, reason, debugEvent); | 284 %PromiseReject(promise, reason, debugEvent); |
285 PromiseSet(promise, kRejected, reason); | 285 PromiseSet(promise, kRejected, reason); |
286 } | 286 } |
287 | 287 |
288 // Export to bindings | 288 // Export to bindings |
289 function DoRejectPromise(promise, reason) { | 289 function DoRejectPromise(promise, reason) { |
290 %PromiseReject(promise, reason, true); | 290 %PromiseReject(promise, reason, true); |
291 PromiseSet(promise, kRejected, reason); | 291 PromiseSet(promise, kRejected, reason); |
292 } | 292 } |
293 | 293 |
294 // The resultCapability.promise is only ever fulfilled internally, | |
295 // so we don't need the closures to protect against accidentally | |
296 // calling them multiple times. | |
297 function NewPromiseCapabilityWithoutCallbacks() { | |
Dan Ehrenberg
2016/11/18 12:54:52
Name suggestion: CreatePromiseCapability
gsathya
2016/11/18 15:39:48
Doesn't seem to convey the difference between NewP
caitp
2016/11/18 15:42:28
"CreateInternalPromiseCapability"?
| |
298 return { | |
299 promise: PromiseCreate(), | |
300 resolve: UNDEFINED, | |
301 reject: UNDEFINED | |
302 }; | |
303 } | |
304 | |
294 // ES#sec-newpromisecapability | 305 // ES#sec-newpromisecapability |
295 // NewPromiseCapability ( C ) | 306 // NewPromiseCapability ( C ) |
296 function NewPromiseCapability(C, debugEvent) { | 307 function NewPromiseCapability(C, debugEvent) { |
297 if (C === GlobalPromise) { | 308 if (C === GlobalPromise) { |
298 // Optimized case, avoid extra closure. | 309 // Optimized case, avoid extra closure. |
299 var promise = PromiseCreate(); | 310 var promise = PromiseCreate(); |
300 // TODO(gsathya): Remove container for callbacks when this is | 311 // TODO(gsathya): Remove container for callbacks when this is |
301 // moved to CPP/TF. | 312 // moved to CPP/TF. |
302 var callbacks = %create_resolving_functions(promise, debugEvent); | 313 var callbacks = %create_resolving_functions(promise, debugEvent); |
303 return { | 314 return { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 // Promise.prototype.then ( onFulfilled, onRejected ) | 385 // Promise.prototype.then ( onFulfilled, onRejected ) |
375 // Multi-unwrapped chaining with thenable coercion. | 386 // Multi-unwrapped chaining with thenable coercion. |
376 function PromiseThen(onResolve, onReject) { | 387 function PromiseThen(onResolve, onReject) { |
377 var status = GET_PRIVATE(this, promiseStateSymbol); | 388 var status = GET_PRIVATE(this, promiseStateSymbol); |
378 if (IS_UNDEFINED(status)) { | 389 if (IS_UNDEFINED(status)) { |
379 throw %make_type_error(kNotAPromise, this); | 390 throw %make_type_error(kNotAPromise, this); |
380 } | 391 } |
381 | 392 |
382 var constructor = SpeciesConstructor(this, GlobalPromise); | 393 var constructor = SpeciesConstructor(this, GlobalPromise); |
383 var resultCapability; | 394 var resultCapability; |
384 | |
385 // The resultCapability.promise is only ever fulfilled internally, | |
386 // so we don't need the closures to protect against accidentally | |
387 // calling them multiple times. | |
388 if (constructor === GlobalPromise) { | 395 if (constructor === GlobalPromise) { |
389 // TODO(gsathya): Combine this into NewPromiseCapability. | 396 resultCapability = NewPromiseCapabilityWithoutCallbacks(); |
390 resultCapability = { | |
391 promise: PromiseCreate(), | |
392 resolve: UNDEFINED, | |
393 reject: UNDEFINED | |
394 }; | |
395 } else { | 397 } else { |
396 // Pass false for debugEvent so .then chaining does not trigger | 398 // Pass false for debugEvent so .then chaining does not trigger |
397 // redundant ExceptionEvents. | 399 // redundant ExceptionEvents. |
398 resultCapability = NewPromiseCapability(constructor, false); | 400 resultCapability = NewPromiseCapability(constructor, false); |
399 } | 401 } |
402 | |
Dan Ehrenberg
2016/11/18 12:54:52
Nit: consider reverting the irrelevant whitespace
gsathya
2016/11/18 15:39:48
Done.
| |
400 return PerformPromiseThen(this, onResolve, onReject, resultCapability); | 403 return PerformPromiseThen(this, onResolve, onReject, resultCapability); |
401 } | 404 } |
402 | 405 |
403 // ES#sec-promise.prototype.catch | 406 // ES#sec-promise.prototype.catch |
404 // Promise.prototype.catch ( onRejected ) | 407 // Promise.prototype.catch ( onRejected ) |
405 function PromiseCatch(onReject) { | 408 function PromiseCatch(onReject) { |
406 return this.then(UNDEFINED, onReject); | 409 return this.then(UNDEFINED, onReject); |
407 } | 410 } |
408 | 411 |
409 // Combinators. | 412 // Combinators. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 "resolvePromise", ResolvePromise, | 637 "resolvePromise", ResolvePromise, |
635 "rejectPromise", DoRejectPromise | 638 "rejectPromise", DoRejectPromise |
636 ]); | 639 ]); |
637 | 640 |
638 utils.Export(function(to) { | 641 utils.Export(function(to) { |
639 to.IsPromise = IsPromise; | 642 to.IsPromise = IsPromise; |
640 to.PromiseCreate = PromiseCreate; | 643 to.PromiseCreate = PromiseCreate; |
641 to.PromiseThen = PromiseThen; | 644 to.PromiseThen = PromiseThen; |
642 | 645 |
643 to.GlobalPromise = GlobalPromise; | 646 to.GlobalPromise = GlobalPromise; |
644 to.NewPromiseCapability = NewPromiseCapability; | 647 to.NewPromiseCapabilityWithoutCallbacks = |
648 NewPromiseCapabilityWithoutCallbacks; | |
645 to.PerformPromiseThen = PerformPromiseThen; | 649 to.PerformPromiseThen = PerformPromiseThen; |
646 to.ResolvePromise = ResolvePromise; | 650 to.ResolvePromise = ResolvePromise; |
647 to.RejectPromise = RejectPromise; | 651 to.RejectPromise = RejectPromise; |
648 }); | 652 }); |
649 | 653 |
650 }) | 654 }) |
OLD | NEW |