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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::kDebugEnqueuePromiseReject, | 47 debug::kDebugEnqueuePromiseReject, |
48 isolate->debug()->NextAsyncTaskId(promise)); | 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_ReportPromiseReject) { |
| 55 DCHECK_EQ(2, args.length()); |
| 56 HandleScope scope(isolate); |
| 57 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
| 58 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 59 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value, |
| 60 v8::kPromiseRejectWithNoHandler); |
| 61 return isolate->heap()->undefined_value(); |
| 62 } |
| 63 |
54 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { | 64 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { |
55 DCHECK_EQ(1, args.length()); | 65 DCHECK_EQ(1, args.length()); |
56 HandleScope scope(isolate); | 66 HandleScope scope(isolate); |
57 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 67 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
58 // At this point, no revocation has been issued before | 68 // At this point, no revocation has been issued before |
59 CHECK(!promise->has_handler()); | 69 CHECK(!promise->has_handler()); |
60 isolate->ReportPromiseReject(promise, Handle<Object>(), | 70 isolate->ReportPromiseReject(promise, Handle<Object>(), |
61 v8::kPromiseHandlerAddedAfterReject); | 71 v8::kPromiseHandlerAddedAfterReject); |
62 return isolate->heap()->undefined_value(); | 72 return isolate->heap()->undefined_value(); |
63 } | 73 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise, | 133 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise, |
124 Handle<PromiseReactionJobInfo> info, | 134 Handle<PromiseReactionJobInfo> info, |
125 int status) { | 135 int status) { |
126 if (isolate->debug()->is_active()) { | 136 if (isolate->debug()->is_active()) { |
127 SetDebugInfo(isolate, promise, info, status); | 137 SetDebugInfo(isolate, promise, info, status); |
128 } | 138 } |
129 | 139 |
130 isolate->EnqueueMicrotask(info); | 140 isolate->EnqueueMicrotask(info); |
131 } | 141 } |
132 | 142 |
133 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, | |
134 Handle<Object> result) { | |
135 promise->set_status(status); | |
136 promise->set_result(*result); | |
137 promise->set_deferred_promise(isolate->heap()->undefined_value()); | |
138 promise->set_deferred_on_resolve(isolate->heap()->undefined_value()); | |
139 promise->set_deferred_on_reject(isolate->heap()->undefined_value()); | |
140 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); | |
141 promise->set_reject_reactions(isolate->heap()->undefined_value()); | |
142 } | |
143 | |
144 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, int status, | |
145 Handle<Object> value) { | |
146 if (isolate->debug()->is_active()) { | |
147 isolate->debug()->OnAsyncTaskEvent( | |
148 status == v8::Promise::kFulfilled ? debug::kDebugEnqueuePromiseResolve | |
149 : debug::kDebugEnqueuePromiseReject, | |
150 isolate->debug()->NextAsyncTaskId(promise)); | |
151 } | |
152 // Check if there are any callbacks. | |
153 if (!promise->deferred_promise()->IsUndefined(isolate)) { | |
154 Handle<Object> tasks((status == v8::Promise::kFulfilled) | |
155 ? promise->fulfill_reactions() | |
156 : promise->reject_reactions(), | |
157 isolate); | |
158 Handle<PromiseReactionJobInfo> info = | |
159 isolate->factory()->NewPromiseReactionJobInfo( | |
160 value, tasks, handle(promise->deferred_promise(), isolate), | |
161 handle(promise->deferred_on_resolve(), isolate), | |
162 handle(promise->deferred_on_reject(), isolate), | |
163 isolate->native_context()); | |
164 EnqueuePromiseReactionJob(isolate, promise, info, status); | |
165 } | |
166 | |
167 PromiseSet(isolate, promise, status, value); | |
168 } | |
169 | |
170 } // namespace | 143 } // namespace |
171 | 144 |
172 RUNTIME_FUNCTION(Runtime_PromiseReject) { | |
173 DCHECK_EQ(3, args.length()); | |
174 HandleScope scope(isolate); | |
175 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | |
176 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); | |
177 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); | |
178 | |
179 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); | |
180 PromiseFulfill(isolate, promise, v8::Promise::kRejected, reason); | |
181 | |
182 return isolate->heap()->undefined_value(); | |
183 } | |
184 | |
185 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { | 145 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { |
186 HandleScope scope(isolate); | 146 HandleScope scope(isolate); |
187 DCHECK_EQ(3, args.length()); | 147 DCHECK_EQ(3, args.length()); |
188 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 148 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
189 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 1); | 149 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 1); |
190 CONVERT_SMI_ARG_CHECKED(status, 2); | 150 CONVERT_SMI_ARG_CHECKED(status, 2); |
191 EnqueuePromiseReactionJob(isolate, promise, info, status); | 151 EnqueuePromiseReactionJob(isolate, promise, info, status); |
192 return isolate->heap()->undefined_value(); | 152 return isolate->heap()->undefined_value(); |
193 } | 153 } |
194 | 154 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 HandleScope scope(isolate); | 239 HandleScope scope(isolate); |
280 DCHECK_EQ(1, args.length()); | 240 DCHECK_EQ(1, args.length()); |
281 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 241 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
282 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, | 242 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, |
283 isolate->factory()->undefined_value()); | 243 isolate->factory()->undefined_value()); |
284 return isolate->heap()->undefined_value(); | 244 return isolate->heap()->undefined_value(); |
285 } | 245 } |
286 | 246 |
287 } // namespace internal | 247 } // namespace internal |
288 } // namespace v8 | 248 } // namespace v8 |
OLD | NEW |