OLD | NEW |
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 CreateInternalPromiseCapability; | |
17 var PromiseCreate; | 16 var PromiseCreate; |
18 var PromiseNextMicrotaskID; | 17 var PromiseNextMicrotaskID; |
19 var RejectPromise; | 18 var RejectPromise; |
20 | 19 |
21 utils.Import(function(from) { | 20 utils.Import(function(from) { |
22 AsyncFunctionNext = from.AsyncFunctionNext; | 21 AsyncFunctionNext = from.AsyncFunctionNext; |
23 AsyncFunctionThrow = from.AsyncFunctionThrow; | 22 AsyncFunctionThrow = from.AsyncFunctionThrow; |
24 CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; | |
25 PromiseCreate = from.PromiseCreate; | 23 PromiseCreate = from.PromiseCreate; |
26 RejectPromise = from.RejectPromise; | 24 RejectPromise = from.RejectPromise; |
27 }); | 25 }); |
28 | 26 |
29 var promiseAsyncStackIDSymbol = | 27 var promiseAsyncStackIDSymbol = |
30 utils.ImportNow("promise_async_stack_id_symbol"); | 28 utils.ImportNow("promise_async_stack_id_symbol"); |
31 var promiseHandledBySymbol = | 29 var promiseHandledBySymbol = |
32 utils.ImportNow("promise_handled_by_symbol"); | 30 utils.ImportNow("promise_handled_by_symbol"); |
33 var promiseForwardingHandlerSymbol = | 31 var promiseForwardingHandlerSymbol = |
34 utils.ImportNow("promise_forwarding_handler_symbol"); | 32 utils.ImportNow("promise_forwarding_handler_symbol"); |
35 | 33 |
36 // ------------------------------------------------------------------- | 34 // ------------------------------------------------------------------- |
37 | 35 |
38 function PromiseCastResolved(value) { | 36 function PromiseCastResolved(value) { |
39 // TODO(caitp): This is non spec compliant. See v8:5694. | 37 // TODO(caitp): This is non spec compliant. See v8:5694. |
40 if (%is_promise(value)) { | 38 if (%is_promise(value)) { |
41 return value; | 39 return value; |
42 } else { | 40 } else { |
43 var promise = PromiseCreate(); | 41 var promise = PromiseCreate(UNDEFINED); |
44 %promise_resolve(promise, value); | 42 %promise_resolve(promise, value); |
45 return promise; | 43 return promise; |
46 } | 44 } |
47 } | 45 } |
48 | 46 |
49 // ES#abstract-ops-async-function-await | 47 // ES#abstract-ops-async-function-await |
50 // AsyncFunctionAwait ( value ) | 48 // AsyncFunctionAwait ( value ) |
51 // Shared logic for the core of await. The parser desugars | 49 // Shared logic for the core of await. The parser desugars |
52 // await awaited | 50 // await awaited |
53 // into | 51 // into |
(...skipping 18 matching lines...) Expand all Loading... |
72 }; | 70 }; |
73 var onRejected = sentError => { | 71 var onRejected = sentError => { |
74 %_Call(AsyncFunctionThrow, generator, sentError); | 72 %_Call(AsyncFunctionThrow, generator, sentError); |
75 // Similarly, returning the huge Promise here would cause a long | 73 // Similarly, returning the huge Promise here would cause a long |
76 // resolution chain to find what the exception to throw is, and | 74 // resolution chain to find what the exception to throw is, and |
77 // create a similar memory leak, and it does not matter what | 75 // create a similar memory leak, and it does not matter what |
78 // sort of rejection this intermediate Promise becomes. | 76 // sort of rejection this intermediate Promise becomes. |
79 return; | 77 return; |
80 } | 78 } |
81 | 79 |
82 // Just forwarding the exception, so no debugEvent for throwawayCapability. | 80 var throwawayPromise = PromiseCreate(promise); |
83 var throwawayCapability = CreateInternalPromiseCapability(promise); | |
84 | 81 |
85 // The Promise will be thrown away and not handled, but it shouldn't trigger | 82 // The Promise will be thrown away and not handled, but it shouldn't trigger |
86 // unhandled reject events as its work is done | 83 // unhandled reject events as its work is done |
87 %PromiseMarkAsHandled(throwawayCapability.promise); | 84 %PromiseMarkAsHandled(throwawayPromise); |
88 | 85 |
89 if (DEBUG_IS_ACTIVE) { | 86 if (DEBUG_IS_ACTIVE) { |
90 if (%is_promise(awaited)) { | 87 if (%is_promise(awaited)) { |
91 // Mark the reject handler callback to be a forwarding edge, rather | 88 // Mark the reject handler callback to be a forwarding edge, rather |
92 // than a meaningful catch handler | 89 // than a meaningful catch handler |
93 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); | 90 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); |
94 } | 91 } |
95 | 92 |
96 // Mark the dependency to outerPromise in case the throwaway Promise is | 93 // Mark the dependency to outerPromise in case the throwaway Promise is |
97 // found on the Promise stack | 94 // found on the Promise stack |
98 SET_PRIVATE(throwawayCapability.promise, promiseHandledBySymbol, | 95 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, outerPromise); |
99 outerPromise); | |
100 } | 96 } |
101 | 97 |
102 %perform_promise_then(promise, onFulfilled, onRejected, throwawayCapability); | 98 %perform_promise_then(promise, onFulfilled, onRejected, throwawayPromise); |
103 } | 99 } |
104 | 100 |
105 // Called by the parser from the desugaring of 'await' when catch | 101 // Called by the parser from the desugaring of 'await' when catch |
106 // prediction indicates no locally surrounding catch block | 102 // prediction indicates no locally surrounding catch block |
107 function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { | 103 function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { |
108 AsyncFunctionAwait(generator, awaited, outerPromise); | 104 AsyncFunctionAwait(generator, awaited, outerPromise); |
109 } | 105 } |
110 | 106 |
111 // Called by the parser from the desugaring of 'await' when catch | 107 // Called by the parser from the desugaring of 'await' when catch |
112 // prediction indicates that there is a locally surrounding catch block | 108 // prediction indicates that there is a locally surrounding catch block |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 152 |
157 %InstallToContext([ | 153 %InstallToContext([ |
158 "async_function_await_caught", AsyncFunctionAwaitCaught, | 154 "async_function_await_caught", AsyncFunctionAwaitCaught, |
159 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 155 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
160 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 156 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
161 "async_function_promise_create", AsyncFunctionPromiseCreate, | 157 "async_function_promise_create", AsyncFunctionPromiseCreate, |
162 "async_function_promise_release", AsyncFunctionPromiseRelease, | 158 "async_function_promise_release", AsyncFunctionPromiseRelease, |
163 ]); | 159 ]); |
164 | 160 |
165 }) | 161 }) |
OLD | NEW |