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