Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: src/js/promise.js

Issue 2276243002: Mark await expressions as caught or uncaught (Closed)
Patch Set: Revert "Tests for caught exception" Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/prologue.js ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var InternalArray = utils.InternalArray; 14 var InternalArray = utils.InternalArray;
15 var promiseAwaitHandlerSymbol =
16 utils.ImportNow("promise_await_handler_symbol");
15 var promiseCombinedDeferredSymbol = 17 var promiseCombinedDeferredSymbol =
16 utils.ImportNow("promise_combined_deferred_symbol"); 18 utils.ImportNow("promise_combined_deferred_symbol");
17 var promiseHasHandlerSymbol = 19 var promiseHasHandlerSymbol =
18 utils.ImportNow("promise_has_handler_symbol"); 20 utils.ImportNow("promise_has_handler_symbol");
19 var promiseRejectReactionsSymbol = 21 var promiseRejectReactionsSymbol =
20 utils.ImportNow("promise_reject_reactions_symbol"); 22 utils.ImportNow("promise_reject_reactions_symbol");
21 var promiseFulfillReactionsSymbol = 23 var promiseFulfillReactionsSymbol =
22 utils.ImportNow("promise_fulfill_reactions_symbol"); 24 utils.ImportNow("promise_fulfill_reactions_symbol");
23 var promiseDeferredReactionsSymbol = 25 var promiseDeferredReactionsSymbol =
24 utils.ImportNow("promise_deferred_reactions_symbol"); 26 utils.ImportNow("promise_deferred_reactions_symbol");
27 var promiseHandledHintSymbol =
28 utils.ImportNow("promise_handled_hint_symbol");
25 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol"); 29 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol");
26 var promiseStateSymbol = utils.ImportNow("promise_state_symbol"); 30 var promiseStateSymbol = utils.ImportNow("promise_state_symbol");
27 var promiseResultSymbol = utils.ImportNow("promise_result_symbol"); 31 var promiseResultSymbol = utils.ImportNow("promise_result_symbol");
28 var SpeciesConstructor; 32 var SpeciesConstructor;
29 var speciesSymbol = utils.ImportNow("species_symbol"); 33 var speciesSymbol = utils.ImportNow("species_symbol");
30 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 34 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
31 35
32 utils.Import(function(from) { 36 utils.Import(function(from) {
33 SpeciesConstructor = from.SpeciesConstructor; 37 SpeciesConstructor = from.SpeciesConstructor;
34 }); 38 });
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // equivalent to throwing an exception directly. 378 // equivalent to throwing an exception directly.
375 %PromiseRejectEventFromStack(promise, r); 379 %PromiseRejectEventFromStack(promise, r);
376 return promise; 380 return promise;
377 } else { 381 } else {
378 var promiseCapability = NewPromiseCapability(this, true); 382 var promiseCapability = NewPromiseCapability(this, true);
379 %_Call(promiseCapability.reject, UNDEFINED, r); 383 %_Call(promiseCapability.reject, UNDEFINED, r);
380 return promiseCapability.promise; 384 return promiseCapability.promise;
381 } 385 }
382 } 386 }
383 387
384 function PromiseCastResolved(value) {
385 if (IsPromise(value)) {
386 return value;
387 } else {
388 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol));
389 var resolveResult = ResolvePromise(promise, value);
390 return promise;
391 }
392 }
393
394 function PerformPromiseThen(promise, onResolve, onReject, resultCapability) { 388 function PerformPromiseThen(promise, onResolve, onReject, resultCapability) {
395 if (!IS_CALLABLE(onResolve)) onResolve = PromiseIdResolveHandler; 389 if (!IS_CALLABLE(onResolve)) onResolve = PromiseIdResolveHandler;
396 if (!IS_CALLABLE(onReject)) onReject = PromiseIdRejectHandler; 390 if (!IS_CALLABLE(onReject)) onReject = PromiseIdRejectHandler;
397 391
398 var status = GET_PRIVATE(promise, promiseStateSymbol); 392 var status = GET_PRIVATE(promise, promiseStateSymbol);
399 switch (status) { 393 switch (status) {
400 case kPending: 394 case kPending:
401 PromiseAttachCallbacks(promise, resultCapability, onResolve, onReject); 395 PromiseAttachCallbacks(promise, resultCapability, onResolve, onReject);
402 break; 396 break;
403 case kFulfilled: 397 case kFulfilled:
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } catch (e) { 530 } catch (e) {
537 deferred.reject(e) 531 deferred.reject(e)
538 } 532 }
539 return deferred.promise; 533 return deferred.promise;
540 } 534 }
541 535
542 536
543 // Utility for debugger 537 // Utility for debugger
544 538
545 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) { 539 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) {
540 // If this handler was installed by async/await, it does not indicate
541 // that there is a user-defined reject handler.
542 if (GET_PRIVATE(handler, promiseAwaitHandlerSymbol)) return false;
546 if (handler !== PromiseIdRejectHandler) { 543 if (handler !== PromiseIdRejectHandler) {
547 var combinedDeferred = GET_PRIVATE(handler, promiseCombinedDeferredSymbol); 544 var combinedDeferred = GET_PRIVATE(handler, promiseCombinedDeferredSymbol);
548 if (IS_UNDEFINED(combinedDeferred)) return true; 545 if (IS_UNDEFINED(combinedDeferred)) return true;
549 if (PromiseHasUserDefinedRejectHandlerRecursive(combinedDeferred.promise)) { 546 if (PromiseHasUserDefinedRejectHandlerRecursive(combinedDeferred.promise)) {
550 return true; 547 return true;
551 } 548 }
552 } else if (PromiseHasUserDefinedRejectHandlerRecursive(deferred.promise)) { 549 } else if (PromiseHasUserDefinedRejectHandlerRecursive(deferred.promise)) {
553 return true; 550 return true;
554 } 551 }
555 return false; 552 return false;
556 } 553 }
557 554
558 function PromiseHasUserDefinedRejectHandlerRecursive(promise) { 555 function PromiseHasUserDefinedRejectHandlerRecursive(promise) {
556 // If this promise was marked as being handled by a catch block
557 // in an async function, then it has a user-defined reject handler.
558 if (GET_PRIVATE(promise, promiseHandledHintSymbol)) return true;
559
559 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol); 560 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol);
560 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); 561 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol);
562
561 if (IS_UNDEFINED(queue)) return false; 563 if (IS_UNDEFINED(queue)) return false;
564
562 if (!IS_ARRAY(queue)) { 565 if (!IS_ARRAY(queue)) {
563 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds); 566 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds);
564 } else { 567 }
565 for (var i = 0; i < queue.length; i += 2) { 568
566 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) { 569 for (var i = 0; i < queue.length; i += 2) {
567 return true; 570 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) {
568 } 571 return true;
569 } 572 }
570 } 573 }
571 return false; 574 return false;
572 } 575 }
573 576
574 // Return whether the promise will be handled by a user-defined reject 577 // Return whether the promise will be handled by a user-defined reject
575 // handler somewhere down the promise chain. For this, we do a depth-first 578 // handler somewhere down the promise chain. For this, we do a depth-first
576 // search for a reject handler that's not the default PromiseIdRejectHandler. 579 // search for a reject handler that's not the default PromiseIdRejectHandler.
577 function PromiseHasUserDefinedRejectHandler() { 580 function PromiseHasUserDefinedRejectHandler() {
578 return PromiseHasUserDefinedRejectHandlerRecursive(this); 581 return PromiseHasUserDefinedRejectHandlerRecursive(this);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // This allows extras to create promises quickly without building extra 619 // This allows extras to create promises quickly without building extra
617 // resolve/reject closures, and allows them to later resolve and reject any 620 // resolve/reject closures, and allows them to later resolve and reject any
618 // promise without having to hold on to those closures forever. 621 // promise without having to hold on to those closures forever.
619 utils.InstallFunctions(extrasUtils, 0, [ 622 utils.InstallFunctions(extrasUtils, 0, [
620 "createPromise", PromiseCreate, 623 "createPromise", PromiseCreate,
621 "resolvePromise", ResolvePromise, 624 "resolvePromise", ResolvePromise,
622 "rejectPromise", DoRejectPromise 625 "rejectPromise", DoRejectPromise
623 ]); 626 ]);
624 627
625 utils.Export(function(to) { 628 utils.Export(function(to) {
626 to.PromiseCastResolved = PromiseCastResolved; 629 to.IsPromise = IsPromise;
630 to.PromiseCreate = PromiseCreate;
627 to.PromiseThen = PromiseThen; 631 to.PromiseThen = PromiseThen;
628 632
629 to.GlobalPromise = GlobalPromise; 633 to.GlobalPromise = GlobalPromise;
630 to.NewPromiseCapability = NewPromiseCapability; 634 to.NewPromiseCapability = NewPromiseCapability;
631 to.PerformPromiseThen = PerformPromiseThen; 635 to.PerformPromiseThen = PerformPromiseThen;
636 to.ResolvePromise = ResolvePromise;
632 to.RejectPromise = RejectPromise; 637 to.RejectPromise = RejectPromise;
633 }); 638 });
634 639
635 }) 640 })
OLDNEW
« no previous file with comments | « src/js/prologue.js ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698