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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 | 1255 |
1256 bool Debug::IsBreakOnException(ExceptionBreakType type) { | 1256 bool Debug::IsBreakOnException(ExceptionBreakType type) { |
1257 if (type == BreakUncaughtException) { | 1257 if (type == BreakUncaughtException) { |
1258 return break_on_uncaught_exception_; | 1258 return break_on_uncaught_exception_; |
1259 } else { | 1259 } else { |
1260 return break_on_exception_; | 1260 return break_on_exception_; |
1261 } | 1261 } |
1262 } | 1262 } |
1263 | 1263 |
1264 | 1264 |
1265 bool Debug::PromiseHasRejectHandler(Handle<JSObject> promise) { | |
1266 Handle<JSFunction> fun = Handle<JSFunction>::cast( | |
1267 JSObject::GetDataProperty(isolate_->js_builtins_object(), | |
1268 isolate_->factory()->NewStringFromStaticChars( | |
1269 "PromiseHasRejectHandler"))); | |
1270 Handle<Object> result = | |
1271 Execution::Call(isolate_, fun, promise, 0, NULL).ToHandleChecked(); | |
1272 return result->IsTrue(); | |
1273 } | |
1274 | |
1275 | |
1276 void Debug::PrepareStep(StepAction step_action, | 1265 void Debug::PrepareStep(StepAction step_action, |
1277 int step_count, | 1266 int step_count, |
1278 StackFrame::Id frame_id) { | 1267 StackFrame::Id frame_id) { |
1279 HandleScope scope(isolate_); | 1268 HandleScope scope(isolate_); |
1280 | 1269 |
1281 PrepareForBreakPoints(); | 1270 PrepareForBreakPoints(); |
1282 | 1271 |
1283 DCHECK(in_debug_scope()); | 1272 DCHECK(in_debug_scope()); |
1284 | 1273 |
1285 // Remember this step action and count. | 1274 // Remember this step action and count. |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2504 void Debug::OnThrow(Handle<Object> exception, bool uncaught) { | 2493 void Debug::OnThrow(Handle<Object> exception, bool uncaught) { |
2505 if (in_debug_scope() || ignore_events()) return; | 2494 if (in_debug_scope() || ignore_events()) return; |
2506 // Temporarily clear any scheduled_exception to allow evaluating | 2495 // Temporarily clear any scheduled_exception to allow evaluating |
2507 // JavaScript from the debug event handler. | 2496 // JavaScript from the debug event handler. |
2508 HandleScope scope(isolate_); | 2497 HandleScope scope(isolate_); |
2509 Handle<Object> scheduled_exception; | 2498 Handle<Object> scheduled_exception; |
2510 if (isolate_->has_scheduled_exception()) { | 2499 if (isolate_->has_scheduled_exception()) { |
2511 scheduled_exception = handle(isolate_->scheduled_exception(), isolate_); | 2500 scheduled_exception = handle(isolate_->scheduled_exception(), isolate_); |
2512 isolate_->clear_scheduled_exception(); | 2501 isolate_->clear_scheduled_exception(); |
2513 } | 2502 } |
2514 OnException(exception, uncaught, isolate_->GetPromiseOnStackOnThrow()); | 2503 Handle<Object> promise = isolate_->GetPromiseOnStackOnThrow(); |
2504 if (promise->IsJSObject()) { | |
2505 // Mark the promise as already having triggered a message. | |
2506 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); | |
2507 JSObject::SetProperty(Handle<JSObject>::cast(promise), key, key, STRICT) | |
2508 .Assert(); | |
2509 } | |
2510 OnException(exception, uncaught, promise); | |
2515 if (!scheduled_exception.is_null()) { | 2511 if (!scheduled_exception.is_null()) { |
2516 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; | 2512 isolate_->thread_local_top()->scheduled_exception_ = *scheduled_exception; |
2517 } | 2513 } |
2518 } | 2514 } |
2519 | 2515 |
2520 | 2516 |
2521 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { | 2517 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { |
2522 if (in_debug_scope() || ignore_events()) return; | 2518 if (in_debug_scope() || ignore_events()) return; |
2523 HandleScope scope(isolate_); | 2519 HandleScope scope(isolate_); |
2524 OnException(value, false, promise); | 2520 // Check whether the promise has been marked as having triggered a message. |
2521 Handle<Symbol> key = isolate_->factory()->promise_debug_marker_symbol(); | |
2522 if (JSObject::GetDataProperty(promise, key)->IsUndefined()) { | |
2523 OnException(value, false, promise); | |
aandrey
2014/09/30 14:43:27
But we should also call JSObject::SetProperty(Hand
| |
2524 } | |
2525 } | |
2526 | |
2527 | |
2528 MaybeHandle<Object> Debug::PromiseHasUserDefinedRejectHandler( | |
2529 Handle<JSObject> promise) { | |
2530 Handle<JSFunction> fun = Handle<JSFunction>::cast( | |
2531 JSObject::GetDataProperty(isolate_->js_builtins_object(), | |
2532 isolate_->factory()->NewStringFromStaticChars( | |
2533 "PromiseHasUserDefinedRejectHandler"))); | |
2534 return Execution::Call(isolate_, fun, promise, 0, NULL); | |
2525 } | 2535 } |
2526 | 2536 |
2527 | 2537 |
2528 void Debug::OnException(Handle<Object> exception, bool uncaught, | 2538 void Debug::OnException(Handle<Object> exception, bool uncaught, |
2529 Handle<Object> promise) { | 2539 Handle<Object> promise) { |
2530 if (promise->IsJSObject()) { | 2540 if (!uncaught && promise->IsJSObject()) { |
2531 uncaught |= !PromiseHasRejectHandler(Handle<JSObject>::cast(promise)); | 2541 // Check whether the promise reject is considered an uncaught exception. |
2542 Handle<Object> has_reject_handler; | |
2543 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
2544 isolate_, has_reject_handler, | |
2545 PromiseHasUserDefinedRejectHandler(Handle<JSObject>::cast(promise)), | |
2546 /* void */); | |
2547 uncaught = has_reject_handler->IsFalse(); | |
2532 } | 2548 } |
2533 // Bail out if exception breaks are not active | 2549 // Bail out if exception breaks are not active |
2534 if (uncaught) { | 2550 if (uncaught) { |
2535 // Uncaught exceptions are reported by either flags. | 2551 // Uncaught exceptions are reported by either flags. |
2536 if (!(break_on_uncaught_exception_ || break_on_exception_)) return; | 2552 if (!(break_on_uncaught_exception_ || break_on_exception_)) return; |
2537 } else { | 2553 } else { |
2538 // Caught exceptions are reported is activated. | 2554 // Caught exceptions are reported is activated. |
2539 if (!break_on_exception_) return; | 2555 if (!break_on_exception_) return; |
2540 } | 2556 } |
2541 | 2557 |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3370 logger_->DebugEvent("Put", message.text()); | 3386 logger_->DebugEvent("Put", message.text()); |
3371 } | 3387 } |
3372 | 3388 |
3373 | 3389 |
3374 void LockingCommandMessageQueue::Clear() { | 3390 void LockingCommandMessageQueue::Clear() { |
3375 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 3391 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
3376 queue_.Clear(); | 3392 queue_.Clear(); |
3377 } | 3393 } |
3378 | 3394 |
3379 } } // namespace v8::internal | 3395 } } // namespace v8::internal |
OLD | NEW |