Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 NATIVES_CODE); | 767 NATIVES_CODE); |
| 768 | 768 |
| 769 // Silently ignore stack overflows during compilation. | 769 // Silently ignore stack overflows during compilation. |
| 770 if (function_info.is_null()) { | 770 if (function_info.is_null()) { |
| 771 ASSERT(isolate->has_pending_exception()); | 771 ASSERT(isolate->has_pending_exception()); |
| 772 isolate->clear_pending_exception(); | 772 isolate->clear_pending_exception(); |
| 773 return false; | 773 return false; |
| 774 } | 774 } |
| 775 | 775 |
| 776 // Execute the shared function in the debugger context. | 776 // Execute the shared function in the debugger context. |
| 777 bool caught_exception; | |
| 778 Handle<JSFunction> function = | 777 Handle<JSFunction> function = |
| 779 factory->NewFunctionFromSharedFunctionInfo(function_info, context); | 778 factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
| 780 | 779 |
| 781 Handle<Object> exception = | 780 Handle<Object> exception; |
| 782 Execution::TryCall(function, | 781 bool caught_exception = !Execution::TryCall( |
| 783 Handle<Object>(context->global_object(), isolate), | 782 function, |
| 784 0, | 783 Handle<Object>(context->global_object(), isolate), |
| 785 NULL, | 784 0, |
| 786 &caught_exception); | 785 NULL).ToHandle(&exception); |
| 787 | 786 |
| 788 // Check for caught exceptions. | 787 // Check for caught exceptions. |
| 789 if (caught_exception) { | 788 if (caught_exception) { |
| 790 ASSERT(!isolate->has_pending_exception()); | 789 ASSERT(!isolate->has_pending_exception()); |
| 791 MessageLocation computed_location; | 790 MessageLocation computed_location; |
| 792 isolate->ComputeLocation(&computed_location); | 791 isolate->ComputeLocation(&computed_location); |
| 793 Handle<Object> message = MessageHandler::MakeMessageObject( | 792 Handle<Object> message = MessageHandler::MakeMessageObject( |
| 794 isolate, "error_loading_debugger", &computed_location, | 793 isolate, "error_loading_debugger", &computed_location, |
| 795 Vector<Handle<Object> >::empty(), Handle<JSArray>()); | 794 Vector<Handle<Object> >::empty(), Handle<JSArray>()); |
| 796 ASSERT(!isolate->has_pending_exception()); | 795 ASSERT(!isolate->has_pending_exception()); |
| 797 if (!exception.is_null()) { | 796 if (!exception.is_null()) { |
|
Igor Sheludko
2014/04/10 15:14:42
I think exception can't be null here anymore.
| |
| 798 isolate->set_pending_exception(*exception); | 797 isolate->set_pending_exception(*exception); |
| 799 MessageHandler::ReportMessage(isolate, NULL, message); | 798 MessageHandler::ReportMessage(isolate, NULL, message); |
| 800 isolate->clear_pending_exception(); | 799 isolate->clear_pending_exception(); |
| 801 } | 800 } |
| 802 return false; | 801 return false; |
| 803 } | 802 } |
| 804 | 803 |
| 805 // Mark this script as native and return successfully. | 804 // Mark this script as native and return successfully. |
| 806 Handle<Script> script(Script::cast(function->shared()->script())); | 805 Handle<Script> script(Script::cast(function->shared()->script())); |
| 807 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 806 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 STATIC_ASCII_VECTOR("IsBreakPointTriggered")); | 1117 STATIC_ASCII_VECTOR("IsBreakPointTriggered")); |
| 1119 Handle<GlobalObject> debug_global(debug_context()->global_object()); | 1118 Handle<GlobalObject> debug_global(debug_context()->global_object()); |
| 1120 Handle<JSFunction> check_break_point = | 1119 Handle<JSFunction> check_break_point = |
| 1121 Handle<JSFunction>::cast(GlobalObject::GetPropertyNoExceptionThrown( | 1120 Handle<JSFunction>::cast(GlobalObject::GetPropertyNoExceptionThrown( |
| 1122 debug_global, is_break_point_triggered_string)); | 1121 debug_global, is_break_point_triggered_string)); |
| 1123 | 1122 |
| 1124 // Get the break id as an object. | 1123 // Get the break id as an object. |
| 1125 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); | 1124 Handle<Object> break_id = factory->NewNumberFromInt(Debug::break_id()); |
| 1126 | 1125 |
| 1127 // Call HandleBreakPointx. | 1126 // Call HandleBreakPointx. |
| 1128 bool caught_exception; | |
| 1129 Handle<Object> argv[] = { break_id, break_point_object }; | 1127 Handle<Object> argv[] = { break_id, break_point_object }; |
| 1130 Handle<Object> result = Execution::TryCall(check_break_point, | 1128 Handle<Object> result; |
| 1131 isolate_->js_builtins_object(), | 1129 bool caught_exception = !Execution::TryCall( |
| 1132 ARRAY_SIZE(argv), | 1130 check_break_point, |
| 1133 argv, | 1131 isolate_->js_builtins_object(), |
| 1134 &caught_exception); | 1132 ARRAY_SIZE(argv), |
| 1133 argv).ToHandle(&result); | |
| 1135 | 1134 |
| 1136 // If exception or non boolean result handle as not triggered | 1135 // If exception or non boolean result handle as not triggered |
| 1137 if (caught_exception || !result->IsBoolean()) { | 1136 if (caught_exception || !result->IsBoolean()) { |
| 1138 return false; | 1137 return false; |
| 1139 } | 1138 } |
| 1140 | 1139 |
| 1141 // Return whether the break point is triggered. | 1140 // Return whether the break point is triggered. |
| 1142 ASSERT(!result.is_null()); | 1141 ASSERT(!result.is_null()); |
|
Igor Sheludko
2014/04/10 15:14:42
While we are here: It's too late to ASSERT this an
| |
| 1143 return (*result)->IsTrue(); | 1142 return (*result)->IsTrue(); |
|
Igor Sheludko
2014/04/10 15:14:42
return result->IsTrue();
| |
| 1144 } | 1143 } |
| 1145 | 1144 |
| 1146 | 1145 |
| 1147 // Check whether the function has debug information. | 1146 // Check whether the function has debug information. |
| 1148 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { | 1147 bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1149 return !shared->debug_info()->IsUndefined(); | 1148 return !shared->debug_info()->IsUndefined(); |
| 1150 } | 1149 } |
| 1151 | 1150 |
| 1152 | 1151 |
| 1153 // Return the debug info for this function. EnsureDebugInfo must be called | 1152 // Return the debug info for this function. EnsureDebugInfo must be called |
| (...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 PostponeInterruptsScope postpone(isolate_); | 2458 PostponeInterruptsScope postpone(isolate_); |
| 2460 HandleScope scope(isolate_); | 2459 HandleScope scope(isolate_); |
| 2461 ASSERT(isolate_->context() == *Debug::debug_context()); | 2460 ASSERT(isolate_->context() == *Debug::debug_context()); |
| 2462 | 2461 |
| 2463 // Clear the mirror cache. | 2462 // Clear the mirror cache. |
| 2464 Handle<String> function_name = isolate_->factory()->InternalizeOneByteString( | 2463 Handle<String> function_name = isolate_->factory()->InternalizeOneByteString( |
| 2465 STATIC_ASCII_VECTOR("ClearMirrorCache")); | 2464 STATIC_ASCII_VECTOR("ClearMirrorCache")); |
| 2466 Handle<Object> fun = GlobalObject::GetPropertyNoExceptionThrown( | 2465 Handle<Object> fun = GlobalObject::GetPropertyNoExceptionThrown( |
| 2467 isolate_->global_object(), function_name); | 2466 isolate_->global_object(), function_name); |
| 2468 ASSERT(fun->IsJSFunction()); | 2467 ASSERT(fun->IsJSFunction()); |
| 2469 bool caught_exception; | 2468 Execution::TryCall( |
| 2470 Execution::TryCall(Handle<JSFunction>::cast(fun), | 2469 Handle<JSFunction>::cast(fun), |
| 2471 Handle<JSObject>(Debug::debug_context()->global_object()), | 2470 Handle<JSObject>(Debug::debug_context()->global_object()), |
| 2472 0, NULL, &caught_exception); | 2471 0, |
| 2472 NULL); | |
| 2473 } | 2473 } |
| 2474 | 2474 |
| 2475 | 2475 |
| 2476 void Debug::CreateScriptCache() { | 2476 void Debug::CreateScriptCache() { |
| 2477 Heap* heap = isolate_->heap(); | 2477 Heap* heap = isolate_->heap(); |
| 2478 HandleScope scope(isolate_); | 2478 HandleScope scope(isolate_); |
| 2479 | 2479 |
| 2480 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | 2480 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets |
| 2481 // rid of all the cached script wrappers and the second gets rid of the | 2481 // rid of all the cached script wrappers and the second gets rid of the |
| 2482 // scripts which are no longer referenced. The second also sweeps precisely, | 2482 // scripts which are no longer referenced. The second also sweeps precisely, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2583 command_queue_(isolate->logger(), kQueueInitialSize), | 2583 command_queue_(isolate->logger(), kQueueInitialSize), |
| 2584 command_received_(0), | 2584 command_received_(0), |
| 2585 event_command_queue_(isolate->logger(), kQueueInitialSize), | 2585 event_command_queue_(isolate->logger(), kQueueInitialSize), |
| 2586 isolate_(isolate) { | 2586 isolate_(isolate) { |
| 2587 } | 2587 } |
| 2588 | 2588 |
| 2589 | 2589 |
| 2590 Debugger::~Debugger() {} | 2590 Debugger::~Debugger() {} |
| 2591 | 2591 |
| 2592 | 2592 |
| 2593 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 2593 MaybeHandle<Object> Debugger::MakeJSObject( |
| 2594 int argc, | 2594 Vector<const char> constructor_name, |
| 2595 Handle<Object> argv[], | 2595 int argc, |
| 2596 bool* caught_exception) { | 2596 Handle<Object> argv[]) { |
| 2597 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2597 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2598 | 2598 |
| 2599 // Create the execution state object. | 2599 // Create the execution state object. |
| 2600 Handle<String> constructor_str = | 2600 Handle<String> constructor_str = |
| 2601 isolate_->factory()->InternalizeUtf8String(constructor_name); | 2601 isolate_->factory()->InternalizeUtf8String(constructor_name); |
| 2602 ASSERT(!constructor_str.is_null()); | 2602 ASSERT(!constructor_str.is_null()); |
| 2603 Handle<Object> constructor = GlobalObject::GetPropertyNoExceptionThrown( | 2603 Handle<Object> constructor = GlobalObject::GetPropertyNoExceptionThrown( |
| 2604 isolate_->global_object(), constructor_str); | 2604 isolate_->global_object(), constructor_str); |
| 2605 ASSERT(constructor->IsJSFunction()); | 2605 ASSERT(constructor->IsJSFunction()); |
| 2606 if (!constructor->IsJSFunction()) { | 2606 if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); |
| 2607 *caught_exception = true; | 2607 return Execution::TryCall( |
| 2608 return isolate_->factory()->undefined_value(); | |
| 2609 } | |
| 2610 Handle<Object> js_object = Execution::TryCall( | |
| 2611 Handle<JSFunction>::cast(constructor), | 2608 Handle<JSFunction>::cast(constructor), |
| 2612 Handle<JSObject>(isolate_->debug()->debug_context()->global_object()), | 2609 Handle<JSObject>(isolate_->debug()->debug_context()->global_object()), |
| 2613 argc, | 2610 argc, |
| 2614 argv, | 2611 argv); |
| 2615 caught_exception); | |
| 2616 return js_object; | |
| 2617 } | 2612 } |
| 2618 | 2613 |
| 2619 | 2614 |
| 2620 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { | 2615 MaybeHandle<Object> Debugger::MakeExecutionState() { |
| 2621 // Create the execution state object. | 2616 // Create the execution state object. |
| 2622 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( | 2617 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( |
| 2623 isolate_->debug()->break_id()); | 2618 isolate_->debug()->break_id()); |
| 2624 Handle<Object> argv[] = { break_id }; | 2619 Handle<Object> argv[] = { break_id }; |
| 2625 return MakeJSObject(CStrVector("MakeExecutionState"), | 2620 return MakeJSObject(CStrVector("MakeExecutionState"), ARRAY_SIZE(argv), argv); |
| 2626 ARRAY_SIZE(argv), | |
| 2627 argv, | |
| 2628 caught_exception); | |
| 2629 } | 2621 } |
| 2630 | 2622 |
| 2631 | 2623 |
| 2632 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, | 2624 MaybeHandle<Object> Debugger::MakeBreakEvent(Handle<Object> break_points_hit) { |
| 2633 Handle<Object> break_points_hit, | 2625 Handle<Object> exec_state; |
| 2634 bool* caught_exception) { | 2626 ASSIGN_RETURN_ON_EXCEPTION( |
| 2627 isolate_, exec_state, MakeExecutionState(), Object); | |
| 2635 // Create the new break event object. | 2628 // Create the new break event object. |
| 2636 Handle<Object> argv[] = { exec_state, break_points_hit }; | 2629 Handle<Object> argv[] = { exec_state, break_points_hit }; |
| 2637 return MakeJSObject(CStrVector("MakeBreakEvent"), | 2630 return MakeJSObject(CStrVector("MakeBreakEvent"), ARRAY_SIZE(argv), argv); |
| 2638 ARRAY_SIZE(argv), | |
| 2639 argv, | |
| 2640 caught_exception); | |
| 2641 } | 2631 } |
| 2642 | 2632 |
| 2643 | 2633 |
| 2644 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, | 2634 MaybeHandle<Object> Debugger::MakeExceptionEvent(Handle<Object> exception, |
| 2645 Handle<Object> exception, | 2635 bool uncaught) { |
| 2646 bool uncaught, | 2636 Handle<Object> exec_state; |
| 2647 bool* caught_exception) { | 2637 ASSIGN_RETURN_ON_EXCEPTION( |
| 2648 Factory* factory = isolate_->factory(); | 2638 isolate_, exec_state, MakeExecutionState(), Object); |
| 2649 // Create the new exception event object. | 2639 // Create the new exception event object. |
| 2650 Handle<Object> argv[] = { exec_state, | 2640 Handle<Object> argv[] = { exec_state, |
| 2651 exception, | 2641 exception, |
| 2652 factory->ToBoolean(uncaught) }; | 2642 isolate_->factory()->ToBoolean(uncaught) }; |
| 2653 return MakeJSObject(CStrVector("MakeExceptionEvent"), | 2643 return MakeJSObject(CStrVector("MakeExceptionEvent"), ARRAY_SIZE(argv), argv); |
| 2654 ARRAY_SIZE(argv), | |
| 2655 argv, | |
| 2656 caught_exception); | |
| 2657 } | 2644 } |
| 2658 | 2645 |
| 2659 | 2646 |
| 2660 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, | 2647 MaybeHandle<Object> Debugger::MakeCompileEvent(Handle<Script> script, |
| 2661 bool* caught_exception) { | 2648 bool before) { |
| 2662 // Create the new function event object. | |
| 2663 Handle<Object> argv[] = { function }; | |
| 2664 return MakeJSObject(CStrVector("MakeNewFunctionEvent"), | |
| 2665 ARRAY_SIZE(argv), | |
| 2666 argv, | |
| 2667 caught_exception); | |
| 2668 } | |
| 2669 | |
| 2670 | |
| 2671 Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script, | |
| 2672 bool before, | |
| 2673 bool* caught_exception) { | |
| 2674 Factory* factory = isolate_->factory(); | 2649 Factory* factory = isolate_->factory(); |
| 2675 // Create the compile event object. | 2650 // Create the compile event object. |
| 2676 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2651 Handle<Object> exec_state; |
| 2652 ASSIGN_RETURN_ON_EXCEPTION( | |
| 2653 isolate_, exec_state, MakeExecutionState(), Object); | |
| 2677 Handle<Object> script_wrapper = GetScriptWrapper(script); | 2654 Handle<Object> script_wrapper = GetScriptWrapper(script); |
| 2678 Handle<Object> argv[] = { exec_state, | 2655 Handle<Object> argv[] = { exec_state, |
| 2679 script_wrapper, | 2656 script_wrapper, |
| 2680 factory->ToBoolean(before) }; | 2657 factory->ToBoolean(before) }; |
| 2681 return MakeJSObject(CStrVector("MakeCompileEvent"), | 2658 return MakeJSObject(CStrVector("MakeCompileEvent"), ARRAY_SIZE(argv), argv); |
| 2682 ARRAY_SIZE(argv), | |
| 2683 argv, | |
| 2684 caught_exception); | |
| 2685 } | 2659 } |
| 2686 | 2660 |
| 2687 | 2661 |
| 2688 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, | 2662 MaybeHandle<Object> Debugger::MakeScriptCollectedEvent(int id) { |
| 2689 bool* caught_exception) { | |
| 2690 // Create the script collected event object. | 2663 // Create the script collected event object. |
| 2691 Handle<Object> exec_state = MakeExecutionState(caught_exception); | 2664 Handle<Object> exec_state; |
| 2665 ASSIGN_RETURN_ON_EXCEPTION( | |
| 2666 isolate_, exec_state, MakeExecutionState(), Object); | |
| 2692 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_); | 2667 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_); |
| 2693 Handle<Object> argv[] = { exec_state, id_object }; | 2668 Handle<Object> argv[] = { exec_state, id_object }; |
| 2694 | 2669 |
| 2695 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), | 2670 return MakeJSObject( |
| 2696 ARRAY_SIZE(argv), | 2671 CStrVector("MakeScriptCollectedEvent"), ARRAY_SIZE(argv), argv); |
| 2697 argv, | |
| 2698 caught_exception); | |
| 2699 } | 2672 } |
| 2700 | 2673 |
| 2701 | 2674 |
| 2702 void Debugger::OnException(Handle<Object> exception, bool uncaught) { | 2675 void Debugger::OnException(Handle<Object> exception, bool uncaught) { |
| 2703 HandleScope scope(isolate_); | 2676 HandleScope scope(isolate_); |
| 2704 Debug* debug = isolate_->debug(); | 2677 Debug* debug = isolate_->debug(); |
| 2705 | 2678 |
| 2706 // Bail out based on state or if there is no listener for this event | 2679 // Bail out based on state or if there is no listener for this event |
| 2707 if (debug->InDebugger()) return; | 2680 if (debug->InDebugger()) return; |
| 2708 if (!Debugger::EventActive(v8::Exception)) return; | 2681 if (!Debugger::EventActive(v8::Exception)) return; |
| 2709 | 2682 |
| 2710 // Bail out if exception breaks are not active | 2683 // Bail out if exception breaks are not active |
| 2711 if (uncaught) { | 2684 if (uncaught) { |
| 2712 // Uncaught exceptions are reported by either flags. | 2685 // Uncaught exceptions are reported by either flags. |
| 2713 if (!(debug->break_on_uncaught_exception() || | 2686 if (!(debug->break_on_uncaught_exception() || |
| 2714 debug->break_on_exception())) return; | 2687 debug->break_on_exception())) return; |
| 2715 } else { | 2688 } else { |
| 2716 // Caught exceptions are reported is activated. | 2689 // Caught exceptions are reported is activated. |
| 2717 if (!debug->break_on_exception()) return; | 2690 if (!debug->break_on_exception()) return; |
| 2718 } | 2691 } |
| 2719 | 2692 |
| 2720 // Enter the debugger. | 2693 // Enter the debugger. |
| 2721 EnterDebugger debugger(isolate_); | 2694 EnterDebugger debugger(isolate_); |
| 2722 if (debugger.FailedToEnter()) return; | 2695 if (debugger.FailedToEnter()) return; |
| 2723 | 2696 |
| 2724 // Clear all current stepping setup. | 2697 // Clear all current stepping setup. |
| 2725 debug->ClearStepping(); | 2698 debug->ClearStepping(); |
| 2726 // Create the event data object. | 2699 // Create the event data object. |
| 2727 bool caught_exception = false; | |
| 2728 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | |
| 2729 Handle<Object> event_data; | 2700 Handle<Object> event_data; |
| 2730 if (!caught_exception) { | |
| 2731 event_data = MakeExceptionEvent(exec_state, exception, uncaught, | |
| 2732 &caught_exception); | |
| 2733 } | |
| 2734 // Bail out and don't call debugger if exception. | 2701 // Bail out and don't call debugger if exception. |
| 2735 if (caught_exception) { | 2702 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2736 return; | 2703 isolate_, event_data, MakeExceptionEvent(exception, uncaught), |
| 2737 } | 2704 /* void */ ;); |
| 2738 | 2705 |
| 2739 // Process debug event. | 2706 // Process debug event. |
| 2740 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 2707 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
| 2741 // Return to continue execution from where the exception was thrown. | 2708 // Return to continue execution from where the exception was thrown. |
| 2742 } | 2709 } |
| 2743 | 2710 |
| 2744 | 2711 |
| 2745 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, | 2712 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, |
| 2746 bool auto_continue) { | 2713 bool auto_continue) { |
| 2747 HandleScope scope(isolate_); | 2714 HandleScope scope(isolate_); |
| 2748 | 2715 |
| 2749 // Debugger has already been entered by caller. | 2716 // Debugger has already been entered by caller. |
| 2750 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2717 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2751 | 2718 |
| 2752 // Bail out if there is no listener for this event | 2719 // Bail out if there is no listener for this event |
| 2753 if (!Debugger::EventActive(v8::Break)) return; | 2720 if (!Debugger::EventActive(v8::Break)) return; |
| 2754 | 2721 |
| 2755 // Debugger must be entered in advance. | 2722 // Debugger must be entered in advance. |
| 2756 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2723 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
| 2757 | 2724 |
| 2758 // Create the event data object. | 2725 // Create the event data object. |
| 2759 bool caught_exception = false; | |
| 2760 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | |
| 2761 Handle<Object> event_data; | 2726 Handle<Object> event_data; |
| 2762 if (!caught_exception) { | |
| 2763 event_data = MakeBreakEvent(exec_state, break_points_hit, | |
| 2764 &caught_exception); | |
| 2765 } | |
| 2766 // Bail out and don't call debugger if exception. | 2727 // Bail out and don't call debugger if exception. |
| 2767 if (caught_exception) { | 2728 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2768 return; | 2729 isolate_, event_data, MakeBreakEvent(break_points_hit), /* void */ ;); |
| 2769 } | |
| 2770 | 2730 |
| 2771 // Process debug event. | 2731 // Process debug event. |
| 2772 ProcessDebugEvent(v8::Break, | 2732 ProcessDebugEvent(v8::Break, |
| 2773 Handle<JSObject>::cast(event_data), | 2733 Handle<JSObject>::cast(event_data), |
| 2774 auto_continue); | 2734 auto_continue); |
| 2775 } | 2735 } |
| 2776 | 2736 |
| 2777 | 2737 |
| 2778 void Debugger::OnBeforeCompile(Handle<Script> script) { | 2738 void Debugger::OnBeforeCompile(Handle<Script> script) { |
| 2779 HandleScope scope(isolate_); | 2739 HandleScope scope(isolate_); |
| 2780 | 2740 |
| 2781 // Bail out based on state or if there is no listener for this event | 2741 // Bail out based on state or if there is no listener for this event |
| 2782 if (isolate_->debug()->InDebugger()) return; | 2742 if (isolate_->debug()->InDebugger()) return; |
| 2783 if (compiling_natives()) return; | 2743 if (compiling_natives()) return; |
| 2784 if (!EventActive(v8::BeforeCompile)) return; | 2744 if (!EventActive(v8::BeforeCompile)) return; |
| 2785 | 2745 |
| 2786 // Enter the debugger. | 2746 // Enter the debugger. |
| 2787 EnterDebugger debugger(isolate_); | 2747 EnterDebugger debugger(isolate_); |
| 2788 if (debugger.FailedToEnter()) return; | 2748 if (debugger.FailedToEnter()) return; |
| 2789 | 2749 |
| 2790 // Create the event data object. | 2750 // Create the event data object. |
| 2791 bool caught_exception = false; | 2751 Handle<Object> event_data; |
| 2792 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); | |
| 2793 // Bail out and don't call debugger if exception. | 2752 // Bail out and don't call debugger if exception. |
| 2794 if (caught_exception) { | 2753 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2795 return; | 2754 isolate_, event_data, MakeCompileEvent(script, true), /* void */ ;); |
| 2796 } | |
| 2797 | 2755 |
| 2798 // Process debug event. | 2756 // Process debug event. |
| 2799 ProcessDebugEvent(v8::BeforeCompile, | 2757 ProcessDebugEvent(v8::BeforeCompile, |
| 2800 Handle<JSObject>::cast(event_data), | 2758 Handle<JSObject>::cast(event_data), |
| 2801 true); | 2759 true); |
| 2802 } | 2760 } |
| 2803 | 2761 |
| 2804 | 2762 |
| 2805 // Handle debugger actions when a new script is compiled. | 2763 // Handle debugger actions when a new script is compiled. |
| 2806 void Debugger::OnAfterCompile(Handle<Script> script, | 2764 void Debugger::OnAfterCompile(Handle<Script> script, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2838 if (!update_script_break_points->IsJSFunction()) { | 2796 if (!update_script_break_points->IsJSFunction()) { |
| 2839 return; | 2797 return; |
| 2840 } | 2798 } |
| 2841 ASSERT(update_script_break_points->IsJSFunction()); | 2799 ASSERT(update_script_break_points->IsJSFunction()); |
| 2842 | 2800 |
| 2843 // Wrap the script object in a proper JS object before passing it | 2801 // Wrap the script object in a proper JS object before passing it |
| 2844 // to JavaScript. | 2802 // to JavaScript. |
| 2845 Handle<JSValue> wrapper = GetScriptWrapper(script); | 2803 Handle<JSValue> wrapper = GetScriptWrapper(script); |
| 2846 | 2804 |
| 2847 // Call UpdateScriptBreakPoints expect no exceptions. | 2805 // Call UpdateScriptBreakPoints expect no exceptions. |
| 2848 bool caught_exception; | |
| 2849 Handle<Object> argv[] = { wrapper }; | 2806 Handle<Object> argv[] = { wrapper }; |
| 2850 Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points), | 2807 if (Execution::TryCall( |
| 2851 isolate_->js_builtins_object(), | 2808 Handle<JSFunction>::cast(update_script_break_points), |
| 2852 ARRAY_SIZE(argv), | 2809 isolate_->js_builtins_object(), |
| 2853 argv, | 2810 ARRAY_SIZE(argv), |
| 2854 &caught_exception); | 2811 argv).is_null()) { |
| 2855 if (caught_exception) { | |
| 2856 return; | 2812 return; |
| 2857 } | 2813 } |
| 2858 // Bail out based on state or if there is no listener for this event | 2814 // Bail out based on state or if there is no listener for this event |
| 2859 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; | 2815 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; |
| 2860 if (!Debugger::EventActive(v8::AfterCompile)) return; | 2816 if (!Debugger::EventActive(v8::AfterCompile)) return; |
| 2861 | 2817 |
| 2862 // Create the compile state object. | 2818 // Create the compile state object. |
| 2863 Handle<Object> event_data = MakeCompileEvent(script, | 2819 Handle<Object> event_data; |
| 2864 false, | |
| 2865 &caught_exception); | |
| 2866 // Bail out and don't call debugger if exception. | 2820 // Bail out and don't call debugger if exception. |
| 2867 if (caught_exception) { | 2821 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2868 return; | 2822 isolate_, event_data, MakeCompileEvent(script, false), /* void */ ;); |
| 2869 } | 2823 |
| 2870 // Process debug event. | 2824 // Process debug event. |
| 2871 ProcessDebugEvent(v8::AfterCompile, | 2825 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true); |
| 2872 Handle<JSObject>::cast(event_data), | |
| 2873 true); | |
| 2874 } | 2826 } |
| 2875 | 2827 |
| 2876 | 2828 |
| 2877 void Debugger::OnScriptCollected(int id) { | 2829 void Debugger::OnScriptCollected(int id) { |
| 2878 HandleScope scope(isolate_); | 2830 HandleScope scope(isolate_); |
| 2879 | 2831 |
| 2880 // No more to do if not debugging. | 2832 // No more to do if not debugging. |
| 2881 if (isolate_->debug()->InDebugger()) return; | 2833 if (isolate_->debug()->InDebugger()) return; |
| 2882 if (!IsDebuggerActive()) return; | 2834 if (!IsDebuggerActive()) return; |
| 2883 if (!Debugger::EventActive(v8::ScriptCollected)) return; | 2835 if (!Debugger::EventActive(v8::ScriptCollected)) return; |
| 2884 | 2836 |
| 2885 // Enter the debugger. | 2837 // Enter the debugger. |
| 2886 EnterDebugger debugger(isolate_); | 2838 EnterDebugger debugger(isolate_); |
| 2887 if (debugger.FailedToEnter()) return; | 2839 if (debugger.FailedToEnter()) return; |
| 2888 | 2840 |
| 2889 // Create the script collected state object. | 2841 // Create the script collected state object. |
| 2890 bool caught_exception = false; | 2842 Handle<Object> event_data; |
| 2891 Handle<Object> event_data = MakeScriptCollectedEvent(id, | |
| 2892 &caught_exception); | |
| 2893 // Bail out and don't call debugger if exception. | 2843 // Bail out and don't call debugger if exception. |
| 2894 if (caught_exception) { | 2844 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2895 return; | 2845 isolate_, event_data, MakeScriptCollectedEvent(id), /* void */ ;); |
| 2896 } | |
| 2897 | 2846 |
| 2898 // Process debug event. | 2847 // Process debug event. |
| 2899 ProcessDebugEvent(v8::ScriptCollected, | 2848 ProcessDebugEvent(v8::ScriptCollected, |
| 2900 Handle<JSObject>::cast(event_data), | 2849 Handle<JSObject>::cast(event_data), |
| 2901 true); | 2850 true); |
| 2902 } | 2851 } |
| 2903 | 2852 |
| 2904 | 2853 |
| 2905 void Debugger::ProcessDebugEvent(v8::DebugEvent event, | 2854 void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
| 2906 Handle<JSObject> event_data, | 2855 Handle<JSObject> event_data, |
| 2907 bool auto_continue) { | 2856 bool auto_continue) { |
| 2908 HandleScope scope(isolate_); | 2857 HandleScope scope(isolate_); |
| 2909 | 2858 |
| 2910 // Clear any pending debug break if this is a real break. | 2859 // Clear any pending debug break if this is a real break. |
| 2911 if (!auto_continue) { | 2860 if (!auto_continue) { |
| 2912 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); | 2861 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); |
| 2913 } | 2862 } |
| 2914 | 2863 |
| 2915 // Create the execution state. | 2864 // Create the execution state. |
| 2916 bool caught_exception = false; | 2865 Handle<Object> exec_state; |
| 2917 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 2866 // Bail out and don't call debugger if exception. |
| 2918 if (caught_exception) { | 2867 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 2919 return; | 2868 isolate_, exec_state, MakeExecutionState(), /* void */ ;); |
| 2920 } | |
| 2921 // First notify the message handler if any. | 2869 // First notify the message handler if any. |
| 2922 if (message_handler_ != NULL) { | 2870 if (message_handler_ != NULL) { |
| 2923 NotifyMessageHandler(event, | 2871 NotifyMessageHandler(event, |
| 2924 Handle<JSObject>::cast(exec_state), | 2872 Handle<JSObject>::cast(exec_state), |
| 2925 event_data, | 2873 event_data, |
| 2926 auto_continue); | 2874 auto_continue); |
| 2927 } | 2875 } |
| 2928 // Notify registered debug event listener. This can be either a C or | 2876 // Notify registered debug event listener. This can be either a C or |
| 2929 // a JavaScript function. Don't call event listener for v8::Break | 2877 // a JavaScript function. Don't call event listener for v8::Break |
| 2930 // here, if it's only a debug command -- they will be processed later. | 2878 // here, if it's only a debug command -- they will be processed later. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2981 Handle<Object> exec_state, | 2929 Handle<Object> exec_state, |
| 2982 Handle<Object> event_data) { | 2930 Handle<Object> event_data) { |
| 2983 ASSERT(event_listener_->IsJSFunction()); | 2931 ASSERT(event_listener_->IsJSFunction()); |
| 2984 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); | 2932 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); |
| 2985 | 2933 |
| 2986 // Invoke the JavaScript debug event listener. | 2934 // Invoke the JavaScript debug event listener. |
| 2987 Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_), | 2935 Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_), |
| 2988 exec_state, | 2936 exec_state, |
| 2989 event_data, | 2937 event_data, |
| 2990 event_listener_data_ }; | 2938 event_listener_data_ }; |
| 2991 bool caught_exception; | |
| 2992 Execution::TryCall(fun, | 2939 Execution::TryCall(fun, |
| 2993 isolate_->global_object(), | 2940 isolate_->global_object(), |
| 2994 ARRAY_SIZE(argv), | 2941 ARRAY_SIZE(argv), |
| 2995 argv, | 2942 argv); |
| 2996 &caught_exception); | |
| 2997 // Silently ignore exceptions from debug event listeners. | 2943 // Silently ignore exceptions from debug event listeners. |
| 2998 } | 2944 } |
| 2999 | 2945 |
| 3000 | 2946 |
| 3001 Handle<Context> Debugger::GetDebugContext() { | 2947 Handle<Context> Debugger::GetDebugContext() { |
| 3002 never_unload_debugger_ = true; | 2948 never_unload_debugger_ = true; |
| 3003 EnterDebugger debugger(isolate_); | 2949 EnterDebugger debugger(isolate_); |
| 3004 return isolate_->debug()->debug_context(); | 2950 return isolate_->debug()->debug_context(); |
| 3005 } | 2951 } |
| 3006 | 2952 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3340 | 3286 |
| 3341 bool Debugger::IsDebuggerActive() { | 3287 bool Debugger::IsDebuggerActive() { |
| 3342 LockGuard<RecursiveMutex> with(debugger_access_); | 3288 LockGuard<RecursiveMutex> with(debugger_access_); |
| 3343 | 3289 |
| 3344 return message_handler_ != NULL || | 3290 return message_handler_ != NULL || |
| 3345 !event_listener_.is_null() || | 3291 !event_listener_.is_null() || |
| 3346 force_debugger_active_; | 3292 force_debugger_active_; |
| 3347 } | 3293 } |
| 3348 | 3294 |
| 3349 | 3295 |
| 3350 Handle<Object> Debugger::Call(Handle<JSFunction> fun, | 3296 MaybeHandle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 3351 Handle<Object> data, | 3297 Handle<Object> data) { |
| 3352 bool* pending_exception) { | |
| 3353 // When calling functions in the debugger prevent it from beeing unloaded. | 3298 // When calling functions in the debugger prevent it from beeing unloaded. |
| 3354 Debugger::never_unload_debugger_ = true; | 3299 Debugger::never_unload_debugger_ = true; |
| 3355 | 3300 |
| 3356 // Enter the debugger. | 3301 // Enter the debugger. |
| 3357 EnterDebugger debugger(isolate_); | 3302 EnterDebugger debugger(isolate_); |
| 3358 if (debugger.FailedToEnter()) { | 3303 if (debugger.FailedToEnter()) { |
| 3359 return isolate_->factory()->undefined_value(); | 3304 return isolate_->factory()->undefined_value(); |
| 3360 } | 3305 } |
| 3361 | 3306 |
| 3362 // Create the execution state. | 3307 // Create the execution state. |
| 3363 bool caught_exception = false; | 3308 Handle<Object> exec_state; |
| 3364 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 3309 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 3365 if (caught_exception) { | 3310 isolate_, exec_state, |
| 3366 return isolate_->factory()->undefined_value(); | 3311 MakeExecutionState(), |
| 3367 } | 3312 isolate_->factory()->undefined_value()); |
| 3368 | 3313 |
| 3369 Handle<Object> argv[] = { exec_state, data }; | 3314 Handle<Object> argv[] = { exec_state, data }; |
| 3370 Handle<Object> result = Execution::Call( | 3315 return Execution::Call( |
| 3371 isolate_, | 3316 isolate_, |
| 3372 fun, | 3317 fun, |
| 3373 Handle<Object>(isolate_->debug()->debug_context_->global_proxy(), | 3318 Handle<Object>(isolate_->debug()->debug_context_->global_proxy(), |
| 3374 isolate_), | 3319 isolate_), |
| 3375 ARRAY_SIZE(argv), | 3320 ARRAY_SIZE(argv), |
| 3376 argv, | 3321 argv); |
| 3377 pending_exception); | |
| 3378 return result; | |
| 3379 } | 3322 } |
| 3380 | 3323 |
| 3381 | 3324 |
| 3382 static void StubMessageHandler2(const v8::Debug::Message& message) { | 3325 static void StubMessageHandler2(const v8::Debug::Message& message) { |
| 3383 // Simply ignore message. | 3326 // Simply ignore message. |
| 3384 } | 3327 } |
| 3385 | 3328 |
| 3386 | 3329 |
| 3387 bool Debugger::StartAgent(const char* name, int port, | 3330 bool Debugger::StartAgent(const char* name, int port, |
| 3388 bool wait_for_connection) { | 3331 bool wait_for_connection) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3597 v8::EscapableHandleScope scope( | 3540 v8::EscapableHandleScope scope( |
| 3598 reinterpret_cast<v8::Isolate*>(event_data_->GetIsolate())); | 3541 reinterpret_cast<v8::Isolate*>(event_data_->GetIsolate())); |
| 3599 | 3542 |
| 3600 if (IsEvent()) { | 3543 if (IsEvent()) { |
| 3601 // Call toJSONProtocol on the debug event object. | 3544 // Call toJSONProtocol on the debug event object. |
| 3602 Handle<Object> fun = | 3545 Handle<Object> fun = |
| 3603 GetProperty(event_data_, "toJSONProtocol").ToHandleChecked(); | 3546 GetProperty(event_data_, "toJSONProtocol").ToHandleChecked(); |
| 3604 if (!fun->IsJSFunction()) { | 3547 if (!fun->IsJSFunction()) { |
| 3605 return v8::Handle<v8::String>(); | 3548 return v8::Handle<v8::String>(); |
| 3606 } | 3549 } |
| 3607 bool caught_exception; | 3550 Handle<Object> json; |
| 3608 Handle<Object> json = Execution::TryCall(Handle<JSFunction>::cast(fun), | 3551 bool caught_exception = !Execution::TryCall( |
| 3609 event_data_, | 3552 Handle<JSFunction>::cast(fun), |
| 3610 0, NULL, &caught_exception); | 3553 event_data_, |
| 3554 0, | |
| 3555 NULL).ToHandle(&json); | |
| 3611 if (caught_exception || !json->IsString()) { | 3556 if (caught_exception || !json->IsString()) { |
| 3612 return v8::Handle<v8::String>(); | 3557 return v8::Handle<v8::String>(); |
| 3613 } | 3558 } |
| 3614 return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json))); | 3559 return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json))); |
| 3615 } else { | 3560 } else { |
| 3616 return v8::Utils::ToLocal(response_json_); | 3561 return v8::Utils::ToLocal(response_json_); |
| 3617 } | 3562 } |
| 3618 } | 3563 } |
| 3619 | 3564 |
| 3620 | 3565 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3809 { | 3754 { |
| 3810 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 3755 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 3811 isolate_->debugger()->CallMessageDispatchHandler(); | 3756 isolate_->debugger()->CallMessageDispatchHandler(); |
| 3812 } | 3757 } |
| 3813 } | 3758 } |
| 3814 } | 3759 } |
| 3815 | 3760 |
| 3816 #endif // ENABLE_DEBUGGER_SUPPORT | 3761 #endif // ENABLE_DEBUGGER_SUPPORT |
| 3817 | 3762 |
| 3818 } } // namespace v8::internal | 3763 } } // namespace v8::internal |
| OLD | NEW |