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

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

Issue 2599003002: [async-await] Remove call indirection in Create and Reject (Closed)
Patch Set: Remove RejectPromise and empty utils.Export call Created 3 years, 11 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 | « no previous file | src/js/promise.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 AsyncFunctionNext; 14 var AsyncFunctionNext;
15 var AsyncFunctionThrow; 15 var AsyncFunctionThrow;
16 var PromiseCreate;
17 var PromiseNextMicrotaskID;
18 var RejectPromise;
19 16
20 utils.Import(function(from) { 17 utils.Import(function(from) {
21 AsyncFunctionNext = from.AsyncFunctionNext; 18 AsyncFunctionNext = from.AsyncFunctionNext;
22 AsyncFunctionThrow = from.AsyncFunctionThrow; 19 AsyncFunctionThrow = from.AsyncFunctionThrow;
23 PromiseCreate = from.PromiseCreate;
24 RejectPromise = from.RejectPromise;
25 }); 20 });
26 21
27 var promiseAsyncStackIDSymbol = 22 var promiseAsyncStackIDSymbol =
28 utils.ImportNow("promise_async_stack_id_symbol"); 23 utils.ImportNow("promise_async_stack_id_symbol");
29 var promiseHandledBySymbol = 24 var promiseHandledBySymbol =
30 utils.ImportNow("promise_handled_by_symbol"); 25 utils.ImportNow("promise_handled_by_symbol");
31 var promiseForwardingHandlerSymbol = 26 var promiseForwardingHandlerSymbol =
32 utils.ImportNow("promise_forwarding_handler_symbol"); 27 utils.ImportNow("promise_forwarding_handler_symbol");
33 28
34 // ------------------------------------------------------------------- 29 // -------------------------------------------------------------------
35 30
36 function PromiseCastResolved(value) { 31 function PromiseCastResolved(value) {
37 // TODO(caitp): This is non spec compliant. See v8:5694. 32 // TODO(caitp): This is non spec compliant. See v8:5694.
38 if (%is_promise(value)) { 33 if (%is_promise(value)) {
39 return value; 34 return value;
40 } else { 35 } else {
41 var promise = PromiseCreate(UNDEFINED); 36 var promise = %promise_internal_constructor(UNDEFINED);
42 %promise_resolve(promise, value); 37 %promise_resolve(promise, value);
43 return promise; 38 return promise;
44 } 39 }
45 } 40 }
46 41
47 // ES#abstract-ops-async-function-await 42 // ES#abstract-ops-async-function-await
48 // AsyncFunctionAwait ( value ) 43 // AsyncFunctionAwait ( value )
49 // Shared logic for the core of await. The parser desugars 44 // Shared logic for the core of await. The parser desugars
50 // await awaited 45 // await awaited
51 // into 46 // into
(...skipping 18 matching lines...) Expand all
70 }; 65 };
71 var onRejected = sentError => { 66 var onRejected = sentError => {
72 %_Call(AsyncFunctionThrow, generator, sentError); 67 %_Call(AsyncFunctionThrow, generator, sentError);
73 // Similarly, returning the huge Promise here would cause a long 68 // Similarly, returning the huge Promise here would cause a long
74 // resolution chain to find what the exception to throw is, and 69 // resolution chain to find what the exception to throw is, and
75 // create a similar memory leak, and it does not matter what 70 // create a similar memory leak, and it does not matter what
76 // sort of rejection this intermediate Promise becomes. 71 // sort of rejection this intermediate Promise becomes.
77 return; 72 return;
78 } 73 }
79 74
80 var throwawayPromise = PromiseCreate(promise); 75 var throwawayPromise = %promise_internal_constructor(promise);
81 76
82 // The Promise will be thrown away and not handled, but it shouldn't trigger 77 // The Promise will be thrown away and not handled, but it shouldn't trigger
83 // unhandled reject events as its work is done 78 // unhandled reject events as its work is done
84 %PromiseMarkAsHandled(throwawayPromise); 79 %PromiseMarkAsHandled(throwawayPromise);
85 80
86 if (DEBUG_IS_ACTIVE) { 81 if (DEBUG_IS_ACTIVE) {
87 if (%is_promise(awaited)) { 82 if (%is_promise(awaited)) {
88 // Mark the reject handler callback to be a forwarding edge, rather 83 // Mark the reject handler callback to be a forwarding edge, rather
89 // than a meaningful catch handler 84 // than a meaningful catch handler
90 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); 85 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true);
(...skipping 17 matching lines...) Expand all
108 // prediction indicates that there is a locally surrounding catch block 103 // prediction indicates that there is a locally surrounding catch block
109 function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { 104 function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) {
110 if (DEBUG_IS_ACTIVE && %is_promise(awaited)) { 105 if (DEBUG_IS_ACTIVE && %is_promise(awaited)) {
111 %PromiseMarkHandledHint(awaited); 106 %PromiseMarkHandledHint(awaited);
112 } 107 }
113 AsyncFunctionAwait(generator, awaited, outerPromise); 108 AsyncFunctionAwait(generator, awaited, outerPromise);
114 } 109 }
115 110
116 // How the parser rejects promises from async/await desugaring 111 // How the parser rejects promises from async/await desugaring
117 function RejectPromiseNoDebugEvent(promise, reason) { 112 function RejectPromiseNoDebugEvent(promise, reason) {
118 return RejectPromise(promise, reason, false); 113 return %PromiseReject(promise, reason, false);
119 } 114 }
120 115
121 function AsyncFunctionPromiseCreate() { 116 function AsyncFunctionPromiseCreate() {
122 var promise = PromiseCreate(); 117 var promise = %promise_internal_constructor(UNDEFINED);
123 if (DEBUG_IS_ACTIVE) { 118 if (DEBUG_IS_ACTIVE) {
124 // Push the Promise under construction in an async function on 119 // Push the Promise under construction in an async function on
125 // the catch prediction stack to handle exceptions thrown before 120 // the catch prediction stack to handle exceptions thrown before
126 // the first await. 121 // the first await.
127 %DebugPushPromise(promise); 122 %DebugPushPromise(promise);
128 // Assign ID and create a recurring task to save stack for future 123 // Assign ID and create a recurring task to save stack for future
129 // resumptions from await. 124 // resumptions from await.
130 var id = %DebugNextMicrotaskId(); 125 var id = %DebugNextMicrotaskId();
131 SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id); 126 SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id);
132 %DebugAsyncTaskEvent(kEnqueueRecurring, id, kAsyncFunction); 127 %DebugAsyncTaskEvent(kEnqueueRecurring, id, kAsyncFunction);
(...skipping 19 matching lines...) Expand all
152 147
153 %InstallToContext([ 148 %InstallToContext([
154 "async_function_await_caught", AsyncFunctionAwaitCaught, 149 "async_function_await_caught", AsyncFunctionAwaitCaught,
155 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, 150 "async_function_await_uncaught", AsyncFunctionAwaitUncaught,
156 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, 151 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent,
157 "async_function_promise_create", AsyncFunctionPromiseCreate, 152 "async_function_promise_create", AsyncFunctionPromiseCreate,
158 "async_function_promise_release", AsyncFunctionPromiseRelease, 153 "async_function_promise_release", AsyncFunctionPromiseRelease,
159 ]); 154 ]);
160 155
161 }) 156 })
OLDNEW
« no previous file with comments | « no previous file | src/js/promise.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698