| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 // equivalent to throwing an exception directly. | 374 // equivalent to throwing an exception directly. |
| 375 %PromiseRejectEventFromStack(promise, r); | 375 %PromiseRejectEventFromStack(promise, r); |
| 376 return promise; | 376 return promise; |
| 377 } else { | 377 } else { |
| 378 var promiseCapability = NewPromiseCapability(this, true); | 378 var promiseCapability = NewPromiseCapability(this, true); |
| 379 %_Call(promiseCapability.reject, UNDEFINED, r); | 379 %_Call(promiseCapability.reject, UNDEFINED, r); |
| 380 return promiseCapability.promise; | 380 return promiseCapability.promise; |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Shortcut Promise.reject and Promise.resolve() implementations, used by | |
| 385 // Async Functions implementation. | |
| 386 function PromiseCreateRejected(r) { | |
| 387 var promise = PromiseCreateAndSet(kRejected, r); | |
| 388 // This is called from the desugaring of async/await; no reason to | |
| 389 // create a redundant reject event. | |
| 390 %PromiseRejectEvent(promise, r, false); | |
| 391 return promise; | |
| 392 } | |
| 393 | |
| 394 function PromiseCreateResolved(value) { | |
| 395 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | |
| 396 var resolveResult = ResolvePromise(promise, value); | |
| 397 return promise; | |
| 398 } | |
| 399 | |
| 400 function PromiseCastResolved(value) { | 384 function PromiseCastResolved(value) { |
| 401 if (IsPromise(value)) { | 385 if (IsPromise(value)) { |
| 402 return value; | 386 return value; |
| 403 } else { | 387 } else { |
| 404 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | 388 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); |
| 405 var resolveResult = ResolvePromise(promise, value); | 389 var resolveResult = ResolvePromise(promise, value); |
| 406 return promise; | 390 return promise; |
| 407 } | 391 } |
| 408 } | 392 } |
| 409 | 393 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 "catch", PromiseCatch | 604 "catch", PromiseCatch |
| 621 ]); | 605 ]); |
| 622 | 606 |
| 623 %InstallToContext([ | 607 %InstallToContext([ |
| 624 "promise_catch", PromiseCatch, | 608 "promise_catch", PromiseCatch, |
| 625 "promise_create", PromiseCreate, | 609 "promise_create", PromiseCreate, |
| 626 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, | 610 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, |
| 627 "promise_reject", DoRejectPromise, | 611 "promise_reject", DoRejectPromise, |
| 628 "promise_resolve", ResolvePromise, | 612 "promise_resolve", ResolvePromise, |
| 629 "promise_then", PromiseThen, | 613 "promise_then", PromiseThen, |
| 630 "promise_create_rejected", PromiseCreateRejected, | |
| 631 "promise_create_resolved", PromiseCreateResolved | |
| 632 ]); | 614 ]); |
| 633 | 615 |
| 634 // This allows extras to create promises quickly without building extra | 616 // This allows extras to create promises quickly without building extra |
| 635 // resolve/reject closures, and allows them to later resolve and reject any | 617 // resolve/reject closures, and allows them to later resolve and reject any |
| 636 // promise without having to hold on to those closures forever. | 618 // promise without having to hold on to those closures forever. |
| 637 utils.InstallFunctions(extrasUtils, 0, [ | 619 utils.InstallFunctions(extrasUtils, 0, [ |
| 638 "createPromise", PromiseCreate, | 620 "createPromise", PromiseCreate, |
| 639 "resolvePromise", ResolvePromise, | 621 "resolvePromise", ResolvePromise, |
| 640 "rejectPromise", DoRejectPromise | 622 "rejectPromise", DoRejectPromise |
| 641 ]); | 623 ]); |
| 642 | 624 |
| 643 utils.Export(function(to) { | 625 utils.Export(function(to) { |
| 644 to.PromiseCastResolved = PromiseCastResolved; | 626 to.PromiseCastResolved = PromiseCastResolved; |
| 645 to.PromiseThen = PromiseThen; | 627 to.PromiseThen = PromiseThen; |
| 646 | 628 |
| 647 to.GlobalPromise = GlobalPromise; | 629 to.GlobalPromise = GlobalPromise; |
| 648 to.NewPromiseCapability = NewPromiseCapability; | 630 to.NewPromiseCapability = NewPromiseCapability; |
| 649 to.PerformPromiseThen = PerformPromiseThen; | 631 to.PerformPromiseThen = PerformPromiseThen; |
| 632 to.RejectPromise = RejectPromise; |
| 650 }); | 633 }); |
| 651 | 634 |
| 652 }) | 635 }) |
| OLD | NEW |