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 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 // external handler which is on top of the top-most JS_ENTRY handler. | 1686 // external handler which is on top of the top-most JS_ENTRY handler. |
1687 // | 1687 // |
1688 // Note, that finally clauses would re-throw an exception unless it's aborted | 1688 // Note, that finally clauses would re-throw an exception unless it's aborted |
1689 // by jumps in control flow (like return, break, etc.) and we'll have another | 1689 // by jumps in control flow (like return, break, etc.) and we'll have another |
1690 // chance to set proper v8::TryCatch later. | 1690 // chance to set proper v8::TryCatch later. |
1691 return (entry_handler > external_handler); | 1691 return (entry_handler > external_handler); |
1692 } | 1692 } |
1693 | 1693 |
1694 | 1694 |
1695 void Isolate::ReportPendingMessages() { | 1695 void Isolate::ReportPendingMessages() { |
| 1696 DCHECK(AllowExceptions::IsAllowed(this)); |
| 1697 |
1696 Object* exception = pending_exception(); | 1698 Object* exception = pending_exception(); |
1697 | 1699 |
1698 // Try to propagate the exception to an external v8::TryCatch handler. If | 1700 // Try to propagate the exception to an external v8::TryCatch handler. If |
1699 // propagation was unsuccessful, then we will get another chance at reporting | 1701 // propagation was unsuccessful, then we will get another chance at reporting |
1700 // the pending message if the exception is re-thrown. | 1702 // the pending message if the exception is re-thrown. |
1701 bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch(); | 1703 bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch(); |
1702 if (!has_been_propagated) return; | 1704 if (!has_been_propagated) return; |
1703 | 1705 |
1704 // Clear the pending message object early to avoid endless recursion. | 1706 // Clear the pending message object early to avoid endless recursion. |
1705 Object* message_obj = thread_local_top_.pending_message_obj_; | 1707 Object* message_obj = thread_local_top_.pending_message_obj_; |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3301 Handle<FixedArray> deferred_on_resolve_arr( | 3303 Handle<FixedArray> deferred_on_resolve_arr( |
3302 FixedArray::cast(info->deferred_on_resolve()), this); | 3304 FixedArray::cast(info->deferred_on_resolve()), this); |
3303 Handle<FixedArray> deferred_on_reject_arr( | 3305 Handle<FixedArray> deferred_on_reject_arr( |
3304 FixedArray::cast(info->deferred_on_reject()), this); | 3306 FixedArray::cast(info->deferred_on_reject()), this); |
3305 Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks); | 3307 Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks); |
3306 for (int i = 0; i < deferred_promise_arr->length(); i++) { | 3308 for (int i = 0; i < deferred_promise_arr->length(); i++) { |
3307 Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this), | 3309 Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this), |
3308 handle(deferred_promise_arr->get(i), this), | 3310 handle(deferred_promise_arr->get(i), this), |
3309 handle(deferred_on_resolve_arr->get(i), this), | 3311 handle(deferred_on_resolve_arr->get(i), this), |
3310 handle(deferred_on_reject_arr->get(i), this)}; | 3312 handle(deferred_on_reject_arr->get(i), this)}; |
3311 *result = Execution::TryCall(this, promise_handle_fn, undefined, | 3313 *result = Execution::TryCall( |
3312 arraysize(argv), argv, maybe_exception); | 3314 this, promise_handle_fn, undefined, arraysize(argv), argv, |
| 3315 Execution::MessageHandling::kReport, maybe_exception); |
3313 // If execution is terminating, just bail out. | 3316 // If execution is terminating, just bail out. |
3314 if (result->is_null() && maybe_exception->is_null()) { | 3317 if (result->is_null() && maybe_exception->is_null()) { |
3315 return; | 3318 return; |
3316 } | 3319 } |
3317 } | 3320 } |
3318 } else { | 3321 } else { |
3319 Handle<Object> argv[] = {value, tasks, deferred_promise, | 3322 Handle<Object> argv[] = {value, tasks, deferred_promise, |
3320 handle(info->deferred_on_resolve(), this), | 3323 handle(info->deferred_on_resolve(), this), |
3321 handle(info->deferred_on_reject(), this)}; | 3324 handle(info->deferred_on_reject(), this)}; |
3322 *result = Execution::TryCall(this, promise_handle_fn, undefined, | 3325 *result = Execution::TryCall( |
3323 arraysize(argv), argv, maybe_exception); | 3326 this, promise_handle_fn, undefined, arraysize(argv), argv, |
| 3327 Execution::MessageHandling::kReport, maybe_exception); |
3324 } | 3328 } |
3325 } | 3329 } |
3326 | 3330 |
3327 void Isolate::PromiseResolveThenableJob( | 3331 void Isolate::PromiseResolveThenableJob( |
3328 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, | 3332 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, |
3329 MaybeHandle<Object>* maybe_exception) { | 3333 MaybeHandle<Object>* maybe_exception) { |
3330 PromiseDebugEventScope helper(this, info->debug_id()); | 3334 PromiseDebugEventScope helper(this, info->debug_id()); |
3331 | 3335 |
3332 Handle<JSReceiver> thenable(info->thenable(), this); | 3336 Handle<JSReceiver> thenable(info->thenable(), this); |
3333 Handle<JSFunction> resolve(info->resolve(), this); | 3337 Handle<JSFunction> resolve(info->resolve(), this); |
3334 Handle<JSFunction> reject(info->reject(), this); | 3338 Handle<JSFunction> reject(info->reject(), this); |
3335 Handle<JSReceiver> then(info->then(), this); | 3339 Handle<JSReceiver> then(info->then(), this); |
3336 Handle<Object> argv[] = {resolve, reject}; | 3340 Handle<Object> argv[] = {resolve, reject}; |
3337 *result = Execution::TryCall(this, then, thenable, arraysize(argv), argv, | 3341 *result = |
3338 maybe_exception); | 3342 Execution::TryCall(this, then, thenable, arraysize(argv), argv, |
| 3343 Execution::MessageHandling::kReport, maybe_exception); |
3339 | 3344 |
3340 Handle<Object> reason; | 3345 Handle<Object> reason; |
3341 if (maybe_exception->ToHandle(&reason)) { | 3346 if (maybe_exception->ToHandle(&reason)) { |
3342 DCHECK(result->is_null()); | 3347 DCHECK(result->is_null()); |
3343 Handle<Object> reason_arg[] = {reason}; | 3348 Handle<Object> reason_arg[] = {reason}; |
3344 *result = | 3349 *result = Execution::TryCall( |
3345 Execution::TryCall(this, reject, factory()->undefined_value(), | 3350 this, reject, factory()->undefined_value(), arraysize(reason_arg), |
3346 arraysize(reason_arg), reason_arg, maybe_exception); | 3351 reason_arg, Execution::MessageHandling::kReport, maybe_exception); |
3347 } | 3352 } |
3348 } | 3353 } |
3349 | 3354 |
3350 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { | 3355 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
3351 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || | 3356 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
3352 microtask->IsPromiseResolveThenableJobInfo() || | 3357 microtask->IsPromiseResolveThenableJobInfo() || |
3353 microtask->IsPromiseReactionJobInfo()); | 3358 microtask->IsPromiseReactionJobInfo()); |
3354 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 3359 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
3355 int num_tasks = pending_microtask_count(); | 3360 int num_tasks = pending_microtask_count(); |
3356 DCHECK(num_tasks <= queue->length()); | 3361 DCHECK(num_tasks <= queue->length()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3416 set_context(context->native_context()); | 3421 set_context(context->native_context()); |
3417 handle_scope_implementer_->EnterMicrotaskContext( | 3422 handle_scope_implementer_->EnterMicrotaskContext( |
3418 Handle<Context>(context, this)); | 3423 Handle<Context>(context, this)); |
3419 | 3424 |
3420 MaybeHandle<Object> result; | 3425 MaybeHandle<Object> result; |
3421 MaybeHandle<Object> maybe_exception; | 3426 MaybeHandle<Object> maybe_exception; |
3422 | 3427 |
3423 if (microtask->IsJSFunction()) { | 3428 if (microtask->IsJSFunction()) { |
3424 Handle<JSFunction> microtask_function = | 3429 Handle<JSFunction> microtask_function = |
3425 Handle<JSFunction>::cast(microtask); | 3430 Handle<JSFunction>::cast(microtask); |
3426 result = Execution::TryCall(this, microtask_function, | 3431 result = Execution::TryCall( |
3427 factory()->undefined_value(), 0, NULL, | 3432 this, microtask_function, factory()->undefined_value(), 0, |
3428 &maybe_exception); | 3433 nullptr, Execution::MessageHandling::kReport, &maybe_exception); |
3429 } else if (microtask->IsPromiseResolveThenableJobInfo()) { | 3434 } else if (microtask->IsPromiseResolveThenableJobInfo()) { |
3430 PromiseResolveThenableJob( | 3435 PromiseResolveThenableJob( |
3431 Handle<PromiseResolveThenableJobInfo>::cast(microtask), &result, | 3436 Handle<PromiseResolveThenableJobInfo>::cast(microtask), &result, |
3432 &maybe_exception); | 3437 &maybe_exception); |
3433 } else { | 3438 } else { |
3434 PromiseReactionJob(Handle<PromiseReactionJobInfo>::cast(microtask), | 3439 PromiseReactionJob(Handle<PromiseReactionJobInfo>::cast(microtask), |
3435 &result, &maybe_exception); | 3440 &result, &maybe_exception); |
3436 } | 3441 } |
3437 | 3442 |
3438 handle_scope_implementer_->LeaveMicrotaskContext(); | 3443 handle_scope_implementer_->LeaveMicrotaskContext(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3651 // Then check whether this scope intercepts. | 3656 // Then check whether this scope intercepts. |
3652 if ((flag & intercept_mask_)) { | 3657 if ((flag & intercept_mask_)) { |
3653 intercepted_flags_ |= flag; | 3658 intercepted_flags_ |= flag; |
3654 return true; | 3659 return true; |
3655 } | 3660 } |
3656 return false; | 3661 return false; |
3657 } | 3662 } |
3658 | 3663 |
3659 } // namespace internal | 3664 } // namespace internal |
3660 } // namespace v8 | 3665 } // namespace v8 |
OLD | NEW |