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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 return promiseCapability.promise; | 379 return promiseCapability.promise; |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 // Shortcut Promise.reject and Promise.resolve() implementations, used by | 383 // Shortcut Promise.reject and Promise.resolve() implementations, used by |
| 384 // Async Functions implementation. | 384 // Async Functions implementation. |
| 385 function PromiseCreateRejected(r) { | 385 function PromiseCreateRejected(r) { |
| 386 return %_Call(PromiseReject, GlobalPromise, r); | 386 return %_Call(PromiseReject, GlobalPromise, r); |
| 387 } | 387 } |
| 388 | 388 |
| 389 function PromiseCreateResolved(x) { | 389 function PromiseCreateResolved(value) { |
| 390 return %_Call(PromiseResolve, GlobalPromise, x); | 390 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); |
| 391 var resolveResult = ResolvePromise(promise, value); | |
| 392 return promise; | |
| 393 } | |
| 394 | |
| 395 function PromiseCastResolved(value) { | |
|
caitp
2016/08/06 00:55:50
nit: an alternative name for this would be very ni
| |
| 396 if (IsPromise(value)) { | |
| 397 return value; | |
| 398 } else { | |
| 399 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | |
| 400 var resolveResult = ResolvePromise(promise, value); | |
| 401 return promise; | |
| 402 } | |
| 391 } | 403 } |
| 392 | 404 |
| 393 function PerformPromiseThen(promise, onResolve, onReject, resultCapability) { | 405 function PerformPromiseThen(promise, onResolve, onReject, resultCapability) { |
| 394 if (!IS_CALLABLE(onResolve)) onResolve = PromiseIdResolveHandler; | 406 if (!IS_CALLABLE(onResolve)) onResolve = PromiseIdResolveHandler; |
| 395 if (!IS_CALLABLE(onReject)) onReject = PromiseIdRejectHandler; | 407 if (!IS_CALLABLE(onReject)) onReject = PromiseIdRejectHandler; |
| 396 | 408 |
| 397 var status = GET_PRIVATE(promise, promiseStateSymbol); | 409 var status = GET_PRIVATE(promise, promiseStateSymbol); |
| 398 switch (status) { | 410 switch (status) { |
| 399 case kPending: | 411 case kPending: |
| 400 PromiseAttachCallbacks(promise, resultCapability, onResolve, onReject); | 412 PromiseAttachCallbacks(promise, resultCapability, onResolve, onReject); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 "createPromise", PromiseCreate, | 634 "createPromise", PromiseCreate, |
| 623 "resolvePromise", ResolvePromise, | 635 "resolvePromise", ResolvePromise, |
| 624 "rejectPromise", RejectPromise | 636 "rejectPromise", RejectPromise |
| 625 ]); | 637 ]); |
| 626 | 638 |
| 627 // TODO(v8:4567): Allow experimental natives to remove function prototype | 639 // TODO(v8:4567): Allow experimental natives to remove function prototype |
| 628 [PromiseChain, PromiseDefer, PromiseAccept].forEach( | 640 [PromiseChain, PromiseDefer, PromiseAccept].forEach( |
| 629 fn => %FunctionRemovePrototype(fn)); | 641 fn => %FunctionRemovePrototype(fn)); |
| 630 | 642 |
| 631 utils.Export(function(to) { | 643 utils.Export(function(to) { |
| 632 to.IsPromise = IsPromise; | |
| 633 | |
| 634 to.PromiseChain = PromiseChain; | 644 to.PromiseChain = PromiseChain; |
| 635 to.PromiseDefer = PromiseDefer; | 645 to.PromiseDefer = PromiseDefer; |
| 636 to.PromiseAccept = PromiseAccept; | 646 to.PromiseAccept = PromiseAccept; |
| 637 | 647 |
| 638 to.PromiseCreateRejected = PromiseCreateRejected; | 648 to.PromiseCastResolved = PromiseCastResolved; |
| 639 to.PromiseCreateResolved = PromiseCreateResolved; | |
| 640 to.PromiseThen = PromiseThen; | 649 to.PromiseThen = PromiseThen; |
| 641 | 650 |
| 642 to.GlobalPromise = GlobalPromise; | 651 to.GlobalPromise = GlobalPromise; |
| 643 to.NewPromiseCapability = NewPromiseCapability; | 652 to.NewPromiseCapability = NewPromiseCapability; |
| 644 to.PerformPromiseThen = PerformPromiseThen; | 653 to.PerformPromiseThen = PerformPromiseThen; |
| 645 }); | 654 }); |
| 646 | 655 |
| 647 }) | 656 }) |
| OLD | NEW |