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; | 16 var CreateInternalPromiseCapability; |
17 var PromiseCreate; | |
18 var PromiseNextMicrotaskID; | |
19 var RejectPromise; | |
20 | 17 |
21 utils.Import(function(from) { | 18 utils.Import(function(from) { |
22 AsyncFunctionNext = from.AsyncFunctionNext; | 19 AsyncFunctionNext = from.AsyncFunctionNext; |
23 AsyncFunctionThrow = from.AsyncFunctionThrow; | 20 AsyncFunctionThrow = from.AsyncFunctionThrow; |
24 CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; | 21 CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; |
25 PromiseCreate = from.PromiseCreate; | |
26 RejectPromise = from.RejectPromise; | |
27 }); | 22 }); |
28 | 23 |
29 var promiseAsyncStackIDSymbol = | 24 var promiseAsyncStackIDSymbol = |
30 utils.ImportNow("promise_async_stack_id_symbol"); | 25 utils.ImportNow("promise_async_stack_id_symbol"); |
31 var promiseHandledBySymbol = | 26 var promiseHandledBySymbol = |
32 utils.ImportNow("promise_handled_by_symbol"); | 27 utils.ImportNow("promise_handled_by_symbol"); |
33 var promiseForwardingHandlerSymbol = | 28 var promiseForwardingHandlerSymbol = |
34 utils.ImportNow("promise_forwarding_handler_symbol"); | 29 utils.ImportNow("promise_forwarding_handler_symbol"); |
35 var promiseHandledHintSymbol = | 30 var promiseHandledHintSymbol = |
36 utils.ImportNow("promise_handled_hint_symbol"); | 31 utils.ImportNow("promise_handled_hint_symbol"); |
37 | 32 |
38 // ------------------------------------------------------------------- | 33 // ------------------------------------------------------------------- |
39 | 34 |
40 function PromiseCastResolved(value) { | 35 function PromiseCastResolved(value) { |
41 // TODO(caitp): This is non spec compliant. See v8:5694. | 36 // TODO(caitp): This is non spec compliant. See v8:5694. |
42 if (%is_promise(value)) { | 37 if (%is_promise(value)) { |
43 return value; | 38 return value; |
44 } else { | 39 } else { |
45 var promise = PromiseCreate(); | 40 var promise = %promise_internal_constructor(UNDEFINED); |
46 %promise_resolve(promise, value); | 41 %promise_resolve(promise, value); |
47 return promise; | 42 return promise; |
48 } | 43 } |
49 } | 44 } |
50 | 45 |
51 // ES#abstract-ops-async-function-await | 46 // ES#abstract-ops-async-function-await |
52 // AsyncFunctionAwait ( value ) | 47 // AsyncFunctionAwait ( value ) |
53 // Shared logic for the core of await. The parser desugars | 48 // Shared logic for the core of await. The parser desugars |
54 // await awaited | 49 // await awaited |
55 // into | 50 // into |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // prediction indicates that there is a locally surrounding catch block | 109 // prediction indicates that there is a locally surrounding catch block |
115 function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { | 110 function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { |
116 if (DEBUG_IS_ACTIVE && %is_promise(awaited)) { | 111 if (DEBUG_IS_ACTIVE && %is_promise(awaited)) { |
117 SET_PRIVATE(awaited, promiseHandledHintSymbol, true); | 112 SET_PRIVATE(awaited, promiseHandledHintSymbol, true); |
118 } | 113 } |
119 AsyncFunctionAwait(generator, awaited, outerPromise); | 114 AsyncFunctionAwait(generator, awaited, outerPromise); |
120 } | 115 } |
121 | 116 |
122 // How the parser rejects promises from async/await desugaring | 117 // How the parser rejects promises from async/await desugaring |
123 function RejectPromiseNoDebugEvent(promise, reason) { | 118 function RejectPromiseNoDebugEvent(promise, reason) { |
124 return RejectPromise(promise, reason, false); | 119 return %PromiseReject(promise, reason, false); |
125 } | 120 } |
126 | 121 |
127 function AsyncFunctionPromiseCreate() { | 122 function AsyncFunctionPromiseCreate() { |
128 var promise = PromiseCreate(); | 123 var promise = %promise_internal_constructor(UNDEFINED); |
129 if (DEBUG_IS_ACTIVE) { | 124 if (DEBUG_IS_ACTIVE) { |
130 // Push the Promise under construction in an async function on | 125 // Push the Promise under construction in an async function on |
131 // the catch prediction stack to handle exceptions thrown before | 126 // the catch prediction stack to handle exceptions thrown before |
132 // the first await. | 127 // the first await. |
133 %DebugPushPromise(promise); | 128 %DebugPushPromise(promise); |
134 // Assign ID and create a recurring task to save stack for future | 129 // Assign ID and create a recurring task to save stack for future |
135 // resumptions from await. | 130 // resumptions from await. |
136 var id = %DebugNextMicrotaskId(); | 131 var id = %DebugNextMicrotaskId(); |
137 SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id); | 132 SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id); |
138 %DebugAsyncTaskEvent("enqueueRecurring", id, "async function"); | 133 %DebugAsyncTaskEvent("enqueueRecurring", id, "async function"); |
(...skipping 19 matching lines...) Expand all Loading... |
158 | 153 |
159 %InstallToContext([ | 154 %InstallToContext([ |
160 "async_function_await_caught", AsyncFunctionAwaitCaught, | 155 "async_function_await_caught", AsyncFunctionAwaitCaught, |
161 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 156 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
162 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 157 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
163 "async_function_promise_create", AsyncFunctionPromiseCreate, | 158 "async_function_promise_create", AsyncFunctionPromiseCreate, |
164 "async_function_promise_release", AsyncFunctionPromiseRelease, | 159 "async_function_promise_release", AsyncFunctionPromiseRelease, |
165 ]); | 160 ]); |
166 | 161 |
167 }) | 162 }) |
OLD | NEW |