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

Side by Side Diff: src/isolate.cc

Issue 2536463002: Create JSPromise (Closed)
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « src/heap-symbols.h ('k') | src/js/async-await.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 3142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 3153
3154 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, 3154 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info,
3155 MaybeHandle<Object>* result, 3155 MaybeHandle<Object>* result,
3156 MaybeHandle<Object>* maybe_exception) { 3156 MaybeHandle<Object>* maybe_exception) {
3157 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); 3157 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name());
3158 3158
3159 Handle<Object> value(info->value(), this); 3159 Handle<Object> value(info->value(), this);
3160 Handle<Object> tasks(info->tasks(), this); 3160 Handle<Object> tasks(info->tasks(), this);
3161 Handle<JSFunction> promise_handle_fn = promise_handle(); 3161 Handle<JSFunction> promise_handle_fn = promise_handle();
3162 Handle<Object> undefined = factory()->undefined_value(); 3162 Handle<Object> undefined = factory()->undefined_value();
3163 Handle<Object> deferred(info->deferred(), this);
3163 3164
3164 // If tasks is an array we have multiple onFulfilled/onRejected callbacks 3165 if (deferred->IsFixedArray()) {
3165 // associated with the promise. The deferred object for each callback 3166 DCHECK(tasks->IsFixedArray());
3166 // is attached to this array as well. 3167 Handle<FixedArray> deferred_arr = Handle<FixedArray>::cast(deferred);
3167 // Otherwise, there is a single callback and the deferred object is attached 3168 Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks);
3168 // directly to PromiseReactionJobInfo. 3169 for (int i = 0; i < deferred_arr->length(); i++) {
3169 if (tasks->IsJSArray()) { 3170 Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this),
3170 Handle<JSArray> array = Handle<JSArray>::cast(tasks); 3171 handle(deferred_arr->get(i), this)};
3171 DCHECK(array->length()->IsSmi());
3172 int length = Smi::cast(array->length())->value();
3173 ElementsAccessor* accessor = array->GetElementsAccessor();
3174 DCHECK(length % 2 == 0);
3175 for (int i = 0; i < length; i += 2) {
3176 DCHECK(accessor->HasElement(array, i));
3177 DCHECK(accessor->HasElement(array, i + 1));
3178 Handle<Object> argv[] = {value, accessor->Get(array, i),
3179 accessor->Get(array, i + 1)};
3180 *result = Execution::TryCall(this, promise_handle_fn, undefined, 3172 *result = Execution::TryCall(this, promise_handle_fn, undefined,
3181 arraysize(argv), argv, maybe_exception); 3173 arraysize(argv), argv, maybe_exception);
3182 // If execution is terminating, just bail out. 3174 // If execution is terminating, just bail out.
3183 if (result->is_null() && maybe_exception->is_null()) { 3175 if (result->is_null() && maybe_exception->is_null()) {
3184 return; 3176 return;
3185 } 3177 }
3186 } 3178 }
3187 } else { 3179 } else {
3188 Handle<Object> deferred(info->deferred(), this);
3189 Handle<Object> argv[] = {value, tasks, deferred}; 3180 Handle<Object> argv[] = {value, tasks, deferred};
3190 *result = Execution::TryCall(this, promise_handle_fn, undefined, 3181 *result = Execution::TryCall(this, promise_handle_fn, undefined,
3191 arraysize(argv), argv, maybe_exception); 3182 arraysize(argv), argv, maybe_exception);
3192 } 3183 }
3193 } 3184 }
3194 3185
3195 void Isolate::PromiseResolveThenableJob( 3186 void Isolate::PromiseResolveThenableJob(
3196 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, 3187 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result,
3197 MaybeHandle<Object>* maybe_exception) { 3188 MaybeHandle<Object>* maybe_exception) {
3198 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); 3189 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name());
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3504 // Then check whether this scope intercepts. 3495 // Then check whether this scope intercepts.
3505 if ((flag & intercept_mask_)) { 3496 if ((flag & intercept_mask_)) {
3506 intercepted_flags_ |= flag; 3497 intercepted_flags_ |= flag;
3507 return true; 3498 return true;
3508 } 3499 }
3509 return false; 3500 return false;
3510 } 3501 }
3511 3502
3512 } // namespace internal 3503 } // namespace internal
3513 } // namespace v8 3504 } // namespace v8
OLDNEW
« 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