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 26 matching lines...) Expand all Loading... |
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( | 46 isolate->debug()->OnAsyncTaskEvent( |
47 debug::kDebugEnqueueRecurring, | 47 debug::kDebugEnqueuePromiseReject, |
48 isolate->debug()->NextAsyncTaskId(promise), kDebugPromiseReject); | 48 isolate->debug()->NextAsyncTaskId(promise)); |
49 } | 49 } |
50 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); | 50 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); |
51 return isolate->heap()->undefined_value(); | 51 return isolate->heap()->undefined_value(); |
52 } | 52 } |
53 | 53 |
54 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { | 54 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { |
55 DCHECK_EQ(1, args.length()); | 55 DCHECK_EQ(1, args.length()); |
56 HandleScope scope(isolate); | 56 HandleScope scope(isolate); |
57 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 57 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
58 // At this point, no revocation has been issued before | 58 // At this point, no revocation has been issued before |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if (!id->IsSmi()) { | 105 if (!id->IsSmi()) { |
106 return false; | 106 return false; |
107 } | 107 } |
108 | 108 |
109 *debug_id = Handle<Smi>::cast(id)->value(); | 109 *debug_id = Handle<Smi>::cast(id)->value(); |
110 return true; | 110 return true; |
111 } | 111 } |
112 | 112 |
113 void SetDebugInfo(Isolate* isolate, Handle<JSPromise> promise, | 113 void SetDebugInfo(Isolate* isolate, Handle<JSPromise> promise, |
114 Handle<PromiseReactionJobInfo> info, int status) { | 114 Handle<PromiseReactionJobInfo> info, int status) { |
115 int id; | 115 int id = kDebugPromiseNoID; |
116 PromiseDebugActionName name; | 116 if (!GetDebugIdForAsyncFunction(isolate, info, &id)) { |
117 | |
118 if (GetDebugIdForAsyncFunction(isolate, info, &id)) { | |
119 name = kDebugAsyncFunction; | |
120 } else { | |
121 id = isolate->debug()->NextAsyncTaskId(promise); | 117 id = isolate->debug()->NextAsyncTaskId(promise); |
122 DCHECK(status != v8::Promise::kPending); | 118 DCHECK(status != v8::Promise::kPending); |
123 name = status == v8::Promise::kFulfilled ? kDebugPromiseResolve | |
124 : kDebugPromiseReject; | |
125 } | 119 } |
126 | |
127 info->set_debug_id(id); | 120 info->set_debug_id(id); |
128 info->set_debug_name(name); | |
129 } | 121 } |
130 | 122 |
131 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise, | 123 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise, |
132 Handle<PromiseReactionJobInfo> info, | 124 Handle<PromiseReactionJobInfo> info, |
133 int status) { | 125 int status) { |
134 if (isolate->debug()->is_active()) { | 126 if (isolate->debug()->is_active()) { |
135 SetDebugInfo(isolate, promise, info, status); | 127 SetDebugInfo(isolate, promise, info, status); |
136 } | 128 } |
137 | 129 |
138 isolate->EnqueueMicrotask(info); | 130 isolate->EnqueueMicrotask(info); |
139 } | 131 } |
140 | 132 |
141 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, | 133 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, |
142 Handle<Object> result) { | 134 Handle<Object> result) { |
143 promise->set_status(status); | 135 promise->set_status(status); |
144 promise->set_result(*result); | 136 promise->set_result(*result); |
145 promise->set_deferred_promise(isolate->heap()->undefined_value()); | 137 promise->set_deferred_promise(isolate->heap()->undefined_value()); |
146 promise->set_deferred_on_resolve(isolate->heap()->undefined_value()); | 138 promise->set_deferred_on_resolve(isolate->heap()->undefined_value()); |
147 promise->set_deferred_on_reject(isolate->heap()->undefined_value()); | 139 promise->set_deferred_on_reject(isolate->heap()->undefined_value()); |
148 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); | 140 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); |
149 promise->set_reject_reactions(isolate->heap()->undefined_value()); | 141 promise->set_reject_reactions(isolate->heap()->undefined_value()); |
150 } | 142 } |
151 | 143 |
152 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, int status, | 144 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, int status, |
153 Handle<Object> value) { | 145 Handle<Object> value) { |
154 if (isolate->debug()->is_active()) { | 146 if (isolate->debug()->is_active()) { |
155 isolate->debug()->OnAsyncTaskEvent( | 147 isolate->debug()->OnAsyncTaskEvent( |
156 debug::kDebugEnqueueRecurring, | 148 status == v8::Promise::kFulfilled ? debug::kDebugEnqueuePromiseResolve |
157 isolate->debug()->NextAsyncTaskId(promise), | 149 : debug::kDebugEnqueuePromiseReject, |
158 status == v8::Promise::kFulfilled ? kDebugPromiseResolve | 150 isolate->debug()->NextAsyncTaskId(promise)); |
159 : kDebugPromiseReject); | |
160 } | 151 } |
161 // Check if there are any callbacks. | 152 // Check if there are any callbacks. |
162 if (!promise->deferred_promise()->IsUndefined(isolate)) { | 153 if (!promise->deferred_promise()->IsUndefined(isolate)) { |
163 Handle<Object> tasks((status == v8::Promise::kFulfilled) | 154 Handle<Object> tasks((status == v8::Promise::kFulfilled) |
164 ? promise->fulfill_reactions() | 155 ? promise->fulfill_reactions() |
165 : promise->reject_reactions(), | 156 : promise->reject_reactions(), |
166 isolate); | 157 isolate); |
167 Handle<PromiseReactionJobInfo> info = | 158 Handle<PromiseReactionJobInfo> info = |
168 isolate->factory()->NewPromiseReactionJobInfo( | 159 isolate->factory()->NewPromiseReactionJobInfo( |
169 value, tasks, handle(promise->deferred_promise(), isolate), | 160 value, tasks, handle(promise->deferred_promise(), isolate), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 HandleScope scope(isolate); | 279 HandleScope scope(isolate); |
289 DCHECK_EQ(1, args.length()); | 280 DCHECK_EQ(1, args.length()); |
290 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 281 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
291 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, | 282 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, |
292 isolate->factory()->undefined_value()); | 283 isolate->factory()->undefined_value()); |
293 return isolate->heap()->undefined_value(); | 284 return isolate->heap()->undefined_value(); |
294 } | 285 } |
295 | 286 |
296 } // namespace internal | 287 } // namespace internal |
297 } // namespace v8 | 288 } // namespace v8 |
OLD | NEW |