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

Unified Diff: src/isolate.cc

Issue 2554013002: Revert of Create JSPromise (Closed)
Patch Set: Created 4 years 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/heap-symbols.h ('k') | src/js/async-await.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 d3ab6aa75f876e1c5110b9f32cfae672ea128331..42a5a55b9d622a39ecf8cea37bcf555a7329b47f 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -3160,15 +3160,23 @@
Handle<Object> tasks(info->tasks(), this);
Handle<JSFunction> promise_handle_fn = promise_handle();
Handle<Object> undefined = factory()->undefined_value();
- Handle<Object> deferred(info->deferred(), this);
-
- if (deferred->IsFixedArray()) {
- DCHECK(tasks->IsFixedArray());
- Handle<FixedArray> deferred_arr = Handle<FixedArray>::cast(deferred);
- Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks);
- for (int i = 0; i < deferred_arr->length(); i++) {
- Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this),
- handle(deferred_arr->get(i), this)};
+
+ // If tasks is an array we have multiple onFulfilled/onRejected callbacks
+ // associated with the promise. The deferred object for each callback
+ // is attached to this array as well.
+ // Otherwise, there is a single callback and the deferred object is attached
+ // directly to PromiseReactionJobInfo.
+ if (tasks->IsJSArray()) {
+ Handle<JSArray> array = Handle<JSArray>::cast(tasks);
+ DCHECK(array->length()->IsSmi());
+ int length = Smi::cast(array->length())->value();
+ ElementsAccessor* accessor = array->GetElementsAccessor();
+ DCHECK(length % 2 == 0);
+ for (int i = 0; i < length; i += 2) {
+ DCHECK(accessor->HasElement(array, i));
+ DCHECK(accessor->HasElement(array, i + 1));
+ Handle<Object> argv[] = {value, accessor->Get(array, i),
+ accessor->Get(array, i + 1)};
*result = Execution::TryCall(this, promise_handle_fn, undefined,
arraysize(argv), argv, maybe_exception);
// If execution is terminating, just bail out.
@@ -3177,6 +3185,7 @@
}
}
} else {
+ Handle<Object> deferred(info->deferred(), this);
Handle<Object> argv[] = {value, tasks, deferred};
*result = Execution::TryCall(this, promise_handle_fn, undefined,
arraysize(argv), argv, maybe_exception);
« no previous file with comments | « src/heap-symbols.h ('k') | src/js/async-await.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698