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

Unified Diff: src/isolate.cc

Issue 2314903004: [promises] Move PromiseResolveThenableJob to c++ (Closed)
Patch Set: 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') | src/objects.h » ('J')
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 dcf0dbd4c42b0cc4c3c5b19a08c2fdb327466c5f..08a09b8b064ab2259a03293e97d28dd8a65fd5d1 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -2921,9 +2921,29 @@ void Isolate::ReportPromiseReject(Handle<JSObject> promise,
v8::Utils::StackTraceToLocal(stack_trace)));
}
+void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container) {
+ MaybeHandle<Object> maybe_exception;
+ Handle<Object> resolve(container->resolve(), this);
+ Handle<Object> reject(container->reject(), this);
+ Handle<Object> promise(container->promise(), this);
+ Handle<Object> thenable(container->thenable(), this);
+ Handle<Object> then(container->then(), 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(),
+ arraysize(reason_arg), reason_arg);
+ }
+}
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());
@@ -2984,13 +3004,17 @@ 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 {
+ Handle<PromiseContainer> container =
+ Handle<PromiseContainer>::cast(microtask);
+ PromiseResolveThenableJob(container);
}
});
}
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698