| OLD | NEW |
| 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 3164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3175 | 3175 |
| 3176 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, | 3176 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, |
| 3177 MaybeHandle<Object>* result, | 3177 MaybeHandle<Object>* result, |
| 3178 MaybeHandle<Object>* maybe_exception) { | 3178 MaybeHandle<Object>* maybe_exception) { |
| 3179 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); | 3179 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); |
| 3180 | 3180 |
| 3181 Handle<Object> value(info->value(), this); | 3181 Handle<Object> value(info->value(), this); |
| 3182 Handle<Object> tasks(info->tasks(), this); | 3182 Handle<Object> tasks(info->tasks(), this); |
| 3183 Handle<JSFunction> promise_handle_fn = promise_handle(); | 3183 Handle<JSFunction> promise_handle_fn = promise_handle(); |
| 3184 Handle<Object> undefined = factory()->undefined_value(); | 3184 Handle<Object> undefined = factory()->undefined_value(); |
| 3185 Handle<Object> deferred(info->deferred(), this); |
| 3185 | 3186 |
| 3186 // If tasks is an array we have multiple onFulfilled/onRejected callbacks | 3187 if (deferred->IsFixedArray()) { |
| 3187 // associated with the promise. The deferred object for each callback | 3188 DCHECK(tasks->IsFixedArray()); |
| 3188 // is attached to this array as well. | 3189 Handle<FixedArray> deferred_arr = Handle<FixedArray>::cast(deferred); |
| 3189 // Otherwise, there is a single callback and the deferred object is attached | 3190 Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks); |
| 3190 // directly to PromiseReactionJobInfo. | 3191 for (int i = 0; i < deferred_arr->length(); i++) { |
| 3191 if (tasks->IsJSArray()) { | 3192 Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this), |
| 3192 Handle<JSArray> array = Handle<JSArray>::cast(tasks); | 3193 handle(deferred_arr->get(i), this)}; |
| 3193 DCHECK(array->length()->IsSmi()); | |
| 3194 int length = Smi::cast(array->length())->value(); | |
| 3195 ElementsAccessor* accessor = array->GetElementsAccessor(); | |
| 3196 DCHECK(length % 2 == 0); | |
| 3197 for (int i = 0; i < length; i += 2) { | |
| 3198 DCHECK(accessor->HasElement(array, i)); | |
| 3199 DCHECK(accessor->HasElement(array, i + 1)); | |
| 3200 Handle<Object> argv[] = {value, accessor->Get(array, i), | |
| 3201 accessor->Get(array, i + 1)}; | |
| 3202 *result = Execution::TryCall(this, promise_handle_fn, undefined, | 3194 *result = Execution::TryCall(this, promise_handle_fn, undefined, |
| 3203 arraysize(argv), argv, maybe_exception); | 3195 arraysize(argv), argv, maybe_exception); |
| 3204 // If execution is terminating, just bail out. | 3196 // If execution is terminating, just bail out. |
| 3205 if (result->is_null() && maybe_exception->is_null()) { | 3197 if (result->is_null() && maybe_exception->is_null()) { |
| 3206 return; | 3198 return; |
| 3207 } | 3199 } |
| 3208 } | 3200 } |
| 3209 } else { | 3201 } else { |
| 3210 Handle<Object> deferred(info->deferred(), this); | |
| 3211 Handle<Object> argv[] = {value, tasks, deferred}; | 3202 Handle<Object> argv[] = {value, tasks, deferred}; |
| 3212 *result = Execution::TryCall(this, promise_handle_fn, undefined, | 3203 *result = Execution::TryCall(this, promise_handle_fn, undefined, |
| 3213 arraysize(argv), argv, maybe_exception); | 3204 arraysize(argv), argv, maybe_exception); |
| 3214 } | 3205 } |
| 3215 } | 3206 } |
| 3216 | 3207 |
| 3217 void Isolate::PromiseResolveThenableJob( | 3208 void Isolate::PromiseResolveThenableJob( |
| 3218 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, | 3209 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, |
| 3219 MaybeHandle<Object>* maybe_exception) { | 3210 MaybeHandle<Object>* maybe_exception) { |
| 3220 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); | 3211 PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name()); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3526 // Then check whether this scope intercepts. | 3517 // Then check whether this scope intercepts. |
| 3527 if ((flag & intercept_mask_)) { | 3518 if ((flag & intercept_mask_)) { |
| 3528 intercepted_flags_ |= flag; | 3519 intercepted_flags_ |= flag; |
| 3529 return true; | 3520 return true; |
| 3530 } | 3521 } |
| 3531 return false; | 3522 return false; |
| 3532 } | 3523 } |
| 3533 | 3524 |
| 3534 } // namespace internal | 3525 } // namespace internal |
| 3535 } // namespace v8 | 3526 } // namespace v8 |
| OLD | NEW |