Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 20ff7ff899e317ae3f62f84099117d0165e16677..4c9fda66c11150d1cdf280c2a71076da316d9437 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -8,7 +8,6 @@ |
#include <fstream> // NOLINT(readability/streams) |
#include <sstream> |
- |
#include "src/ast/context-slot-cache.h" |
#include "src/base/hashmap.h" |
#include "src/base/platform/platform.h" |
@@ -24,6 +23,7 @@ |
#include "src/crankshaft/hydrogen.h" |
#include "src/debug/debug.h" |
#include "src/deoptimizer.h" |
+#include "src/elements.h" |
#include "src/external-reference-table.h" |
#include "src/frames-inl.h" |
#include "src/ic/access-compiler-data.h" |
@@ -3008,6 +3008,55 @@ void Isolate::ReportPromiseReject(Handle<JSObject> promise, |
v8::Utils::StackTraceToLocal(stack_trace))); |
} |
+void Isolate::PromiseReactionJob(Handle<PromiseHandleInfo> promise_handle_info, |
+ MaybeHandle<Object>* result, |
+ MaybeHandle<Object>* maybe_exception) { |
+ if (debug()->is_active()) { |
+ Handle<Object> before_debug_event(promise_handle_info->before_debug_event(), |
+ this); |
+ if (before_debug_event->IsJSObject()) { |
+ debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); |
+ } |
+ } |
+ |
+ Handle<Object> value(promise_handle_info->value(), this); |
+ Handle<Object> tasks(promise_handle_info->tasks(), this); |
+ |
+ if (tasks->IsJSArray()) { |
+ Handle<JSArray> array = Handle<JSArray>::cast(tasks); |
+ DCHECK(array->length()->IsSmi()); |
+ Handle<FixedArrayBase> elements(array->elements(), this); |
+ // Safer way to get length? Check backing store? |
+ int length = elements->length(); |
+ ElementsAccessor* accessor = array->GetElementsAccessor(); |
+ for (int i = 0; i < length; i += 2) { |
+ // Do I need the check? |
+ if (accessor->HasElement(array, i, elements) && |
+ accessor->HasElement(array, i + 1, elements)) { |
+ Handle<Object> argv[] = {value, accessor->Get(array, i), |
+ accessor->Get(array, i + 1)}; |
+ *result = Execution::TryCall(this, promise_handle(), |
+ factory()->undefined_value(), |
+ arraysize(argv), argv, maybe_exception); |
+ } |
+ } |
+ } else { |
+ Handle<Object> deferreds(promise_handle_info->deferreds(), this); |
+ Handle<Object> argv[] = {value, tasks, deferreds}; |
+ *result = |
+ Execution::TryCall(this, promise_handle(), factory()->undefined_value(), |
+ arraysize(argv), argv, maybe_exception); |
+ } |
+ |
+ if (debug()->is_active()) { |
+ Handle<Object> after_debug_event(promise_handle_info->after_debug_event(), |
+ this); |
+ if (after_debug_event->IsJSObject()) { |
+ debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); |
+ } |
+ } |
+} |
+ |
void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container, |
MaybeHandle<Object>* result, |
MaybeHandle<Object>* maybe_exception) { |
@@ -3044,8 +3093,9 @@ void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container, |
} |
void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
+ // TODO(gsathya): remove IsJSFunction? |
DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
- microtask->IsPromiseContainer()); |
+ microtask->IsPromiseContainer() || microtask->IsPromiseHandleInfo()); |
Handle<FixedArray> queue(heap()->microtask_queue(), this); |
int num_tasks = pending_microtask_count(); |
DCHECK(num_tasks <= queue->length()); |
@@ -3097,11 +3147,18 @@ void Isolate::RunMicrotasksInternal() { |
callback(data); |
} else { |
SaveContext save(this); |
- Context* context = microtask->IsJSFunction() |
- ? Handle<JSFunction>::cast(microtask)->context() |
- : Handle<PromiseContainer>::cast(microtask) |
- ->resolve() |
- ->context(); |
+ Context* context; |
+ if (microtask->IsJSFunction()) { |
+ context = Handle<JSFunction>::cast(microtask)->context(); |
+ } else if (microtask->IsPromiseContainer()) { |
+ context = |
+ Handle<PromiseContainer>::cast(microtask)->resolve()->context(); |
+ } else { |
+ context = Handle<PromiseHandleInfo>::cast(microtask) |
+ ->reaction_context() |
+ ->context(); |
+ } |
+ |
set_context(context->native_context()); |
handle_scope_implementer_->EnterMicrotaskContext( |
Handle<Context>(context, this)); |
@@ -3115,9 +3172,12 @@ void Isolate::RunMicrotasksInternal() { |
result = Execution::TryCall(this, microtask_function, |
factory()->undefined_value(), 0, NULL, |
&maybe_exception); |
- } else { |
+ } else if (microtask->IsPromiseContainer()) { |
PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask), |
&result, &maybe_exception); |
+ } else if (microtask->IsPromiseHandleInfo()) { |
+ PromiseReactionJob(Handle<PromiseHandleInfo>::cast(microtask), |
+ &result, &maybe_exception); |
} |
handle_scope_implementer_->LeaveMicrotaskContext(); |