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