Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: src/debug.cc

Issue 231883007: Return MaybeHandle from Invoke. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | src/debug-debugger.js » ('j') | src/factory.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool caught_exception = false;
782 Execution::TryCall(function, 781 Handle<Object> 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,
786 &caught_exception);
787 787
788 // Check for caught exceptions. 788 // Check for caught exceptions.
789 if (caught_exception) { 789 if (caught_exception) {
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());
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 };
1129 bool caught_exception = false;
1130 Handle<Object> result = Execution::TryCall(check_break_point, 1130 Handle<Object> result = Execution::TryCall(check_break_point,
1131 isolate_->js_builtins_object(), 1131 isolate_->js_builtins_object(),
1132 ARRAY_SIZE(argv), 1132 ARRAY_SIZE(argv),
1133 argv, 1133 argv,
1134 &caught_exception); 1134 &caught_exception);
1135 1135
1136 // If exception or non boolean result handle as not triggered 1136 // If exception or non boolean result handle as not triggered
1137 if (caught_exception || !result->IsBoolean()) { 1137 if (caught_exception || !result->IsBoolean()) {
1138 return false; 1138 return false;
1139 } 1139 }
1140 1140
1141 // Return whether the break point is triggered. 1141 // Return whether the break point is triggered.
1142 ASSERT(!result.is_null()); 1142 return result->IsTrue();
1143 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
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 bool caught_exception = false;
2470 Execution::TryCall(Handle<JSFunction>::cast(fun), 2469 Execution::TryCall(
2470 Handle<JSFunction>::cast(fun),
2471 Handle<JSObject>(Debug::debug_context()->global_object()), 2471 Handle<JSObject>(Debug::debug_context()->global_object()),
2472 0, NULL, &caught_exception); 2472 0,
2473 NULL,
2474 &caught_exception);
2473 } 2475 }
2474 2476
2475 2477
2476 void Debug::CreateScriptCache() { 2478 void Debug::CreateScriptCache() {
2477 Heap* heap = isolate_->heap(); 2479 Heap* heap = isolate_->heap();
2478 HandleScope scope(isolate_); 2480 HandleScope scope(isolate_);
2479 2481
2480 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets 2482 // 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 2483 // 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, 2484 // scripts which are no longer referenced. The second also sweeps precisely,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 command_queue_(isolate->logger(), kQueueInitialSize), 2585 command_queue_(isolate->logger(), kQueueInitialSize),
2584 command_received_(0), 2586 command_received_(0),
2585 event_command_queue_(isolate->logger(), kQueueInitialSize), 2587 event_command_queue_(isolate->logger(), kQueueInitialSize),
2586 isolate_(isolate) { 2588 isolate_(isolate) {
2587 } 2589 }
2588 2590
2589 2591
2590 Debugger::~Debugger() {} 2592 Debugger::~Debugger() {}
2591 2593
2592 2594
2593 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, 2595 MaybeHandle<Object> Debugger::MakeJSObject(
2594 int argc, 2596 Vector<const char> constructor_name,
2595 Handle<Object> argv[], 2597 int argc,
2596 bool* caught_exception) { 2598 Handle<Object> argv[]) {
2597 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2599 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2598 2600
2599 // Create the execution state object. 2601 // Create the execution state object.
2600 Handle<String> constructor_str = 2602 Handle<String> constructor_str =
2601 isolate_->factory()->InternalizeUtf8String(constructor_name); 2603 isolate_->factory()->InternalizeUtf8String(constructor_name);
2602 ASSERT(!constructor_str.is_null()); 2604 ASSERT(!constructor_str.is_null());
2603 Handle<Object> constructor = GlobalObject::GetPropertyNoExceptionThrown( 2605 Handle<Object> constructor = GlobalObject::GetPropertyNoExceptionThrown(
2604 isolate_->global_object(), constructor_str); 2606 isolate_->global_object(), constructor_str);
2605 ASSERT(constructor->IsJSFunction()); 2607 ASSERT(constructor->IsJSFunction());
2606 if (!constructor->IsJSFunction()) { 2608 if (!constructor->IsJSFunction()) return MaybeHandle<Object>();
2607 *caught_exception = true; 2609 bool caught_exception = false;
2608 return isolate_->factory()->undefined_value(); 2610 return Execution::TryCall(
2609 }
2610 Handle<Object> js_object = Execution::TryCall(
2611 Handle<JSFunction>::cast(constructor), 2611 Handle<JSFunction>::cast(constructor),
2612 Handle<JSObject>(isolate_->debug()->debug_context()->global_object()), 2612 Handle<JSObject>(isolate_->debug()->debug_context()->global_object()),
2613 argc, 2613 argc,
2614 argv, 2614 argv,
2615 caught_exception); 2615 &caught_exception);
Igor Sheludko 2014/04/10 21:34:30 I think we should write here and in all other plac
2616 return js_object;
2617 } 2616 }
2618 2617
2619 2618
2620 Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) { 2619 MaybeHandle<Object> Debugger::MakeExecutionState() {
2621 // Create the execution state object. 2620 // Create the execution state object.
2622 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt( 2621 Handle<Object> break_id = isolate_->factory()->NewNumberFromInt(
2623 isolate_->debug()->break_id()); 2622 isolate_->debug()->break_id());
2624 Handle<Object> argv[] = { break_id }; 2623 Handle<Object> argv[] = { break_id };
2625 return MakeJSObject(CStrVector("MakeExecutionState"), 2624 return MakeJSObject(CStrVector("MakeExecutionState"), ARRAY_SIZE(argv), argv);
2626 ARRAY_SIZE(argv),
2627 argv,
2628 caught_exception);
2629 } 2625 }
2630 2626
2631 2627
2632 Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state, 2628 MaybeHandle<Object> Debugger::MakeBreakEvent(Handle<Object> break_points_hit) {
2633 Handle<Object> break_points_hit, 2629 Handle<Object> exec_state;
2634 bool* caught_exception) { 2630 ASSIGN_RETURN_ON_EXCEPTION(
2631 isolate_, exec_state, MakeExecutionState(), Object);
2635 // Create the new break event object. 2632 // Create the new break event object.
2636 Handle<Object> argv[] = { exec_state, break_points_hit }; 2633 Handle<Object> argv[] = { exec_state, break_points_hit };
2637 return MakeJSObject(CStrVector("MakeBreakEvent"), 2634 return MakeJSObject(CStrVector("MakeBreakEvent"), ARRAY_SIZE(argv), argv);
2638 ARRAY_SIZE(argv),
2639 argv,
2640 caught_exception);
2641 } 2635 }
2642 2636
2643 2637
2644 Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state, 2638 MaybeHandle<Object> Debugger::MakeExceptionEvent(Handle<Object> exception,
2645 Handle<Object> exception, 2639 bool uncaught) {
2646 bool uncaught, 2640 Handle<Object> exec_state;
2647 bool* caught_exception) { 2641 ASSIGN_RETURN_ON_EXCEPTION(
2648 Factory* factory = isolate_->factory(); 2642 isolate_, exec_state, MakeExecutionState(), Object);
2649 // Create the new exception event object. 2643 // Create the new exception event object.
2650 Handle<Object> argv[] = { exec_state, 2644 Handle<Object> argv[] = { exec_state,
2651 exception, 2645 exception,
2652 factory->ToBoolean(uncaught) }; 2646 isolate_->factory()->ToBoolean(uncaught) };
2653 return MakeJSObject(CStrVector("MakeExceptionEvent"), 2647 return MakeJSObject(CStrVector("MakeExceptionEvent"), ARRAY_SIZE(argv), argv);
2654 ARRAY_SIZE(argv),
2655 argv,
2656 caught_exception);
2657 } 2648 }
2658 2649
2659 2650
2660 Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function, 2651 MaybeHandle<Object> Debugger::MakeCompileEvent(Handle<Script> script,
2661 bool* caught_exception) { 2652 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(); 2653 Factory* factory = isolate_->factory();
2675 // Create the compile event object. 2654 // Create the compile event object.
2676 Handle<Object> exec_state = MakeExecutionState(caught_exception); 2655 Handle<Object> exec_state;
2656 ASSIGN_RETURN_ON_EXCEPTION(
2657 isolate_, exec_state, MakeExecutionState(), Object);
2677 Handle<Object> script_wrapper = GetScriptWrapper(script); 2658 Handle<Object> script_wrapper = GetScriptWrapper(script);
2678 Handle<Object> argv[] = { exec_state, 2659 Handle<Object> argv[] = { exec_state,
2679 script_wrapper, 2660 script_wrapper,
2680 factory->ToBoolean(before) }; 2661 factory->ToBoolean(before) };
2681 return MakeJSObject(CStrVector("MakeCompileEvent"), 2662 return MakeJSObject(CStrVector("MakeCompileEvent"), ARRAY_SIZE(argv), argv);
2682 ARRAY_SIZE(argv),
2683 argv,
2684 caught_exception);
2685 } 2663 }
2686 2664
2687 2665
2688 Handle<Object> Debugger::MakeScriptCollectedEvent(int id, 2666 MaybeHandle<Object> Debugger::MakeScriptCollectedEvent(int id) {
2689 bool* caught_exception) {
2690 // Create the script collected event object. 2667 // Create the script collected event object.
2691 Handle<Object> exec_state = MakeExecutionState(caught_exception); 2668 Handle<Object> exec_state;
2669 ASSIGN_RETURN_ON_EXCEPTION(
2670 isolate_, exec_state, MakeExecutionState(), Object);
2692 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_); 2671 Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id), isolate_);
2693 Handle<Object> argv[] = { exec_state, id_object }; 2672 Handle<Object> argv[] = { exec_state, id_object };
2694 2673
2695 return MakeJSObject(CStrVector("MakeScriptCollectedEvent"), 2674 return MakeJSObject(
2696 ARRAY_SIZE(argv), 2675 CStrVector("MakeScriptCollectedEvent"), ARRAY_SIZE(argv), argv);
2697 argv,
2698 caught_exception);
2699 } 2676 }
2700 2677
2701 2678
2702 void Debugger::OnException(Handle<Object> exception, bool uncaught) { 2679 void Debugger::OnException(Handle<Object> exception, bool uncaught) {
2703 HandleScope scope(isolate_); 2680 HandleScope scope(isolate_);
2704 Debug* debug = isolate_->debug(); 2681 Debug* debug = isolate_->debug();
2705 2682
2706 // Bail out based on state or if there is no listener for this event 2683 // Bail out based on state or if there is no listener for this event
2707 if (debug->InDebugger()) return; 2684 if (debug->InDebugger()) return;
2708 if (!Debugger::EventActive(v8::Exception)) return; 2685 if (!Debugger::EventActive(v8::Exception)) return;
2709 2686
2710 // Bail out if exception breaks are not active 2687 // Bail out if exception breaks are not active
2711 if (uncaught) { 2688 if (uncaught) {
2712 // Uncaught exceptions are reported by either flags. 2689 // Uncaught exceptions are reported by either flags.
2713 if (!(debug->break_on_uncaught_exception() || 2690 if (!(debug->break_on_uncaught_exception() ||
2714 debug->break_on_exception())) return; 2691 debug->break_on_exception())) return;
2715 } else { 2692 } else {
2716 // Caught exceptions are reported is activated. 2693 // Caught exceptions are reported is activated.
2717 if (!debug->break_on_exception()) return; 2694 if (!debug->break_on_exception()) return;
2718 } 2695 }
2719 2696
2720 // Enter the debugger. 2697 // Enter the debugger.
2721 EnterDebugger debugger(isolate_); 2698 EnterDebugger debugger(isolate_);
2722 if (debugger.FailedToEnter()) return; 2699 if (debugger.FailedToEnter()) return;
2723 2700
2724 // Clear all current stepping setup. 2701 // Clear all current stepping setup.
2725 debug->ClearStepping(); 2702 debug->ClearStepping();
2726 // Create the event data object. 2703 // Create the event data object.
2727 bool caught_exception = false;
2728 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2729 Handle<Object> event_data; 2704 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. 2705 // Bail out and don't call debugger if exception.
2735 if (caught_exception) { 2706 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2736 return; 2707 isolate_, event_data, MakeExceptionEvent(exception, uncaught),
2737 } 2708 /* void */ ;);
2738 2709
2739 // Process debug event. 2710 // Process debug event.
2740 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); 2711 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false);
2741 // Return to continue execution from where the exception was thrown. 2712 // Return to continue execution from where the exception was thrown.
2742 } 2713 }
2743 2714
2744 2715
2745 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, 2716 void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
2746 bool auto_continue) { 2717 bool auto_continue) {
2747 HandleScope scope(isolate_); 2718 HandleScope scope(isolate_);
2748 2719
2749 // Debugger has already been entered by caller. 2720 // Debugger has already been entered by caller.
2750 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2721 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2751 2722
2752 // Bail out if there is no listener for this event 2723 // Bail out if there is no listener for this event
2753 if (!Debugger::EventActive(v8::Break)) return; 2724 if (!Debugger::EventActive(v8::Break)) return;
2754 2725
2755 // Debugger must be entered in advance. 2726 // Debugger must be entered in advance.
2756 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2727 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2757 2728
2758 // Create the event data object. 2729 // Create the event data object.
2759 bool caught_exception = false;
2760 Handle<Object> exec_state = MakeExecutionState(&caught_exception);
2761 Handle<Object> event_data; 2730 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. 2731 // Bail out and don't call debugger if exception.
2767 if (caught_exception) { 2732 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2768 return; 2733 isolate_, event_data, MakeBreakEvent(break_points_hit), /* void */ ;);
2769 }
2770 2734
2771 // Process debug event. 2735 // Process debug event.
2772 ProcessDebugEvent(v8::Break, 2736 ProcessDebugEvent(v8::Break,
2773 Handle<JSObject>::cast(event_data), 2737 Handle<JSObject>::cast(event_data),
2774 auto_continue); 2738 auto_continue);
2775 } 2739 }
2776 2740
2777 2741
2778 void Debugger::OnBeforeCompile(Handle<Script> script) { 2742 void Debugger::OnBeforeCompile(Handle<Script> script) {
2779 HandleScope scope(isolate_); 2743 HandleScope scope(isolate_);
2780 2744
2781 // Bail out based on state or if there is no listener for this event 2745 // Bail out based on state or if there is no listener for this event
2782 if (isolate_->debug()->InDebugger()) return; 2746 if (isolate_->debug()->InDebugger()) return;
2783 if (compiling_natives()) return; 2747 if (compiling_natives()) return;
2784 if (!EventActive(v8::BeforeCompile)) return; 2748 if (!EventActive(v8::BeforeCompile)) return;
2785 2749
2786 // Enter the debugger. 2750 // Enter the debugger.
2787 EnterDebugger debugger(isolate_); 2751 EnterDebugger debugger(isolate_);
2788 if (debugger.FailedToEnter()) return; 2752 if (debugger.FailedToEnter()) return;
2789 2753
2790 // Create the event data object. 2754 // Create the event data object.
2791 bool caught_exception = false; 2755 Handle<Object> event_data;
2792 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception);
2793 // Bail out and don't call debugger if exception. 2756 // Bail out and don't call debugger if exception.
2794 if (caught_exception) { 2757 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2795 return; 2758 isolate_, event_data, MakeCompileEvent(script, true), /* void */ ;);
2796 }
2797 2759
2798 // Process debug event. 2760 // Process debug event.
2799 ProcessDebugEvent(v8::BeforeCompile, 2761 ProcessDebugEvent(v8::BeforeCompile,
2800 Handle<JSObject>::cast(event_data), 2762 Handle<JSObject>::cast(event_data),
2801 true); 2763 true);
2802 } 2764 }
2803 2765
2804 2766
2805 // Handle debugger actions when a new script is compiled. 2767 // Handle debugger actions when a new script is compiled.
2806 void Debugger::OnAfterCompile(Handle<Script> script, 2768 void Debugger::OnAfterCompile(Handle<Script> script,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 if (!update_script_break_points->IsJSFunction()) { 2800 if (!update_script_break_points->IsJSFunction()) {
2839 return; 2801 return;
2840 } 2802 }
2841 ASSERT(update_script_break_points->IsJSFunction()); 2803 ASSERT(update_script_break_points->IsJSFunction());
2842 2804
2843 // Wrap the script object in a proper JS object before passing it 2805 // Wrap the script object in a proper JS object before passing it
2844 // to JavaScript. 2806 // to JavaScript.
2845 Handle<JSValue> wrapper = GetScriptWrapper(script); 2807 Handle<JSValue> wrapper = GetScriptWrapper(script);
2846 2808
2847 // Call UpdateScriptBreakPoints expect no exceptions. 2809 // Call UpdateScriptBreakPoints expect no exceptions.
2848 bool caught_exception;
2849 Handle<Object> argv[] = { wrapper }; 2810 Handle<Object> argv[] = { wrapper };
2811 bool caught_exception = false;
2850 Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points), 2812 Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points),
2851 isolate_->js_builtins_object(), 2813 isolate_->js_builtins_object(),
2852 ARRAY_SIZE(argv), 2814 ARRAY_SIZE(argv),
2853 argv, 2815 argv,
2854 &caught_exception); 2816 &caught_exception);
2855 if (caught_exception) { 2817 if (caught_exception) return;
2856 return;
2857 }
2858 // Bail out based on state or if there is no listener for this event 2818 // 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; 2819 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
2860 if (!Debugger::EventActive(v8::AfterCompile)) return; 2820 if (!Debugger::EventActive(v8::AfterCompile)) return;
2861 2821
2862 // Create the compile state object. 2822 // Create the compile state object.
2863 Handle<Object> event_data = MakeCompileEvent(script, 2823 Handle<Object> event_data;
2864 false,
2865 &caught_exception);
2866 // Bail out and don't call debugger if exception. 2824 // Bail out and don't call debugger if exception.
2867 if (caught_exception) { 2825 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2868 return; 2826 isolate_, event_data, MakeCompileEvent(script, false), /* void */ ;);
2869 } 2827
2870 // Process debug event. 2828 // Process debug event.
2871 ProcessDebugEvent(v8::AfterCompile, 2829 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true);
2872 Handle<JSObject>::cast(event_data),
2873 true);
2874 } 2830 }
2875 2831
2876 2832
2877 void Debugger::OnScriptCollected(int id) { 2833 void Debugger::OnScriptCollected(int id) {
2878 HandleScope scope(isolate_); 2834 HandleScope scope(isolate_);
2879 2835
2880 // No more to do if not debugging. 2836 // No more to do if not debugging.
2881 if (isolate_->debug()->InDebugger()) return; 2837 if (isolate_->debug()->InDebugger()) return;
2882 if (!IsDebuggerActive()) return; 2838 if (!IsDebuggerActive()) return;
2883 if (!Debugger::EventActive(v8::ScriptCollected)) return; 2839 if (!Debugger::EventActive(v8::ScriptCollected)) return;
2884 2840
2885 // Enter the debugger. 2841 // Enter the debugger.
2886 EnterDebugger debugger(isolate_); 2842 EnterDebugger debugger(isolate_);
2887 if (debugger.FailedToEnter()) return; 2843 if (debugger.FailedToEnter()) return;
2888 2844
2889 // Create the script collected state object. 2845 // Create the script collected state object.
2890 bool caught_exception = false; 2846 Handle<Object> event_data;
2891 Handle<Object> event_data = MakeScriptCollectedEvent(id,
2892 &caught_exception);
2893 // Bail out and don't call debugger if exception. 2847 // Bail out and don't call debugger if exception.
2894 if (caught_exception) { 2848 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2895 return; 2849 isolate_, event_data, MakeScriptCollectedEvent(id), /* void */ ;);
2896 }
2897 2850
2898 // Process debug event. 2851 // Process debug event.
2899 ProcessDebugEvent(v8::ScriptCollected, 2852 ProcessDebugEvent(v8::ScriptCollected,
2900 Handle<JSObject>::cast(event_data), 2853 Handle<JSObject>::cast(event_data),
2901 true); 2854 true);
2902 } 2855 }
2903 2856
2904 2857
2905 void Debugger::ProcessDebugEvent(v8::DebugEvent event, 2858 void Debugger::ProcessDebugEvent(v8::DebugEvent event,
2906 Handle<JSObject> event_data, 2859 Handle<JSObject> event_data,
2907 bool auto_continue) { 2860 bool auto_continue) {
2908 HandleScope scope(isolate_); 2861 HandleScope scope(isolate_);
2909 2862
2910 // Clear any pending debug break if this is a real break. 2863 // Clear any pending debug break if this is a real break.
2911 if (!auto_continue) { 2864 if (!auto_continue) {
2912 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK); 2865 isolate_->debug()->clear_interrupt_pending(DEBUGBREAK);
2913 } 2866 }
2914 2867
2915 // Create the execution state. 2868 // Create the execution state.
2916 bool caught_exception = false; 2869 Handle<Object> exec_state;
2917 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 2870 // Bail out and don't call debugger if exception.
2918 if (caught_exception) { 2871 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2919 return; 2872 isolate_, exec_state, MakeExecutionState(), /* void */ ;);
2920 }
2921 // First notify the message handler if any. 2873 // First notify the message handler if any.
2922 if (message_handler_ != NULL) { 2874 if (message_handler_ != NULL) {
2923 NotifyMessageHandler(event, 2875 NotifyMessageHandler(event,
2924 Handle<JSObject>::cast(exec_state), 2876 Handle<JSObject>::cast(exec_state),
2925 event_data, 2877 event_data,
2926 auto_continue); 2878 auto_continue);
2927 } 2879 }
2928 // Notify registered debug event listener. This can be either a C or 2880 // Notify registered debug event listener. This can be either a C or
2929 // a JavaScript function. Don't call event listener for v8::Break 2881 // 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. 2882 // 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
2981 Handle<Object> exec_state, 2933 Handle<Object> exec_state,
2982 Handle<Object> event_data) { 2934 Handle<Object> event_data) {
2983 ASSERT(event_listener_->IsJSFunction()); 2935 ASSERT(event_listener_->IsJSFunction());
2984 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); 2936 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_));
2985 2937
2986 // Invoke the JavaScript debug event listener. 2938 // Invoke the JavaScript debug event listener.
2987 Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_), 2939 Handle<Object> argv[] = { Handle<Object>(Smi::FromInt(event), isolate_),
2988 exec_state, 2940 exec_state,
2989 event_data, 2941 event_data,
2990 event_listener_data_ }; 2942 event_listener_data_ };
2991 bool caught_exception; 2943 bool caught_exception = false;
2992 Execution::TryCall(fun, 2944 Execution::TryCall(fun,
2993 isolate_->global_object(), 2945 isolate_->global_object(),
2994 ARRAY_SIZE(argv), 2946 ARRAY_SIZE(argv),
2995 argv, 2947 argv,
2996 &caught_exception); 2948 &caught_exception);
2997 // Silently ignore exceptions from debug event listeners. 2949 // Silently ignore exceptions from debug event listeners.
2998 } 2950 }
2999 2951
3000 2952
3001 Handle<Context> Debugger::GetDebugContext() { 2953 Handle<Context> Debugger::GetDebugContext() {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 3292
3341 bool Debugger::IsDebuggerActive() { 3293 bool Debugger::IsDebuggerActive() {
3342 LockGuard<RecursiveMutex> with(debugger_access_); 3294 LockGuard<RecursiveMutex> with(debugger_access_);
3343 3295
3344 return message_handler_ != NULL || 3296 return message_handler_ != NULL ||
3345 !event_listener_.is_null() || 3297 !event_listener_.is_null() ||
3346 force_debugger_active_; 3298 force_debugger_active_;
3347 } 3299 }
3348 3300
3349 3301
3350 Handle<Object> Debugger::Call(Handle<JSFunction> fun, 3302 MaybeHandle<Object> Debugger::Call(Handle<JSFunction> fun,
3351 Handle<Object> data, 3303 Handle<Object> data) {
3352 bool* pending_exception) {
3353 // When calling functions in the debugger prevent it from beeing unloaded. 3304 // When calling functions in the debugger prevent it from beeing unloaded.
3354 Debugger::never_unload_debugger_ = true; 3305 Debugger::never_unload_debugger_ = true;
3355 3306
3356 // Enter the debugger. 3307 // Enter the debugger.
3357 EnterDebugger debugger(isolate_); 3308 EnterDebugger debugger(isolate_);
3358 if (debugger.FailedToEnter()) { 3309 if (debugger.FailedToEnter()) {
3359 return isolate_->factory()->undefined_value(); 3310 return isolate_->factory()->undefined_value();
3360 } 3311 }
3361 3312
3362 // Create the execution state. 3313 // Create the execution state.
3363 bool caught_exception = false; 3314 Handle<Object> exec_state;
3364 Handle<Object> exec_state = MakeExecutionState(&caught_exception); 3315 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3365 if (caught_exception) { 3316 isolate_, exec_state,
3366 return isolate_->factory()->undefined_value(); 3317 MakeExecutionState(),
3367 } 3318 isolate_->factory()->undefined_value());
3368 3319
3369 Handle<Object> argv[] = { exec_state, data }; 3320 Handle<Object> argv[] = { exec_state, data };
3370 Handle<Object> result = Execution::Call( 3321 return Execution::Call(
3371 isolate_, 3322 isolate_,
3372 fun, 3323 fun,
3373 Handle<Object>(isolate_->debug()->debug_context_->global_proxy(), 3324 Handle<Object>(isolate_->debug()->debug_context_->global_proxy(),
3374 isolate_), 3325 isolate_),
3375 ARRAY_SIZE(argv), 3326 ARRAY_SIZE(argv),
3376 argv, 3327 argv);
3377 pending_exception);
3378 return result;
3379 } 3328 }
3380 3329
3381 3330
3382 static void StubMessageHandler2(const v8::Debug::Message& message) { 3331 static void StubMessageHandler2(const v8::Debug::Message& message) {
3383 // Simply ignore message. 3332 // Simply ignore message.
3384 } 3333 }
3385 3334
3386 3335
3387 bool Debugger::StartAgent(const char* name, int port, 3336 bool Debugger::StartAgent(const char* name, int port,
3388 bool wait_for_connection) { 3337 bool wait_for_connection) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 v8::EscapableHandleScope scope( 3546 v8::EscapableHandleScope scope(
3598 reinterpret_cast<v8::Isolate*>(event_data_->GetIsolate())); 3547 reinterpret_cast<v8::Isolate*>(event_data_->GetIsolate()));
3599 3548
3600 if (IsEvent()) { 3549 if (IsEvent()) {
3601 // Call toJSONProtocol on the debug event object. 3550 // Call toJSONProtocol on the debug event object.
3602 Handle<Object> fun = 3551 Handle<Object> fun =
3603 GetProperty(event_data_, "toJSONProtocol").ToHandleChecked(); 3552 GetProperty(event_data_, "toJSONProtocol").ToHandleChecked();
3604 if (!fun->IsJSFunction()) { 3553 if (!fun->IsJSFunction()) {
3605 return v8::Handle<v8::String>(); 3554 return v8::Handle<v8::String>();
3606 } 3555 }
3607 bool caught_exception; 3556 Handle<Object> json;
3608 Handle<Object> json = Execution::TryCall(Handle<JSFunction>::cast(fun), 3557 bool caught_exception = false;
3609 event_data_, 3558 Execution::TryCall(Handle<JSFunction>::cast(fun),
3610 0, NULL, &caught_exception); 3559 event_data_,
3560 0,
3561 NULL,
3562 &caught_exception);
3611 if (caught_exception || !json->IsString()) { 3563 if (caught_exception || !json->IsString()) {
3612 return v8::Handle<v8::String>(); 3564 return v8::Handle<v8::String>();
3613 } 3565 }
3614 return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json))); 3566 return scope.Escape(v8::Utils::ToLocal(Handle<String>::cast(json)));
3615 } else { 3567 } else {
3616 return v8::Utils::ToLocal(response_json_); 3568 return v8::Utils::ToLocal(response_json_);
3617 } 3569 }
3618 } 3570 }
3619 3571
3620 3572
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
3809 { 3761 {
3810 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); 3762 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_));
3811 isolate_->debugger()->CallMessageDispatchHandler(); 3763 isolate_->debugger()->CallMessageDispatchHandler();
3812 } 3764 }
3813 } 3765 }
3814 } 3766 }
3815 3767
3816 #endif // ENABLE_DEBUGGER_SUPPORT 3768 #endif // ENABLE_DEBUGGER_SUPPORT
3817 3769
3818 } } // namespace v8::internal 3770 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | src/debug-debugger.js » ('j') | src/factory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698