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 PerformPromiseThen; |
17 var PromiseCreate; | 18 var PromiseCreate; |
18 var PromiseNextMicrotaskID; | 19 var PromiseNextMicrotaskID; |
19 var RejectPromise; | 20 var RejectPromise; |
20 var ResolvePromise; | 21 var ResolvePromise; |
21 | 22 |
22 utils.Import(function(from) { | 23 utils.Import(function(from) { |
23 AsyncFunctionNext = from.AsyncFunctionNext; | 24 AsyncFunctionNext = from.AsyncFunctionNext; |
24 AsyncFunctionThrow = from.AsyncFunctionThrow; | 25 AsyncFunctionThrow = from.AsyncFunctionThrow; |
25 CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; | 26 CreateInternalPromiseCapability = from.CreateInternalPromiseCapability; |
| 27 PerformPromiseThen = from.PerformPromiseThen; |
26 PromiseCreate = from.PromiseCreate; | 28 PromiseCreate = from.PromiseCreate; |
27 RejectPromise = from.RejectPromise; | 29 RejectPromise = from.RejectPromise; |
28 ResolvePromise = from.ResolvePromise; | 30 ResolvePromise = from.ResolvePromise; |
29 }); | 31 }); |
30 | 32 |
31 var promiseAsyncStackIDSymbol = | 33 var promiseAsyncStackIDSymbol = |
32 utils.ImportNow("promise_async_stack_id_symbol"); | 34 utils.ImportNow("promise_async_stack_id_symbol"); |
33 var promiseHandledBySymbol = | 35 var promiseHandledBySymbol = |
34 utils.ImportNow("promise_handled_by_symbol"); | 36 utils.ImportNow("promise_handled_by_symbol"); |
35 var promiseForwardingHandlerSymbol = | 37 var promiseForwardingHandlerSymbol = |
36 utils.ImportNow("promise_forwarding_handler_symbol"); | 38 utils.ImportNow("promise_forwarding_handler_symbol"); |
37 var promiseHandledHintSymbol = | 39 var promiseHandledHintSymbol = |
38 utils.ImportNow("promise_handled_hint_symbol"); | 40 utils.ImportNow("promise_handled_hint_symbol"); |
39 var promiseHasHandlerSymbol = | 41 var promiseHasHandlerSymbol = |
40 utils.ImportNow("promise_has_handler_symbol"); | 42 utils.ImportNow("promise_has_handler_symbol"); |
41 | 43 |
42 // ------------------------------------------------------------------- | 44 // ------------------------------------------------------------------- |
43 | 45 |
44 function PromiseCastResolved(value) { | 46 function PromiseCastResolved(value) { |
45 // TODO(caitp): This is non spec compliant. See v8:5694. | |
46 if (%is_promise(value)) { | 47 if (%is_promise(value)) { |
47 return value; | 48 return value; |
48 } else { | 49 } else { |
49 var promise = PromiseCreate(); | 50 var promise = PromiseCreate(); |
50 ResolvePromise(promise, value); | 51 ResolvePromise(promise, value); |
51 return promise; | 52 return promise; |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 // ES#abstract-ops-async-function-await | 56 // ES#abstract-ops-async-function-await |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // than a meaningful catch handler | 99 // than a meaningful catch handler |
99 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); | 100 SET_PRIVATE(onRejected, promiseForwardingHandlerSymbol, true); |
100 } | 101 } |
101 | 102 |
102 // Mark the dependency to outerPromise in case the throwaway Promise is | 103 // Mark the dependency to outerPromise in case the throwaway Promise is |
103 // found on the Promise stack | 104 // found on the Promise stack |
104 SET_PRIVATE(throwawayCapability.promise, promiseHandledBySymbol, | 105 SET_PRIVATE(throwawayCapability.promise, promiseHandledBySymbol, |
105 outerPromise); | 106 outerPromise); |
106 } | 107 } |
107 | 108 |
108 %perform_promise_then(promise, onFulfilled, onRejected, throwawayCapability); | 109 PerformPromiseThen(promise, onFulfilled, onRejected, throwawayCapability); |
109 } | 110 } |
110 | 111 |
111 // Called by the parser from the desugaring of 'await' when catch | 112 // Called by the parser from the desugaring of 'await' when catch |
112 // prediction indicates no locally surrounding catch block | 113 // prediction indicates no locally surrounding catch block |
113 function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { | 114 function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { |
114 AsyncFunctionAwait(generator, awaited, outerPromise); | 115 AsyncFunctionAwait(generator, awaited, outerPromise); |
115 } | 116 } |
116 | 117 |
117 // Called by the parser from the desugaring of 'await' when catch | 118 // Called by the parser from the desugaring of 'await' when catch |
118 // prediction indicates that there is a locally surrounding catch block | 119 // prediction indicates that there is a locally surrounding catch block |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 163 |
163 %InstallToContext([ | 164 %InstallToContext([ |
164 "async_function_await_caught", AsyncFunctionAwaitCaught, | 165 "async_function_await_caught", AsyncFunctionAwaitCaught, |
165 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 166 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
166 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 167 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
167 "async_function_promise_create", AsyncFunctionPromiseCreate, | 168 "async_function_promise_create", AsyncFunctionPromiseCreate, |
168 "async_function_promise_release", AsyncFunctionPromiseRelease, | 169 "async_function_promise_release", AsyncFunctionPromiseRelease, |
169 ]); | 170 ]); |
170 | 171 |
171 }) | 172 }) |
OLD | NEW |