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

Side by Side Diff: src/js/harmony-async-await.js

Issue 2287543002: Catch marking
Patch Set: Fix symbols 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/heap-symbols.h ('k') | src/js/prologue.js » ('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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 AsyncFunctionNext; 15 var AsyncFunctionNext;
15 var AsyncFunctionThrow; 16 var AsyncFunctionThrow;
16 var GlobalPromise; 17 var GlobalPromise;
18 var IsPromise;
17 var NewPromiseCapability; 19 var NewPromiseCapability;
18 var PerformPromiseThen; 20 var PerformPromiseThen;
19 var PromiseCastResolved; 21 var PromiseCreate;
20 var RejectPromise; 22 var RejectPromise;
23 var ResolvePromise;
21 24
22 utils.Import(function(from) { 25 utils.Import(function(from) {
23 AsyncFunctionNext = from.AsyncFunctionNext; 26 AsyncFunctionNext = from.AsyncFunctionNext;
24 AsyncFunctionThrow = from.AsyncFunctionThrow; 27 AsyncFunctionThrow = from.AsyncFunctionThrow;
28 IsPromise = from.IsPromise;
25 GlobalPromise = from.GlobalPromise; 29 GlobalPromise = from.GlobalPromise;
26 NewPromiseCapability = from.NewPromiseCapability; 30 NewPromiseCapability = from.NewPromiseCapability;
27 PromiseCastResolved = from.PromiseCastResolved; 31 PromiseCreate = from.PromiseCreate;
28 PerformPromiseThen = from.PerformPromiseThen; 32 PerformPromiseThen = from.PerformPromiseThen;
29 RejectPromise = from.RejectPromise; 33 RejectPromise = from.RejectPromise;
34 ResolvePromise = from.ResolvePromise;
30 }); 35 });
31 36
37 var promiseAwaitHandlerSymbol = utils.ImportNow("promise_await_handler_symbol");
38 var promiseHandledHintSymbol =
39 utils.ImportNow("promise_handled_hint_symbol");
40
32 // ------------------------------------------------------------------- 41 // -------------------------------------------------------------------
33 42
34 function AsyncFunctionAwait(generator, value) { 43 function PromiseCastResolved(value) {
35 // Promise.resolve(value).then( 44 if (IsPromise(value)) {
45 return value;
46 } else {
47 var promise = PromiseCreate();
48 ResolvePromise(promise, value);
49 return promise;
50 }
51 }
52
53 function AsyncFunctionAwait(generator, awaited, mark) {
54 // Promise.resolve(awaited).then(
36 // value => AsyncFunctionNext(value), 55 // value => AsyncFunctionNext(value),
37 // error => AsyncFunctionThrow(error) 56 // error => AsyncFunctionThrow(error)
38 // ); 57 // );
39 var promise = PromiseCastResolved(value); 58 var promise = PromiseCastResolved(awaited);
40 59
41 var onFulfilled = 60 var onFulfilled =
42 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); 61 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue);
43 var onRejected = 62 var onRejected =
44 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); 63 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError);
45 64
46 // false debugEvent to avoid redundant ExceptionEvents 65 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) {
47 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); 66 // Mark the reject handler callback such that it does not influence
67 // catch prediction.
68 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true);
69 }
70
71 var throwawayCapability = NewPromiseCapability(GlobalPromise);
48 return PerformPromiseThen(promise, onFulfilled, onRejected, 72 return PerformPromiseThen(promise, onFulfilled, onRejected,
49 throwawayCapability); 73 throwawayCapability);
50 } 74 }
51 75
76 function AsyncFunctionAwaitUncaught(generator, awaited) {
77 // TODO(littledan): Install a dependency edge from awaited to outerPromise
78 return AsyncFunctionAwait(generator, awaited, true);
79 }
80
81 function AsyncFunctionAwaitCaught(generator, awaited) {
82 if (DEBUG_IS_ACTIVE && IsPromise(awaited)) {
83 SET_PRIVATE(awaited, promiseHandledHintSymbol, true);
84 }
85 return AsyncFunctionAwait(generator, awaited, false);
86 }
87
52 // How the parser rejects promises from async/await desugaring 88 // How the parser rejects promises from async/await desugaring
53 function RejectPromiseNoDebugEvent(promise, reason) { 89 function RejectPromiseNoDebugEvent(promise, reason) {
54 return RejectPromise(promise, reason, false); 90 return RejectPromise(promise, reason, false);
55 } 91 }
56 92
57 %InstallToContext([ 93 %InstallToContext([
58 "async_function_await", AsyncFunctionAwait, 94 "async_function_await_caught", AsyncFunctionAwaitCaught,
95 "async_function_await_uncaught", AsyncFunctionAwaitUncaught,
59 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, 96 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
60 ]); 97 ]);
61 98
62 }) 99 })
OLDNEW
« no previous file with comments | « src/heap-symbols.h ('k') | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698