| 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 | 16 |
| 17 utils.Import(function(from) { | 17 utils.Import(function(from) { |
| 18 AsyncFunctionNext = from.AsyncFunctionNext; | 18 AsyncFunctionNext = from.AsyncFunctionNext; |
| 19 AsyncFunctionThrow = from.AsyncFunctionThrow; | 19 AsyncFunctionThrow = from.AsyncFunctionThrow; |
| 20 }); | 20 }); |
| 21 | 21 |
| 22 var promiseAsyncStackIDSymbol = | |
| 23 utils.ImportNow("promise_async_stack_id_symbol"); | |
| 24 var promiseHandledBySymbol = | 22 var promiseHandledBySymbol = |
| 25 utils.ImportNow("promise_handled_by_symbol"); | 23 utils.ImportNow("promise_handled_by_symbol"); |
| 26 var promiseForwardingHandlerSymbol = | 24 var promiseForwardingHandlerSymbol = |
| 27 utils.ImportNow("promise_forwarding_handler_symbol"); | 25 utils.ImportNow("promise_forwarding_handler_symbol"); |
| 28 | 26 |
| 29 // ------------------------------------------------------------------- | 27 // ------------------------------------------------------------------- |
| 30 | 28 |
| 31 function PromiseCastResolved(value) { | 29 function PromiseCastResolved(value) { |
| 32 // TODO(caitp): This is non spec compliant. See v8:5694. | 30 // TODO(caitp): This is non spec compliant. See v8:5694. |
| 33 if (%is_promise(value)) { | 31 if (%is_promise(value)) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 function RejectPromiseNoDebugEvent(promise, reason) { | 110 function RejectPromiseNoDebugEvent(promise, reason) { |
| 113 return %PromiseReject(promise, reason, false); | 111 return %PromiseReject(promise, reason, false); |
| 114 } | 112 } |
| 115 | 113 |
| 116 function AsyncFunctionPromiseCreate() { | 114 function AsyncFunctionPromiseCreate() { |
| 117 var promise = %promise_internal_constructor(UNDEFINED); | 115 var promise = %promise_internal_constructor(UNDEFINED); |
| 118 if (DEBUG_IS_ACTIVE) { | 116 if (DEBUG_IS_ACTIVE) { |
| 119 // Push the Promise under construction in an async function on | 117 // Push the Promise under construction in an async function on |
| 120 // the catch prediction stack to handle exceptions thrown before | 118 // the catch prediction stack to handle exceptions thrown before |
| 121 // the first await. | 119 // the first await. |
| 122 %DebugPushPromise(promise); | |
| 123 // Assign ID and create a recurring task to save stack for future | 120 // Assign ID and create a recurring task to save stack for future |
| 124 // resumptions from await. | 121 // resumptions from await. |
| 125 var id = %DebugNextMicrotaskId(); | 122 %DebugAsyncFunctionPromiseCreated(promise); |
| 126 SET_PRIVATE(promise, promiseAsyncStackIDSymbol, id); | |
| 127 %DebugAsyncTaskEvent(kEnqueueRecurring, id, kAsyncFunction); | |
| 128 } | 123 } |
| 129 return promise; | 124 return promise; |
| 130 } | 125 } |
| 131 | 126 |
| 132 function AsyncFunctionPromiseRelease(promise) { | 127 function AsyncFunctionPromiseRelease(promise) { |
| 133 if (DEBUG_IS_ACTIVE) { | 128 if (DEBUG_IS_ACTIVE) { |
| 134 // Cancel | |
| 135 var id = GET_PRIVATE(promise, promiseAsyncStackIDSymbol); | |
| 136 | |
| 137 // Don't send invalid events when catch prediction is turned on in | |
| 138 // the middle of some async operation. | |
| 139 if (!IS_UNDEFINED(id)) { | |
| 140 %DebugAsyncTaskEvent(kCancel, id, kAsyncFunction); | |
| 141 } | |
| 142 // Pop the Promise under construction in an async function on | 129 // Pop the Promise under construction in an async function on |
| 143 // from catch prediction stack. | 130 // from catch prediction stack. |
| 144 %DebugPopPromise(); | 131 %DebugPopPromise(); |
| 145 } | 132 } |
| 146 } | 133 } |
| 147 | 134 |
| 148 %InstallToContext([ | 135 %InstallToContext([ |
| 149 "async_function_await_caught", AsyncFunctionAwaitCaught, | 136 "async_function_await_caught", AsyncFunctionAwaitCaught, |
| 150 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, | 137 "async_function_await_uncaught", AsyncFunctionAwaitUncaught, |
| 151 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, | 138 "reject_promise_no_debug_event", RejectPromiseNoDebugEvent, |
| 152 "async_function_promise_create", AsyncFunctionPromiseCreate, | 139 "async_function_promise_create", AsyncFunctionPromiseCreate, |
| 153 "async_function_promise_release", AsyncFunctionPromiseRelease, | 140 "async_function_promise_release", AsyncFunctionPromiseRelease, |
| 154 ]); | 141 ]); |
| 155 | 142 |
| 156 }) | 143 }) |
| OLD | NEW |