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 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 global_handles_(NULL), | 2208 global_handles_(NULL), |
2209 eternal_handles_(NULL), | 2209 eternal_handles_(NULL), |
2210 thread_manager_(NULL), | 2210 thread_manager_(NULL), |
2211 regexp_stack_(NULL), | 2211 regexp_stack_(NULL), |
2212 date_cache_(NULL), | 2212 date_cache_(NULL), |
2213 call_descriptor_data_(NULL), | 2213 call_descriptor_data_(NULL), |
2214 // TODO(bmeurer) Initialized lazily because it depends on flags; can | 2214 // TODO(bmeurer) Initialized lazily because it depends on flags; can |
2215 // be fixed once the default isolate cleanup is done. | 2215 // be fixed once the default isolate cleanup is done. |
2216 random_number_generator_(NULL), | 2216 random_number_generator_(NULL), |
2217 rail_mode_(PERFORMANCE_ANIMATION), | 2217 rail_mode_(PERFORMANCE_ANIMATION), |
| 2218 promise_hook_or_debug_is_active_(false), |
2218 promise_hook_(NULL), | 2219 promise_hook_(NULL), |
2219 load_start_time_ms_(0), | 2220 load_start_time_ms_(0), |
2220 serializer_enabled_(enable_serializer), | 2221 serializer_enabled_(enable_serializer), |
2221 has_fatal_error_(false), | 2222 has_fatal_error_(false), |
2222 initialized_from_snapshot_(false), | 2223 initialized_from_snapshot_(false), |
2223 is_tail_call_elimination_enabled_(true), | 2224 is_tail_call_elimination_enabled_(true), |
2224 is_isolate_in_background_(false), | 2225 is_isolate_in_background_(false), |
2225 cpu_profiler_(NULL), | 2226 cpu_profiler_(NULL), |
2226 heap_profiler_(NULL), | 2227 heap_profiler_(NULL), |
2227 code_event_dispatcher_(new CodeEventDispatcher()), | 2228 code_event_dispatcher_(new CodeEventDispatcher()), |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3238 | 3239 |
3239 if (call_completed_callbacks_.is_empty()) return; | 3240 if (call_completed_callbacks_.is_empty()) return; |
3240 // Fire callbacks. Increase call depth to prevent recursive callbacks. | 3241 // Fire callbacks. Increase call depth to prevent recursive callbacks. |
3241 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this); | 3242 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this); |
3242 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate); | 3243 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate); |
3243 for (int i = 0; i < call_completed_callbacks_.length(); i++) { | 3244 for (int i = 0; i < call_completed_callbacks_.length(); i++) { |
3244 call_completed_callbacks_.at(i)(isolate); | 3245 call_completed_callbacks_.at(i)(isolate); |
3245 } | 3246 } |
3246 } | 3247 } |
3247 | 3248 |
3248 void Isolate::SetPromiseHook(PromiseHook hook) { promise_hook_ = hook; } | 3249 void Isolate::DebugStateUpdated() { |
| 3250 promise_hook_or_debug_is_active_ = promise_hook_ || debug()->is_active(); |
| 3251 } |
| 3252 |
| 3253 void Isolate::SetPromiseHook(PromiseHook hook) { |
| 3254 promise_hook_ = hook; |
| 3255 DebugStateUpdated(); |
| 3256 } |
3249 | 3257 |
3250 void Isolate::RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise, | 3258 void Isolate::RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise, |
3251 Handle<Object> parent) { | 3259 Handle<Object> parent) { |
| 3260 if (debug()->is_active()) debug()->RunPromiseHook(type, promise, parent); |
3252 if (promise_hook_ == nullptr) return; | 3261 if (promise_hook_ == nullptr) return; |
3253 promise_hook_(type, v8::Utils::PromiseToLocal(promise), | 3262 promise_hook_(type, v8::Utils::PromiseToLocal(promise), |
3254 v8::Utils::ToLocal(parent)); | 3263 v8::Utils::ToLocal(parent)); |
3255 } | 3264 } |
3256 | 3265 |
3257 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) { | 3266 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) { |
3258 promise_reject_callback_ = callback; | 3267 promise_reject_callback_ = callback; |
3259 } | 3268 } |
3260 | 3269 |
3261 | 3270 |
3262 void Isolate::ReportPromiseReject(Handle<JSObject> promise, | 3271 void Isolate::ReportPromiseReject(Handle<JSObject> promise, |
3263 Handle<Object> value, | 3272 Handle<Object> value, |
3264 v8::PromiseRejectEvent event) { | 3273 v8::PromiseRejectEvent event) { |
3265 if (promise_reject_callback_ == NULL) return; | 3274 if (promise_reject_callback_ == NULL) return; |
3266 Handle<JSArray> stack_trace; | 3275 Handle<JSArray> stack_trace; |
3267 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { | 3276 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { |
3268 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); | 3277 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); |
3269 } | 3278 } |
3270 promise_reject_callback_(v8::PromiseRejectMessage( | 3279 promise_reject_callback_(v8::PromiseRejectMessage( |
3271 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), | 3280 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), |
3272 v8::Utils::StackTraceToLocal(stack_trace))); | 3281 v8::Utils::StackTraceToLocal(stack_trace))); |
3273 } | 3282 } |
3274 | 3283 |
3275 namespace { | |
3276 class PromiseDebugEventScope { | |
3277 public: | |
3278 PromiseDebugEventScope(Isolate* isolate, int id) | |
3279 : isolate_(isolate), id_(id) { | |
3280 if (isolate_->debug()->is_active() && id_ != kDebugPromiseNoID) { | |
3281 isolate_->debug()->OnAsyncTaskEvent(debug::kDebugWillHandle, id_); | |
3282 } | |
3283 } | |
3284 | |
3285 ~PromiseDebugEventScope() { | |
3286 if (isolate_->debug()->is_active() && id_ != kDebugPromiseNoID) { | |
3287 isolate_->debug()->OnAsyncTaskEvent(debug::kDebugDidHandle, id_); | |
3288 } | |
3289 } | |
3290 | |
3291 private: | |
3292 Isolate* isolate_; | |
3293 int id_; | |
3294 }; | |
3295 } // namespace | |
3296 | |
3297 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, | 3284 void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info, |
3298 MaybeHandle<Object>* result, | 3285 MaybeHandle<Object>* result, |
3299 MaybeHandle<Object>* maybe_exception) { | 3286 MaybeHandle<Object>* maybe_exception) { |
3300 PromiseDebugEventScope helper(this, info->debug_id()); | |
3301 | |
3302 Handle<Object> value(info->value(), this); | 3287 Handle<Object> value(info->value(), this); |
3303 Handle<Object> tasks(info->tasks(), this); | 3288 Handle<Object> tasks(info->tasks(), this); |
3304 Handle<JSFunction> promise_handle_fn = promise_handle(); | 3289 Handle<JSFunction> promise_handle_fn = promise_handle(); |
3305 Handle<Object> undefined = factory()->undefined_value(); | 3290 Handle<Object> undefined = factory()->undefined_value(); |
3306 Handle<Object> deferred_promise(info->deferred_promise(), this); | 3291 Handle<Object> deferred_promise(info->deferred_promise(), this); |
3307 | 3292 |
3308 if (deferred_promise->IsFixedArray()) { | 3293 if (deferred_promise->IsFixedArray()) { |
3309 DCHECK(tasks->IsFixedArray()); | 3294 DCHECK(tasks->IsFixedArray()); |
3310 Handle<FixedArray> deferred_promise_arr = | 3295 Handle<FixedArray> deferred_promise_arr = |
3311 Handle<FixedArray>::cast(deferred_promise); | 3296 Handle<FixedArray>::cast(deferred_promise); |
(...skipping 21 matching lines...) Expand all Loading... |
3333 handle(info->deferred_on_reject(), this)}; | 3318 handle(info->deferred_on_reject(), this)}; |
3334 *result = Execution::TryCall( | 3319 *result = Execution::TryCall( |
3335 this, promise_handle_fn, undefined, arraysize(argv), argv, | 3320 this, promise_handle_fn, undefined, arraysize(argv), argv, |
3336 Execution::MessageHandling::kReport, maybe_exception); | 3321 Execution::MessageHandling::kReport, maybe_exception); |
3337 } | 3322 } |
3338 } | 3323 } |
3339 | 3324 |
3340 void Isolate::PromiseResolveThenableJob( | 3325 void Isolate::PromiseResolveThenableJob( |
3341 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, | 3326 Handle<PromiseResolveThenableJobInfo> info, MaybeHandle<Object>* result, |
3342 MaybeHandle<Object>* maybe_exception) { | 3327 MaybeHandle<Object>* maybe_exception) { |
3343 PromiseDebugEventScope helper(this, info->debug_id()); | |
3344 | |
3345 Handle<JSReceiver> thenable(info->thenable(), this); | 3328 Handle<JSReceiver> thenable(info->thenable(), this); |
3346 Handle<JSFunction> resolve(info->resolve(), this); | 3329 Handle<JSFunction> resolve(info->resolve(), this); |
3347 Handle<JSFunction> reject(info->reject(), this); | 3330 Handle<JSFunction> reject(info->reject(), this); |
3348 Handle<JSReceiver> then(info->then(), this); | 3331 Handle<JSReceiver> then(info->then(), this); |
3349 Handle<Object> argv[] = {resolve, reject}; | 3332 Handle<Object> argv[] = {resolve, reject}; |
3350 *result = | 3333 *result = |
3351 Execution::TryCall(this, then, thenable, arraysize(argv), argv, | 3334 Execution::TryCall(this, then, thenable, arraysize(argv), argv, |
3352 Execution::MessageHandling::kReport, maybe_exception); | 3335 Execution::MessageHandling::kReport, maybe_exception); |
3353 | 3336 |
3354 Handle<Object> reason; | 3337 Handle<Object> reason; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3665 // Then check whether this scope intercepts. | 3648 // Then check whether this scope intercepts. |
3666 if ((flag & intercept_mask_)) { | 3649 if ((flag & intercept_mask_)) { |
3667 intercepted_flags_ |= flag; | 3650 intercepted_flags_ |= flag; |
3668 return true; | 3651 return true; |
3669 } | 3652 } |
3670 return false; | 3653 return false; |
3671 } | 3654 } |
3672 | 3655 |
3673 } // namespace internal | 3656 } // namespace internal |
3674 } // namespace v8 | 3657 } // namespace v8 |
OLD | NEW |