Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Unified Diff: src/isolate.cc

Issue 2314903004: [promises] Move PromiseResolveThenableJob to c++ (Closed)
Patch Set: address review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
});
}
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698