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 #include "src/runtime/runtime-utils.h" | 4 #include "src/runtime/runtime-utils.h" |
5 | 5 |
6 #include "src/debug/debug.h" | 6 #include "src/debug/debug.h" |
7 #include "src/elements.h" | 7 #include "src/elements.h" |
8 #include "src/promise-utils.h" | 8 #include "src/promise-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 25 matching lines...) Expand all Loading... |
36 HandleScope scope(isolate); | 36 HandleScope scope(isolate); |
37 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 37 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
38 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 38 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
39 | 39 |
40 Handle<Object> rejected_promise = promise; | 40 Handle<Object> rejected_promise = promise; |
41 if (isolate->debug()->is_active()) { | 41 if (isolate->debug()->is_active()) { |
42 // If the Promise.reject call is caught, then this will return | 42 // If the Promise.reject call is caught, then this will return |
43 // undefined, which will be interpreted by PromiseRejectEvent | 43 // undefined, which will be interpreted by PromiseRejectEvent |
44 // as being a caught exception event. | 44 // as being a caught exception event. |
45 rejected_promise = isolate->GetPromiseOnStackOnThrow(); | 45 rejected_promise = isolate->GetPromiseOnStackOnThrow(); |
| 46 isolate->debug()->OnAsyncTaskEvent( |
| 47 debug::kDebugEnqueueRecurring, |
| 48 isolate->debug()->NextAsyncTaskId(promise), kDebugPromiseReject); |
46 } | 49 } |
47 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); | 50 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); |
48 return isolate->heap()->undefined_value(); | 51 return isolate->heap()->undefined_value(); |
49 } | 52 } |
50 | 53 |
51 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { | 54 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { |
52 DCHECK_EQ(1, args.length()); | 55 DCHECK_EQ(1, args.length()); |
53 HandleScope scope(isolate); | 56 HandleScope scope(isolate); |
54 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 57 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
55 // At this point, no revocation has been issued before | 58 // At this point, no revocation has been issued before |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 111 } |
109 | 112 |
110 void SetDebugInfo(Isolate* isolate, Handle<PromiseReactionJobInfo> info, | 113 void SetDebugInfo(Isolate* isolate, Handle<PromiseReactionJobInfo> info, |
111 int status) { | 114 int status) { |
112 int id; | 115 int id; |
113 PromiseDebugActionName name; | 116 PromiseDebugActionName name; |
114 | 117 |
115 if (GetDebugIdForAsyncFunction(isolate, info, &id)) { | 118 if (GetDebugIdForAsyncFunction(isolate, info, &id)) { |
116 name = kDebugAsyncFunction; | 119 name = kDebugAsyncFunction; |
117 } else { | 120 } else { |
118 id = isolate->GetNextDebugMicrotaskId(); | 121 id = isolate->debug()->NextAsyncTaskId(handle(info->promise(), isolate)); |
119 | |
120 DCHECK(status != v8::Promise::kPending); | 122 DCHECK(status != v8::Promise::kPending); |
121 name = status == v8::Promise::kFulfilled ? kDebugPromiseResolve | 123 name = status == v8::Promise::kFulfilled ? kDebugPromiseResolve |
122 : kDebugPromiseReject; | 124 : kDebugPromiseReject; |
123 | |
124 isolate->debug()->OnAsyncTaskEvent(kDebugEnqueue, id, name); | |
125 } | 125 } |
126 | 126 |
127 info->set_debug_id(id); | 127 info->set_debug_id(id); |
128 info->set_debug_name(name); | 128 info->set_debug_name(name); |
129 } | 129 } |
130 | 130 |
131 void EnqueuePromiseReactionJob(Isolate* isolate, | 131 void EnqueuePromiseReactionJob(Isolate* isolate, |
132 Handle<PromiseReactionJobInfo> info, | 132 Handle<PromiseReactionJobInfo> info, |
133 int status) { | 133 int status) { |
134 if (isolate->debug()->is_active()) { | 134 if (isolate->debug()->is_active()) { |
135 SetDebugInfo(isolate, info, status); | 135 SetDebugInfo(isolate, info, status); |
136 } | 136 } |
137 | 137 |
138 isolate->EnqueueMicrotask(info); | 138 isolate->EnqueueMicrotask(info); |
139 } | 139 } |
140 | 140 |
141 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, | 141 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, |
142 Handle<Object> result) { | 142 Handle<Object> result) { |
143 promise->set_status(status); | 143 promise->set_status(status); |
144 promise->set_result(*result); | 144 promise->set_result(*result); |
145 promise->set_deferred_promise(isolate->heap()->undefined_value()); | 145 promise->set_deferred_promise(isolate->heap()->undefined_value()); |
146 promise->set_deferred_on_resolve(isolate->heap()->undefined_value()); | 146 promise->set_deferred_on_resolve(isolate->heap()->undefined_value()); |
147 promise->set_deferred_on_reject(isolate->heap()->undefined_value()); | 147 promise->set_deferred_on_reject(isolate->heap()->undefined_value()); |
148 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); | 148 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); |
149 promise->set_reject_reactions(isolate->heap()->undefined_value()); | 149 promise->set_reject_reactions(isolate->heap()->undefined_value()); |
150 } | 150 } |
151 | 151 |
152 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, int status, | 152 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, int status, |
153 Handle<Object> value) { | 153 Handle<Object> value) { |
| 154 if (isolate->debug()->is_active()) { |
| 155 isolate->debug()->OnAsyncTaskEvent( |
| 156 debug::kDebugEnqueueRecurring, |
| 157 isolate->debug()->NextAsyncTaskId(promise), |
| 158 status == v8::Promise::kFulfilled ? kDebugPromiseResolve |
| 159 : kDebugPromiseReject); |
| 160 } |
154 // Check if there are any callbacks. | 161 // Check if there are any callbacks. |
155 if (!promise->deferred_promise()->IsUndefined(isolate)) { | 162 if (!promise->deferred_promise()->IsUndefined(isolate)) { |
156 Handle<Object> tasks((status == v8::Promise::kFulfilled) | 163 Handle<Object> tasks((status == v8::Promise::kFulfilled) |
157 ? promise->fulfill_reactions() | 164 ? promise->fulfill_reactions() |
158 : promise->reject_reactions(), | 165 : promise->reject_reactions(), |
159 isolate); | 166 isolate); |
160 Handle<PromiseReactionJobInfo> info = | 167 Handle<PromiseReactionJobInfo> info = |
161 isolate->factory()->NewPromiseReactionJobInfo( | 168 isolate->factory()->NewPromiseReactionJobInfo( |
162 promise, value, tasks, handle(promise->deferred_promise(), isolate), | 169 promise, value, tasks, handle(promise->deferred_promise(), isolate), |
163 handle(promise->deferred_on_resolve(), isolate), | 170 handle(promise->deferred_on_resolve(), isolate), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 HandleScope scope(isolate); | 287 HandleScope scope(isolate); |
281 DCHECK_EQ(1, args.length()); | 288 DCHECK_EQ(1, args.length()); |
282 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 289 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
283 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, | 290 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, |
284 isolate->factory()->undefined_value()); | 291 isolate->factory()->undefined_value()); |
285 return isolate->heap()->undefined_value(); | 292 return isolate->heap()->undefined_value(); |
286 } | 293 } |
287 | 294 |
288 } // namespace internal | 295 } // namespace internal |
289 } // namespace v8 | 296 } // namespace v8 |
OLD | NEW |