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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 function PromiseCastResolved(value) { | 43 function PromiseCastResolved(value) { |
44 if (IsPromise(value)) { | 44 if (IsPromise(value)) { |
45 return value; | 45 return value; |
46 } else { | 46 } else { |
47 var promise = PromiseCreate(); | 47 var promise = PromiseCreate(); |
48 ResolvePromise(promise, value); | 48 ResolvePromise(promise, value); |
49 return promise; | 49 return promise; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 function AsyncFunctionAwait(generator, awaited, mark) { | 53 function AsyncFunctionAwait(generator, awaited, outerPromise) { |
54 // Promise.resolve(awaited).then( | 54 // Promise.resolve(awaited).then( |
55 // value => AsyncFunctionNext(value), | 55 // value => AsyncFunctionNext(value), |
56 // error => AsyncFunctionThrow(error) | 56 // error => AsyncFunctionThrow(error) |
57 // ); | 57 // ); |
58 var promise = PromiseCastResolved(awaited); | 58 var promise = PromiseCastResolved(awaited); |
59 | 59 |
60 var onFulfilled = | 60 var onFulfilled = |
61 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); | 61 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); |
62 var onRejected = | 62 var onRejected = |
63 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); | 63 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); |
64 | 64 |
65 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) { | 65 if (!IS_UNDEFINED(outerPromise) && DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
66 // Mark the reject handler callback such that it does not influence | 66 // Mark the reject handler callback to continue recursing to outerPromise |
67 // catch prediction. | 67 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, outerPromise); |
68 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true); | |
69 } | 68 } |
70 | 69 |
71 // Just forwarding the exception, so no debugEvent for throwawayCapability | 70 // Just forwarding the exception, so no debugEvent for throwawayCapability |
72 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); | 71 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); |
73 return PerformPromiseThen(promise, onFulfilled, onRejected, | 72 PerformPromiseThen(promise, onFulfilled, onRejected, |
adamk
2016/09/08 22:07:31
AsyncFunctionAwait used to return something, but n
Dan Ehrenberg
2016/09/08 22:34:46
No one calls this; they call AsyncFunctionAwaitCau
| |
74 throwawayCapability); | 73 throwawayCapability); |
74 | |
75 if (DEBUG_IS_ACTIVE) { | |
76 // Mark the dependency to outerPromise in case the throwaway Promise is | |
77 // found on the Promise stack | |
78 SET_PRIVATE(throwawayCapability.promise, promiseAwaitHandlerSymbol, | |
79 outerPromise); | |
80 } | |
75 } | 81 } |
76 | 82 |
77 function AsyncFunctionAwaitUncaught(generator, awaited) { | 83 function AsyncFunctionAwaitUncaught(generator, awaited, outerPromise) { |
78 // TODO(littledan): Install a dependency edge from awaited to outerPromise | 84 AsyncFunctionAwait(generator, awaited, outerPromise); |
79 return AsyncFunctionAwait(generator, awaited, true); | 85 return outerPromise; |
80 } | 86 } |
81 | 87 |
82 function AsyncFunctionAwaitCaught(generator, awaited) { | 88 function AsyncFunctionAwaitCaught(generator, awaited, outerPromise) { |
83 if (DEBUG_IS_ACTIVE && IsPromise(awaited)) { | 89 if (DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
84 SET_PRIVATE(awaited, promiseHandledHintSymbol, true); | 90 SET_PRIVATE(awaited, promiseHandledHintSymbol, true); |
85 } | 91 } |
86 return AsyncFunctionAwait(generator, awaited, false); | 92 AsyncFunctionAwait(generator, awaited, outerPromise); |
93 return outerPromise; | |
87 } | 94 } |
88 | 95 |
89 // How the parser rejects promises from async/await desugaring | 96 // How the parser rejects promises from async/await desugaring |
90 function RejectPromiseNoDebugEvent(promise, reason) { | 97 function RejectPromiseNoDebugEvent(promise, reason) { |
91 return RejectPromise(promise, reason, false); | 98 return RejectPromise(promise, reason, false); |
92 } | 99 } |
93 | 100 |
94 %InstallToContext([ | 101 %InstallToContext([ |
95 "async_function_await_caught", AsyncFunctionAwaitCaught, | 102 "async_function_await_caught", AsyncFunctionAwaitCaught, |
96 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 103 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
97 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 104 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
98 ]); | 105 ]); |
99 | 106 |
100 }) | 107 }) |
OLD | NEW |