Chromium Code Reviews| Index: src/isolate.cc |
| diff --git a/src/isolate.cc b/src/isolate.cc |
| index 20ff7ff899e317ae3f62f84099117d0165e16677..05b128e17aa3211fc079aec5f66c87f1b93b6c2f 100644 |
| --- a/src/isolate.cc |
| +++ b/src/isolate.cc |
| @@ -24,6 +24,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 +3009,50 @@ 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()) { |
|
adamk
2016/10/11 23:14:30
I think you could create a helper class that'd enc
gsathya
2016/10/12 02:00:43
Done. But it's the same LoC
|
| + 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()) { |
|
adamk
2016/10/11 23:14:30
Can you add a comment here about the two possible
gsathya
2016/10/12 02:00:43
Done.
|
| + Handle<JSArray> array = Handle<JSArray>::cast(tasks); |
| + DCHECK(array->length()->IsSmi()); |
| + Handle<FixedArrayBase> elements(array->elements(), this); |
|
adamk
2016/10/11 23:14:30
This is now unused.
gsathya
2016/10/12 02:00:44
Done.
|
| + int length = Smi::cast(array->length())->value(); |
| + ElementsAccessor* accessor = array->GetElementsAccessor(); |
| + for (int i = 0; i < length; i += 2) { |
|
adamk
2016/10/11 23:14:30
Please add a DCHECK that length is even (otherwise
gsathya
2016/10/12 02:00:44
Done.
|
| + Handle<Object> argv[] = {value, accessor->Get(array, i), |
|
adamk
2016/10/11 23:14:30
Please add the DCHECK for Has(i) and Has(i+1).
gsathya
2016/10/12 02:00:44
Done.
|
| + accessor->Get(array, i + 1)}; |
| + *result = Execution::TryCall(this, promise_handle(), |
|
adamk
2016/10/11 23:14:30
I'd hoist this out of the loop, you could store it
gsathya
2016/10/12 02:00:43
Done.
|
| + factory()->undefined_value(), |
|
adamk
2016/10/11 23:14:30
Same as the above, I'd hoist this out.
gsathya
2016/10/12 02:00:43
Done.
|
| + arraysize(argv), argv, maybe_exception); |
|
adamk
2016/10/11 23:14:30
I'm not sure the same logic about result and maybe
gsathya
2016/10/12 02:00:43
Done.
|
| + } |
| + } else { |
| + Handle<Object> deferred(promise_handle_info->deferred(), this); |
| + Handle<Object> argv[] = {value, tasks, deferred}; |
| + *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 +3089,9 @@ void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container, |
| } |
| void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
| + // TODO(gsathya): remove IsJSFunction? |
|
adamk
2016/10/11 23:14:30
You'd have to change the V8 API before you could d
gsathya
2016/10/12 02:00:43
Done.
|
| 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 +3143,17 @@ 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(); |
| + } |
| + |
| set_context(context->native_context()); |
| handle_scope_implementer_->EnterMicrotaskContext( |
| Handle<Context>(context, this)); |
| @@ -3116,8 +3168,13 @@ void Isolate::RunMicrotasksInternal() { |
| factory()->undefined_value(), 0, NULL, |
| &maybe_exception); |
| } else { |
| - PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask), |
| - &result, &maybe_exception); |
| + if (microtask->IsPromiseContainer()) { |
|
adamk
2016/10/11 23:14:30
This should be merged with the else above
gsathya
2016/10/12 02:00:43
Done.
|
| + PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask), |
| + &result, &maybe_exception); |
| + } else { |
| + PromiseReactionJob(Handle<PromiseHandleInfo>::cast(microtask), |
| + &result, &maybe_exception); |
| + } |
| } |
| handle_scope_implementer_->LeaveMicrotaskContext(); |