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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 HandleScope scope(isolate); | 188 HandleScope scope(isolate); |
189 DCHECK_EQ(2, args.length()); | 189 DCHECK_EQ(2, args.length()); |
190 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0); | 190 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0); |
191 CONVERT_SMI_ARG_CHECKED(status, 1); | 191 CONVERT_SMI_ARG_CHECKED(status, 1); |
192 EnqueuePromiseReactionJob(isolate, info, status); | 192 EnqueuePromiseReactionJob(isolate, info, status); |
193 return isolate->heap()->undefined_value(); | 193 return isolate->heap()->undefined_value(); |
194 } | 194 } |
195 | 195 |
196 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { | 196 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { |
197 HandleScope scope(isolate); | 197 HandleScope scope(isolate); |
198 DCHECK_EQ(3, args.length()); | 198 DCHECK(args.length() == 1); |
199 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | 199 CONVERT_ARG_HANDLE_CHECKED(PromiseResolveThenableJobInfo, info, 0); |
200 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1); | |
201 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2); | |
202 | |
203 // TODO(gsathya): Add fast path for native promises with unmodified | |
204 // PromiseThen (which don't need these resolving functions, but | |
205 // instead can just call resolve/reject directly). | |
206 Handle<JSFunction> resolve, reject; | |
207 PromiseUtils::CreateResolvingFunctions( | |
208 isolate, promise, isolate->factory()->false_value(), &resolve, &reject); | |
209 | |
210 int debug_id = kDebugPromiseFirstID; | |
211 PromiseDebugActionName debug_name = kDebugNotActive; | |
212 if (isolate->debug()->is_active()) { | |
213 debug_id = isolate->GetNextDebugMicrotaskId(); | |
214 debug_name = kDebugPromiseResolveThenableJob; | |
215 isolate->debug()->OnAsyncTaskEvent(kDebugEnqueue, debug_id, debug_name); | |
216 } | |
217 | |
218 Handle<PromiseResolveThenableJobInfo> info = | |
219 isolate->factory()->NewPromiseResolveThenableJobInfo( | |
220 resolution, then, resolve, reject, debug_id, debug_name, | |
221 isolate->native_context()); | |
222 isolate->EnqueueMicrotask(info); | 200 isolate->EnqueueMicrotask(info); |
223 | |
224 return isolate->heap()->undefined_value(); | 201 return isolate->heap()->undefined_value(); |
225 } | 202 } |
226 | 203 |
227 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { | 204 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { |
228 HandleScope scope(isolate); | 205 HandleScope scope(isolate); |
229 DCHECK_EQ(1, args.length()); | 206 DCHECK_EQ(1, args.length()); |
230 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); | 207 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); |
231 isolate->EnqueueMicrotask(microtask); | 208 isolate->EnqueueMicrotask(microtask); |
232 return isolate->heap()->undefined_value(); | 209 return isolate->heap()->undefined_value(); |
233 } | 210 } |
234 | 211 |
235 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { | 212 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { |
236 HandleScope scope(isolate); | 213 HandleScope scope(isolate); |
237 DCHECK_EQ(0, args.length()); | 214 DCHECK_EQ(0, args.length()); |
238 isolate->RunMicrotasks(); | 215 isolate->RunMicrotasks(); |
239 return isolate->heap()->undefined_value(); | 216 return isolate->heap()->undefined_value(); |
240 } | 217 } |
241 | 218 |
242 RUNTIME_FUNCTION(Runtime_CreateResolvingFunctions) { | |
243 HandleScope scope(isolate); | |
244 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | |
245 DCHECK_EQ(1, args.length()); | |
246 Handle<JSFunction> resolve, reject; | |
247 | |
248 PromiseUtils::CreateResolvingFunctions( | |
249 isolate, promise, isolate->factory()->true_value(), &resolve, &reject); | |
250 | |
251 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); | |
252 result->set(0, *resolve); | |
253 result->set(1, *reject); | |
254 | |
255 return *result; | |
256 } | |
257 | |
258 RUNTIME_FUNCTION(Runtime_PromiseStatus) { | 219 RUNTIME_FUNCTION(Runtime_PromiseStatus) { |
259 HandleScope scope(isolate); | 220 HandleScope scope(isolate); |
260 DCHECK_EQ(1, args.length()); | 221 DCHECK_EQ(1, args.length()); |
261 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 222 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
262 | 223 |
263 return Smi::FromInt(promise->status()); | 224 return Smi::FromInt(promise->status()); |
264 } | 225 } |
265 | 226 |
266 RUNTIME_FUNCTION(Runtime_PromiseResult) { | 227 RUNTIME_FUNCTION(Runtime_PromiseResult) { |
267 HandleScope scope(isolate); | 228 HandleScope scope(isolate); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 HandleScope scope(isolate); | 280 HandleScope scope(isolate); |
320 DCHECK_EQ(1, args.length()); | 281 DCHECK_EQ(1, args.length()); |
321 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 282 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
322 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, | 283 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, |
323 isolate->factory()->undefined_value()); | 284 isolate->factory()->undefined_value()); |
324 return isolate->heap()->undefined_value(); | 285 return isolate->heap()->undefined_value(); |
325 } | 286 } |
326 | 287 |
327 } // namespace internal | 288 } // namespace internal |
328 } // namespace v8 | 289 } // namespace v8 |
OLD | NEW |