| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name }); | 298 %DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name }); |
| 299 } | 299 } |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 FulfillPromise(promise, kFulfilled, resolution, promiseFulfillReactionsSymbol)
; | 303 FulfillPromise(promise, kFulfilled, resolution, promiseFulfillReactionsSymbol)
; |
| 304 } | 304 } |
| 305 | 305 |
| 306 // ES#sec-rejectpromise | 306 // ES#sec-rejectpromise |
| 307 // RejectPromise ( promise, reason ) | 307 // RejectPromise ( promise, reason ) |
| 308 function RejectPromise(promise, reason) { | 308 function RejectPromise(promise, reason, skipEvent) { |
| 309 // Check promise status to confirm that this reject has an effect. | 309 // Check promise status to confirm that this reject has an effect. |
| 310 // Call runtime for callbacks to the debugger or for unhandled reject. | 310 // Call runtime for callbacks to the debugger or for unhandled reject. |
| 311 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { | 311 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { |
| 312 var debug_is_active = DEBUG_IS_ACTIVE; | 312 var debug_is_active = DEBUG_IS_ACTIVE; |
| 313 if (debug_is_active || | 313 if (debug_is_active || |
| 314 !HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) { | 314 !HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) { |
| 315 %PromiseRejectEvent(promise, reason, debug_is_active); | 315 %PromiseRejectEvent(promise, reason, debug_is_active && !skipEvent); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 FulfillPromise(promise, kRejected, reason, promiseRejectReactionsSymbol) | 318 FulfillPromise(promise, kRejected, reason, promiseRejectReactionsSymbol) |
| 319 } | 319 } |
| 320 | 320 |
| 321 // ES#sec-newpromisecapability | 321 // ES#sec-newpromisecapability |
| 322 // NewPromiseCapability ( C ) | 322 // NewPromiseCapability ( C ) |
| 323 function NewPromiseCapability(C) { | 323 function NewPromiseCapability(C) { |
| 324 if (C === GlobalPromise) { | 324 if (C === GlobalPromise) { |
| 325 // Optimized case, avoid extra closure. | 325 // Optimized case, avoid extra closure. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 // which is usually simply noise. Do not trigger that debug event. | 371 // which is usually simply noise. Do not trigger that debug event. |
| 372 %PromiseRejectEvent(promise, r, false); | 372 %PromiseRejectEvent(promise, r, false); |
| 373 return promise; | 373 return promise; |
| 374 } else { | 374 } else { |
| 375 var promiseCapability = NewPromiseCapability(this); | 375 var promiseCapability = NewPromiseCapability(this); |
| 376 %_Call(promiseCapability.reject, UNDEFINED, r); | 376 %_Call(promiseCapability.reject, UNDEFINED, r); |
| 377 return promiseCapability.promise; | 377 return promiseCapability.promise; |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Shortcut Promise.reject and Promise.resolve() implementations, used by | |
| 382 // Async Functions implementation. | |
| 383 function PromiseCreateRejected(r) { | |
| 384 return %_Call(PromiseReject, GlobalPromise, r); | |
| 385 } | |
| 386 | |
| 387 function PromiseCreateResolved(value) { | |
| 388 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | |
| 389 var resolveResult = ResolvePromise(promise, value); | |
| 390 return promise; | |
| 391 } | |
| 392 | |
| 393 function PromiseCastResolved(value) { | 381 function PromiseCastResolved(value) { |
| 394 if (IsPromise(value)) { | 382 if (IsPromise(value)) { |
| 395 return value; | 383 return value; |
| 396 } else { | 384 } else { |
| 397 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | 385 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); |
| 398 var resolveResult = ResolvePromise(promise, value); | 386 var resolveResult = ResolvePromise(promise, value); |
| 399 return promise; | 387 return promise; |
| 400 } | 388 } |
| 401 } | 389 } |
| 402 | 390 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 ]); | 602 ]); |
| 615 | 603 |
| 616 %InstallToContext([ | 604 %InstallToContext([ |
| 617 "promise_catch", PromiseCatch, | 605 "promise_catch", PromiseCatch, |
| 618 "promise_chain", PromiseChain, | 606 "promise_chain", PromiseChain, |
| 619 "promise_create", PromiseCreate, | 607 "promise_create", PromiseCreate, |
| 620 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, | 608 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, |
| 621 "promise_reject", RejectPromise, | 609 "promise_reject", RejectPromise, |
| 622 "promise_resolve", ResolvePromise, | 610 "promise_resolve", ResolvePromise, |
| 623 "promise_then", PromiseThen, | 611 "promise_then", PromiseThen, |
| 624 "promise_create_rejected", PromiseCreateRejected, | |
| 625 "promise_create_resolved", PromiseCreateResolved | |
| 626 ]); | 612 ]); |
| 627 | 613 |
| 628 // This allows extras to create promises quickly without building extra | 614 // This allows extras to create promises quickly without building extra |
| 629 // resolve/reject closures, and allows them to later resolve and reject any | 615 // resolve/reject closures, and allows them to later resolve and reject any |
| 630 // promise without having to hold on to those closures forever. | 616 // promise without having to hold on to those closures forever. |
| 631 utils.InstallFunctions(extrasUtils, 0, [ | 617 utils.InstallFunctions(extrasUtils, 0, [ |
| 632 "createPromise", PromiseCreate, | 618 "createPromise", PromiseCreate, |
| 633 "resolvePromise", ResolvePromise, | 619 "resolvePromise", ResolvePromise, |
| 634 "rejectPromise", RejectPromise | 620 "rejectPromise", RejectPromise |
| 635 ]); | 621 ]); |
| 636 | 622 |
| 637 // TODO(v8:4567): Allow experimental natives to remove function prototype | 623 // TODO(v8:4567): Allow experimental natives to remove function prototype |
| 638 [PromiseChain, PromiseDefer, PromiseAccept].forEach( | 624 [PromiseChain, PromiseDefer, PromiseAccept].forEach( |
| 639 fn => %FunctionRemovePrototype(fn)); | 625 fn => %FunctionRemovePrototype(fn)); |
| 640 | 626 |
| 641 utils.Export(function(to) { | 627 utils.Export(function(to) { |
| 642 to.PromiseChain = PromiseChain; | 628 to.PromiseChain = PromiseChain; |
| 643 to.PromiseDefer = PromiseDefer; | 629 to.PromiseDefer = PromiseDefer; |
| 644 to.PromiseAccept = PromiseAccept; | 630 to.PromiseAccept = PromiseAccept; |
| 645 | 631 |
| 646 to.PromiseCastResolved = PromiseCastResolved; | 632 to.PromiseCastResolved = PromiseCastResolved; |
| 647 to.PromiseThen = PromiseThen; | 633 to.PromiseThen = PromiseThen; |
| 648 | 634 |
| 649 to.GlobalPromise = GlobalPromise; | 635 to.GlobalPromise = GlobalPromise; |
| 650 to.NewPromiseCapability = NewPromiseCapability; | 636 to.NewPromiseCapability = NewPromiseCapability; |
| 651 to.PerformPromiseThen = PerformPromiseThen; | 637 to.PerformPromiseThen = PerformPromiseThen; |
| 652 }); | 638 }); |
| 653 | 639 |
| 654 }) | 640 }) |
| OLD | NEW |