Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index c7b7486d1e6be0e650d1357e7ca9357efc445745..fb5d9a74582cbd49d4147a06cb4d1381881aa39f 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -2914,9 +2914,46 @@ 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<JSObject> promise(container->promise(), this); |
adamk
2016/09/14 22:52:51
This doesn't seem to be used at all. Why is it pas
|
+ Handle<JSObject> 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 = |
+ Execution::Call(this, reject, factory()->undefined_value(), |
adamk
2016/09/14 22:52:51
What happens if the reject handler throws?
|
+ 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()); |
@@ -2977,13 +3014,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)); |
} |
}); |
} |