| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited) | 59 // yield AsyncFunctionAwait{Caught,Uncaught}(.generator, awaited) |
| 60 // The 'awaited' parameter is the value; the generator stands in | 60 // The 'awaited' parameter is the value; the generator stands in |
| 61 // for the asyncContext, and mark is metadata for debugging | 61 // for the asyncContext, and mark is metadata for debugging |
| 62 function AsyncFunctionAwait(generator, awaited, mark) { | 62 function AsyncFunctionAwait(generator, awaited, mark) { |
| 63 // Promise.resolve(awaited).then( | 63 // Promise.resolve(awaited).then( |
| 64 // value => AsyncFunctionNext(value), | 64 // value => AsyncFunctionNext(value), |
| 65 // error => AsyncFunctionThrow(error) | 65 // error => AsyncFunctionThrow(error) |
| 66 // ); | 66 // ); |
| 67 var promise = PromiseCastResolved(awaited); | 67 var promise = PromiseCastResolved(awaited); |
| 68 | 68 |
| 69 var onFulfilled = | 69 var onFulfilled = sentValue => { |
| 70 (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue); | 70 %_Call(AsyncFunctionNext, generator, sentValue); |
| 71 var onRejected = | 71 // The resulting Promise is a throwaway, so it doesn't matter what it |
| 72 (sentError) => %_Call(AsyncFunctionThrow, generator, sentError); | 72 // resolves to. What is important is that we don't end up keeping the |
| 73 // whole chain of intermediate Promises alive by returning the value |
| 74 // of AsyncFunctionNext, as that would create a memory leak. |
| 75 return; |
| 76 }; |
| 77 var onRejected = sentError => { |
| 78 %_Call(AsyncFunctionThrow, generator, sentError); |
| 79 // Similarly, returning the huge Promise here would cause a long |
| 80 // resolution chain to find what the exception to throw is, and |
| 81 // create a similar memory leak, and it does not matter what |
| 82 // sort of rejection this intermediate Promise becomes. |
| 83 return; |
| 84 } |
| 73 | 85 |
| 74 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) { | 86 if (mark && DEBUG_IS_ACTIVE && IsPromise(awaited)) { |
| 75 // Mark the reject handler callback such that it does not influence | 87 // Mark the reject handler callback such that it does not influence |
| 76 // catch prediction. | 88 // catch prediction. |
| 77 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true); | 89 SET_PRIVATE(onRejected, promiseAwaitHandlerSymbol, true); |
| 78 } | 90 } |
| 79 | 91 |
| 80 // Just forwarding the exception, so no debugEvent for throwawayCapability | 92 // Just forwarding the exception, so no debugEvent for throwawayCapability |
| 81 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); | 93 var throwawayCapability = NewPromiseCapability(GlobalPromise, false); |
| 82 | 94 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 return RejectPromise(promise, reason, false); | 121 return RejectPromise(promise, reason, false); |
| 110 } | 122 } |
| 111 | 123 |
| 112 %InstallToContext([ | 124 %InstallToContext([ |
| 113 "async_function_await_caught", AsyncFunctionAwaitCaught, | 125 "async_function_await_caught", AsyncFunctionAwaitCaught, |
| 114 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 126 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
| 115 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 127 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
| 116 ]); | 128 ]); |
| 117 | 129 |
| 118 }) | 130 }) |
| OLD | NEW |