Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 02e0877117e87678938a67f307cbc7daeec53864..cef49b9f07ee706c93b1c22ab86f617835a41169 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -2959,9 +2959,45 @@ void Isolate::ReportPromiseReject(Handle<JSObject> promise, |
v8::Utils::StackTraceToLocal(stack_trace))); |
} |
+void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container) { |
+ Handle<JSFunction> then(container->then(), this); |
+ SaveContext save(this); |
+ set_context(then->context()->native_context()); |
+ handle_scope_implementer_->EnterMicrotaskContext( |
+ handle(then->context(), this)); |
+ |
+ Handle<Object> before_debug_event(container->before_debug_event(), this); |
+ if (debug()->is_active() && before_debug_event->IsJSObject()) { |
+ debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); |
+ } |
+ |
+ MaybeHandle<Object> maybe_exception; |
+ Handle<JSReceiver> thenable(container->thenable(), this); |
+ Handle<JSFunction> resolve(container->resolve(), this); |
+ Handle<JSFunction> reject(container->reject(), this); |
+ Handle<Object> argv[] = {resolve, reject}; |
+ MaybeHandle<Object> result = Execution::TryCall( |
+ this, then, thenable, arraysize(argv), argv, &maybe_exception); |
+ |
+ Handle<Object> reason; |
+ if (maybe_exception.ToHandle(&reason)) { |
+ Handle<Object> reason_arg[] = {reason}; |
+ MaybeHandle<Object> status = |
adamk
2016/09/19 21:42:35
No need to assign this anymore, now that TryCall s
|
+ Execution::TryCall(this, reject, factory()->undefined_value(), |
+ arraysize(reason_arg), reason_arg); |
+ } |
+ |
+ Handle<Object> after_debug_event(container->after_debug_event(), this); |
+ if (debug()->is_active() && after_debug_event->IsJSObject()) { |
+ debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); |
+ } |
+ |
+ handle_scope_implementer_->LeaveMicrotaskContext(); |
+} |
void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
- DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); |
+ DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
+ microtask->IsPromiseContainer()); |
Handle<FixedArray> queue(heap()->microtask_queue(), this); |
int num_tasks = pending_microtask_count(); |
DCHECK(num_tasks <= queue->length()); |
@@ -3022,13 +3058,15 @@ void Isolate::RunMicrotasksInternal() { |
set_pending_microtask_count(0); |
return; |
} |
- } else { |
+ } else if (microtask->IsCallHandlerInfo()) { |
Handle<CallHandlerInfo> callback_info = |
Handle<CallHandlerInfo>::cast(microtask); |
v8::MicrotaskCallback callback = |
v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); |
void* data = v8::ToCData<void*>(callback_info->data()); |
callback(data); |
+ } else { |
+ PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask)); |
} |
}); |
} |