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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 char last_script_name_hit[80]; | 654 char last_script_name_hit[80]; |
655 char last_script_data_hit[80]; | 655 char last_script_data_hit[80]; |
656 | 656 |
657 // Global variables to store the last source position - used by some tests. | 657 // Global variables to store the last source position - used by some tests. |
658 int last_source_line = -1; | 658 int last_source_line = -1; |
659 int last_source_column = -1; | 659 int last_source_column = -1; |
660 | 660 |
661 // Debug event handler which counts the break points which have been hit. | 661 // Debug event handler which counts the break points which have been hit. |
662 int break_point_hit_count = 0; | 662 int break_point_hit_count = 0; |
663 int break_point_hit_count_deoptimize = 0; | 663 int break_point_hit_count_deoptimize = 0; |
664 static void DebugEventBreakPointHitCount(v8::DebugEvent event, | 664 static void DebugEventBreakPointHitCount( |
665 v8::Handle<v8::Object> exec_state, | 665 const v8::Debug::EventDetails& event_details) { |
666 v8::Handle<v8::Object> event_data, | 666 v8::DebugEvent event = event_details.GetEvent(); |
667 v8::Handle<v8::Value> data) { | 667 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
| 668 v8::Handle<v8::Object> event_data = event_details.GetEventData(); |
668 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); | 669 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); |
669 Debug* debug = isolate->debug(); | 670 Debug* debug = isolate->debug(); |
670 // When hitting a debug event listener there must be a break set. | 671 // When hitting a debug event listener there must be a break set. |
671 CHECK_NE(debug->break_id(), 0); | 672 CHECK_NE(debug->break_id(), 0); |
672 | 673 |
673 // Count the number of breaks. | 674 // Count the number of breaks. |
674 if (event == v8::Break) { | 675 if (event == v8::Break) { |
675 break_point_hit_count++; | 676 break_point_hit_count++; |
676 if (!frame_function_name.IsEmpty()) { | 677 if (!frame_function_name.IsEmpty()) { |
677 // Get the name of the function. | 678 // Get the name of the function. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 int exception_hit_count = 0; | 767 int exception_hit_count = 0; |
767 int uncaught_exception_hit_count = 0; | 768 int uncaught_exception_hit_count = 0; |
768 int last_js_stack_height = -1; | 769 int last_js_stack_height = -1; |
769 | 770 |
770 static void DebugEventCounterClear() { | 771 static void DebugEventCounterClear() { |
771 break_point_hit_count = 0; | 772 break_point_hit_count = 0; |
772 exception_hit_count = 0; | 773 exception_hit_count = 0; |
773 uncaught_exception_hit_count = 0; | 774 uncaught_exception_hit_count = 0; |
774 } | 775 } |
775 | 776 |
776 static void DebugEventCounter(v8::DebugEvent event, | 777 static void DebugEventCounter( |
777 v8::Handle<v8::Object> exec_state, | 778 const v8::Debug::EventDetails& event_details) { |
778 v8::Handle<v8::Object> event_data, | 779 v8::DebugEvent event = event_details.GetEvent(); |
779 v8::Handle<v8::Value> data) { | 780 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
| 781 v8::Handle<v8::Object> event_data = event_details.GetEventData(); |
780 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 782 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
781 | 783 |
782 // When hitting a debug event listener there must be a break set. | 784 // When hitting a debug event listener there must be a break set. |
783 CHECK_NE(debug->break_id(), 0); | 785 CHECK_NE(debug->break_id(), 0); |
784 | 786 |
785 // Count the number of breaks. | 787 // Count the number of breaks. |
786 if (event == v8::Break) { | 788 if (event == v8::Break) { |
787 break_point_hit_count++; | 789 break_point_hit_count++; |
788 } else if (event == v8::Exception) { | 790 } else if (event == v8::Exception) { |
789 exception_hit_count++; | 791 exception_hit_count++; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 struct EvaluateCheck* checks = NULL; | 830 struct EvaluateCheck* checks = NULL; |
829 // Source for The JavaScript function which can do the evaluation when a break | 831 // Source for The JavaScript function which can do the evaluation when a break |
830 // point is hit. | 832 // point is hit. |
831 const char* evaluate_check_source = | 833 const char* evaluate_check_source = |
832 "function evaluate_check(exec_state, expr, expected) {" | 834 "function evaluate_check(exec_state, expr, expected) {" |
833 " return exec_state.frame(0).evaluate(expr).value() === expected;" | 835 " return exec_state.frame(0).evaluate(expr).value() === expected;" |
834 "}"; | 836 "}"; |
835 v8::Local<v8::Function> evaluate_check_function; | 837 v8::Local<v8::Function> evaluate_check_function; |
836 | 838 |
837 // The actual debug event described by the longer comment above. | 839 // The actual debug event described by the longer comment above. |
838 static void DebugEventEvaluate(v8::DebugEvent event, | 840 static void DebugEventEvaluate( |
839 v8::Handle<v8::Object> exec_state, | 841 const v8::Debug::EventDetails& event_details) { |
840 v8::Handle<v8::Object> event_data, | 842 v8::DebugEvent event = event_details.GetEvent(); |
841 v8::Handle<v8::Value> data) { | 843 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
842 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 844 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
843 // When hitting a debug event listener there must be a break set. | 845 // When hitting a debug event listener there must be a break set. |
844 CHECK_NE(debug->break_id(), 0); | 846 CHECK_NE(debug->break_id(), 0); |
845 | 847 |
846 if (event == v8::Break) { | 848 if (event == v8::Break) { |
847 for (int i = 0; checks[i].expr != NULL; i++) { | 849 for (int i = 0; checks[i].expr != NULL; i++) { |
848 const int argc = 3; | 850 const int argc = 3; |
849 v8::Handle<v8::Value> argv[argc] = { exec_state, | 851 v8::Handle<v8::Value> argv[argc] = { exec_state, |
850 v8::String::New(checks[i].expr), | 852 v8::String::New(checks[i].expr), |
851 checks[i].expected }; | 853 checks[i].expected }; |
852 v8::Handle<v8::Value> result = | 854 v8::Handle<v8::Value> result = |
853 evaluate_check_function->Call(exec_state, argc, argv); | 855 evaluate_check_function->Call(exec_state, argc, argv); |
854 if (!result->IsTrue()) { | 856 if (!result->IsTrue()) { |
855 v8::String::Utf8Value utf8(checks[i].expected->ToString()); | 857 v8::String::Utf8Value utf8(checks[i].expected->ToString()); |
856 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *utf8); | 858 V8_Fatal(__FILE__, __LINE__, "%s != %s", checks[i].expr, *utf8); |
857 } | 859 } |
858 } | 860 } |
859 } | 861 } |
860 } | 862 } |
861 | 863 |
862 | 864 |
863 // This debug event listener removes a breakpoint in a function | 865 // This debug event listener removes a breakpoint in a function |
864 int debug_event_remove_break_point = 0; | 866 int debug_event_remove_break_point = 0; |
865 static void DebugEventRemoveBreakPoint(v8::DebugEvent event, | 867 static void DebugEventRemoveBreakPoint( |
866 v8::Handle<v8::Object> exec_state, | 868 const v8::Debug::EventDetails& event_details) { |
867 v8::Handle<v8::Object> event_data, | 869 v8::DebugEvent event = event_details.GetEvent(); |
868 v8::Handle<v8::Value> data) { | 870 v8::Handle<v8::Value> data = event_details.GetCallbackData(); |
869 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 871 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
870 // When hitting a debug event listener there must be a break set. | 872 // When hitting a debug event listener there must be a break set. |
871 CHECK_NE(debug->break_id(), 0); | 873 CHECK_NE(debug->break_id(), 0); |
872 | 874 |
873 if (event == v8::Break) { | 875 if (event == v8::Break) { |
874 break_point_hit_count++; | 876 break_point_hit_count++; |
875 CHECK(data->IsFunction()); | 877 CHECK(data->IsFunction()); |
876 ClearBreakPoint(debug_event_remove_break_point); | 878 ClearBreakPoint(debug_event_remove_break_point); |
877 } | 879 } |
878 } | 880 } |
879 | 881 |
880 | 882 |
881 // Debug event handler which counts break points hit and performs a step | 883 // Debug event handler which counts break points hit and performs a step |
882 // afterwards. | 884 // afterwards. |
883 StepAction step_action = StepIn; // Step action to perform when stepping. | 885 StepAction step_action = StepIn; // Step action to perform when stepping. |
884 static void DebugEventStep(v8::DebugEvent event, | 886 static void DebugEventStep( |
885 v8::Handle<v8::Object> exec_state, | 887 const v8::Debug::EventDetails& event_details) { |
886 v8::Handle<v8::Object> event_data, | 888 v8::DebugEvent event = event_details.GetEvent(); |
887 v8::Handle<v8::Value> data) { | |
888 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 889 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
889 // When hitting a debug event listener there must be a break set. | 890 // When hitting a debug event listener there must be a break set. |
890 CHECK_NE(debug->break_id(), 0); | 891 CHECK_NE(debug->break_id(), 0); |
891 | 892 |
892 if (event == v8::Break) { | 893 if (event == v8::Break) { |
893 break_point_hit_count++; | 894 break_point_hit_count++; |
894 PrepareStep(step_action); | 895 PrepareStep(step_action); |
895 } | 896 } |
896 } | 897 } |
897 | 898 |
898 | 899 |
899 // Debug event handler which counts break points hit and performs a step | 900 // Debug event handler which counts break points hit and performs a step |
900 // afterwards. For each call the expected function is checked. | 901 // afterwards. For each call the expected function is checked. |
901 // For this debug event handler to work the following two global varaibles | 902 // For this debug event handler to work the following two global varaibles |
902 // must be initialized. | 903 // must be initialized. |
903 // expected_step_sequence: An array of the expected function call sequence. | 904 // expected_step_sequence: An array of the expected function call sequence. |
904 // frame_function_name: A JavaScript function (see below). | 905 // frame_function_name: A JavaScript function (see below). |
905 | 906 |
906 // String containing the expected function call sequence. Note: this only works | 907 // String containing the expected function call sequence. Note: this only works |
907 // if functions have name length of one. | 908 // if functions have name length of one. |
908 const char* expected_step_sequence = NULL; | 909 const char* expected_step_sequence = NULL; |
909 | 910 |
910 // The actual debug event described by the longer comment above. | 911 // The actual debug event described by the longer comment above. |
911 static void DebugEventStepSequence(v8::DebugEvent event, | 912 static void DebugEventStepSequence( |
912 v8::Handle<v8::Object> exec_state, | 913 const v8::Debug::EventDetails& event_details) { |
913 v8::Handle<v8::Object> event_data, | 914 v8::DebugEvent event = event_details.GetEvent(); |
914 v8::Handle<v8::Value> data) { | 915 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
915 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 916 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
916 // When hitting a debug event listener there must be a break set. | 917 // When hitting a debug event listener there must be a break set. |
917 CHECK_NE(debug->break_id(), 0); | 918 CHECK_NE(debug->break_id(), 0); |
918 | 919 |
919 if (event == v8::Break || event == v8::Exception) { | 920 if (event == v8::Break || event == v8::Exception) { |
920 // Check that the current function is the expected. | 921 // Check that the current function is the expected. |
921 CHECK(break_point_hit_count < | 922 CHECK(break_point_hit_count < |
922 StrLength(expected_step_sequence)); | 923 StrLength(expected_step_sequence)); |
923 const int argc = 2; | 924 const int argc = 2; |
924 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; | 925 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; |
925 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, | 926 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, |
926 argc, argv); | 927 argc, argv); |
927 CHECK(result->IsString()); | 928 CHECK(result->IsString()); |
928 v8::String::Utf8Value function_name(result->ToString()); | 929 v8::String::Utf8Value function_name(result->ToString()); |
929 CHECK_EQ(1, StrLength(*function_name)); | 930 CHECK_EQ(1, StrLength(*function_name)); |
930 CHECK_EQ((*function_name)[0], | 931 CHECK_EQ((*function_name)[0], |
931 expected_step_sequence[break_point_hit_count]); | 932 expected_step_sequence[break_point_hit_count]); |
932 | 933 |
933 // Perform step. | 934 // Perform step. |
934 break_point_hit_count++; | 935 break_point_hit_count++; |
935 PrepareStep(step_action); | 936 PrepareStep(step_action); |
936 } | 937 } |
937 } | 938 } |
938 | 939 |
939 | 940 |
940 // Debug event handler which performs a garbage collection. | 941 // Debug event handler which performs a garbage collection. |
941 static void DebugEventBreakPointCollectGarbage( | 942 static void DebugEventBreakPointCollectGarbage( |
942 v8::DebugEvent event, | 943 const v8::Debug::EventDetails& event_details) { |
943 v8::Handle<v8::Object> exec_state, | 944 v8::DebugEvent event = event_details.GetEvent(); |
944 v8::Handle<v8::Object> event_data, | |
945 v8::Handle<v8::Value> data) { | |
946 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 945 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
947 // When hitting a debug event listener there must be a break set. | 946 // When hitting a debug event listener there must be a break set. |
948 CHECK_NE(debug->break_id(), 0); | 947 CHECK_NE(debug->break_id(), 0); |
949 | 948 |
950 // Perform a garbage collection when break point is hit and continue. Based | 949 // Perform a garbage collection when break point is hit and continue. Based |
951 // on the number of break points hit either scavenge or mark compact | 950 // on the number of break points hit either scavenge or mark compact |
952 // collector is used. | 951 // collector is used. |
953 if (event == v8::Break) { | 952 if (event == v8::Break) { |
954 break_point_hit_count++; | 953 break_point_hit_count++; |
955 if (break_point_hit_count % 2 == 0) { | 954 if (break_point_hit_count % 2 == 0) { |
956 // Scavenge. | 955 // Scavenge. |
957 HEAP->CollectGarbage(v8::internal::NEW_SPACE); | 956 HEAP->CollectGarbage(v8::internal::NEW_SPACE); |
958 } else { | 957 } else { |
959 // Mark sweep compact. | 958 // Mark sweep compact. |
960 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 959 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
961 } | 960 } |
962 } | 961 } |
963 } | 962 } |
964 | 963 |
965 | 964 |
966 // Debug event handler which re-issues a debug break and calls the garbage | 965 // Debug event handler which re-issues a debug break and calls the garbage |
967 // collector to have the heap verified. | 966 // collector to have the heap verified. |
968 static void DebugEventBreak(v8::DebugEvent event, | 967 static void DebugEventBreak( |
969 v8::Handle<v8::Object> exec_state, | 968 const v8::Debug::EventDetails& event_details) { |
970 v8::Handle<v8::Object> event_data, | 969 v8::DebugEvent event = event_details.GetEvent(); |
971 v8::Handle<v8::Value> data) { | |
972 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 970 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
973 // When hitting a debug event listener there must be a break set. | 971 // When hitting a debug event listener there must be a break set. |
974 CHECK_NE(debug->break_id(), 0); | 972 CHECK_NE(debug->break_id(), 0); |
975 | 973 |
976 if (event == v8::Break) { | 974 if (event == v8::Break) { |
977 // Count the number of breaks. | 975 // Count the number of breaks. |
978 break_point_hit_count++; | 976 break_point_hit_count++; |
979 | 977 |
980 // Run the garbage collector to enforce heap verification if option | 978 // Run the garbage collector to enforce heap verification if option |
981 // --verify-heap is set. | 979 // --verify-heap is set. |
982 HEAP->CollectGarbage(v8::internal::NEW_SPACE); | 980 HEAP->CollectGarbage(v8::internal::NEW_SPACE); |
983 | 981 |
984 // Set the break flag again to come back here as soon as possible. | 982 // Set the break flag again to come back here as soon as possible. |
985 v8::Debug::DebugBreak(); | 983 v8::Debug::DebugBreak(); |
986 } | 984 } |
987 } | 985 } |
988 | 986 |
989 | 987 |
990 // Debug event handler which re-issues a debug break until a limit has been | 988 // Debug event handler which re-issues a debug break until a limit has been |
991 // reached. | 989 // reached. |
992 int max_break_point_hit_count = 0; | 990 int max_break_point_hit_count = 0; |
993 bool terminate_after_max_break_point_hit = false; | 991 bool terminate_after_max_break_point_hit = false; |
994 static void DebugEventBreakMax(v8::DebugEvent event, | 992 static void DebugEventBreakMax( |
995 v8::Handle<v8::Object> exec_state, | 993 const v8::Debug::EventDetails& event_details) { |
996 v8::Handle<v8::Object> event_data, | 994 v8::DebugEvent event = event_details.GetEvent(); |
997 v8::Handle<v8::Value> data) { | 995 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
998 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); | 996 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); |
999 v8::internal::Debug* debug = isolate->debug(); | 997 v8::internal::Debug* debug = isolate->debug(); |
1000 // When hitting a debug event listener there must be a break set. | 998 // When hitting a debug event listener there must be a break set. |
1001 CHECK_NE(debug->break_id(), 0); | 999 CHECK_NE(debug->break_id(), 0); |
1002 | 1000 |
1003 if (event == v8::Break) { | 1001 if (event == v8::Break) { |
1004 if (break_point_hit_count < max_break_point_hit_count) { | 1002 if (break_point_hit_count < max_break_point_hit_count) { |
1005 // Count the number of breaks. | 1003 // Count the number of breaks. |
1006 break_point_hit_count++; | 1004 break_point_hit_count++; |
1007 | 1005 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 CHECK(!HasDebugInfo(bar)); | 1170 CHECK(!HasDebugInfo(bar)); |
1173 } | 1171 } |
1174 | 1172 |
1175 | 1173 |
1176 // Test that a break point can be set at an IC store location. | 1174 // Test that a break point can be set at an IC store location. |
1177 TEST(BreakPointICStore) { | 1175 TEST(BreakPointICStore) { |
1178 break_point_hit_count = 0; | 1176 break_point_hit_count = 0; |
1179 DebugLocalContext env; | 1177 DebugLocalContext env; |
1180 v8::HandleScope scope(env->GetIsolate()); | 1178 v8::HandleScope scope(env->GetIsolate()); |
1181 | 1179 |
1182 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1180 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1183 v8::Undefined()); | |
1184 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run(); | 1181 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run(); |
1185 v8::Local<v8::Function> foo = | 1182 v8::Local<v8::Function> foo = |
1186 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1183 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1187 | 1184 |
1188 // Run without breakpoints. | 1185 // Run without breakpoints. |
1189 foo->Call(env->Global(), 0, NULL); | 1186 foo->Call(env->Global(), 0, NULL); |
1190 CHECK_EQ(0, break_point_hit_count); | 1187 CHECK_EQ(0, break_point_hit_count); |
1191 | 1188 |
1192 // Run with breakpoint | 1189 // Run with breakpoint |
1193 int bp = SetBreakPoint(foo, 0); | 1190 int bp = SetBreakPoint(foo, 0); |
1194 foo->Call(env->Global(), 0, NULL); | 1191 foo->Call(env->Global(), 0, NULL); |
1195 CHECK_EQ(1, break_point_hit_count); | 1192 CHECK_EQ(1, break_point_hit_count); |
1196 foo->Call(env->Global(), 0, NULL); | 1193 foo->Call(env->Global(), 0, NULL); |
1197 CHECK_EQ(2, break_point_hit_count); | 1194 CHECK_EQ(2, break_point_hit_count); |
1198 | 1195 |
1199 // Run without breakpoints. | 1196 // Run without breakpoints. |
1200 ClearBreakPoint(bp); | 1197 ClearBreakPoint(bp); |
1201 foo->Call(env->Global(), 0, NULL); | 1198 foo->Call(env->Global(), 0, NULL); |
1202 CHECK_EQ(2, break_point_hit_count); | 1199 CHECK_EQ(2, break_point_hit_count); |
1203 | 1200 |
1204 v8::Debug::SetDebugEventListener(NULL); | 1201 v8::Debug::SetDebugEventListener2(NULL); |
1205 CheckDebuggerUnloaded(); | 1202 CheckDebuggerUnloaded(); |
1206 } | 1203 } |
1207 | 1204 |
1208 | 1205 |
1209 // Test that a break point can be set at an IC load location. | 1206 // Test that a break point can be set at an IC load location. |
1210 TEST(BreakPointICLoad) { | 1207 TEST(BreakPointICLoad) { |
1211 break_point_hit_count = 0; | 1208 break_point_hit_count = 0; |
1212 DebugLocalContext env; | 1209 DebugLocalContext env; |
1213 v8::HandleScope scope(env->GetIsolate()); | 1210 v8::HandleScope scope(env->GetIsolate()); |
1214 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1211 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1215 v8::Undefined()); | |
1216 v8::Script::Compile(v8::String::New("bar=1"))->Run(); | 1212 v8::Script::Compile(v8::String::New("bar=1"))->Run(); |
1217 v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run(); | 1213 v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run(); |
1218 v8::Local<v8::Function> foo = | 1214 v8::Local<v8::Function> foo = |
1219 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1215 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1220 | 1216 |
1221 // Run without breakpoints. | 1217 // Run without breakpoints. |
1222 foo->Call(env->Global(), 0, NULL); | 1218 foo->Call(env->Global(), 0, NULL); |
1223 CHECK_EQ(0, break_point_hit_count); | 1219 CHECK_EQ(0, break_point_hit_count); |
1224 | 1220 |
1225 // Run with breakpoint. | 1221 // Run with breakpoint. |
1226 int bp = SetBreakPoint(foo, 0); | 1222 int bp = SetBreakPoint(foo, 0); |
1227 foo->Call(env->Global(), 0, NULL); | 1223 foo->Call(env->Global(), 0, NULL); |
1228 CHECK_EQ(1, break_point_hit_count); | 1224 CHECK_EQ(1, break_point_hit_count); |
1229 foo->Call(env->Global(), 0, NULL); | 1225 foo->Call(env->Global(), 0, NULL); |
1230 CHECK_EQ(2, break_point_hit_count); | 1226 CHECK_EQ(2, break_point_hit_count); |
1231 | 1227 |
1232 // Run without breakpoints. | 1228 // Run without breakpoints. |
1233 ClearBreakPoint(bp); | 1229 ClearBreakPoint(bp); |
1234 foo->Call(env->Global(), 0, NULL); | 1230 foo->Call(env->Global(), 0, NULL); |
1235 CHECK_EQ(2, break_point_hit_count); | 1231 CHECK_EQ(2, break_point_hit_count); |
1236 | 1232 |
1237 v8::Debug::SetDebugEventListener(NULL); | 1233 v8::Debug::SetDebugEventListener2(NULL); |
1238 CheckDebuggerUnloaded(); | 1234 CheckDebuggerUnloaded(); |
1239 } | 1235 } |
1240 | 1236 |
1241 | 1237 |
1242 // Test that a break point can be set at an IC call location. | 1238 // Test that a break point can be set at an IC call location. |
1243 TEST(BreakPointICCall) { | 1239 TEST(BreakPointICCall) { |
1244 break_point_hit_count = 0; | 1240 break_point_hit_count = 0; |
1245 DebugLocalContext env; | 1241 DebugLocalContext env; |
1246 v8::HandleScope scope(env->GetIsolate()); | 1242 v8::HandleScope scope(env->GetIsolate()); |
1247 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1243 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1248 v8::Undefined()); | |
1249 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); | 1244 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); |
1250 v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run(); | 1245 v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run(); |
1251 v8::Local<v8::Function> foo = | 1246 v8::Local<v8::Function> foo = |
1252 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1247 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1253 | 1248 |
1254 // Run without breakpoints. | 1249 // Run without breakpoints. |
1255 foo->Call(env->Global(), 0, NULL); | 1250 foo->Call(env->Global(), 0, NULL); |
1256 CHECK_EQ(0, break_point_hit_count); | 1251 CHECK_EQ(0, break_point_hit_count); |
1257 | 1252 |
1258 // Run with breakpoint | 1253 // Run with breakpoint |
1259 int bp = SetBreakPoint(foo, 0); | 1254 int bp = SetBreakPoint(foo, 0); |
1260 foo->Call(env->Global(), 0, NULL); | 1255 foo->Call(env->Global(), 0, NULL); |
1261 CHECK_EQ(1, break_point_hit_count); | 1256 CHECK_EQ(1, break_point_hit_count); |
1262 foo->Call(env->Global(), 0, NULL); | 1257 foo->Call(env->Global(), 0, NULL); |
1263 CHECK_EQ(2, break_point_hit_count); | 1258 CHECK_EQ(2, break_point_hit_count); |
1264 | 1259 |
1265 // Run without breakpoints. | 1260 // Run without breakpoints. |
1266 ClearBreakPoint(bp); | 1261 ClearBreakPoint(bp); |
1267 foo->Call(env->Global(), 0, NULL); | 1262 foo->Call(env->Global(), 0, NULL); |
1268 CHECK_EQ(2, break_point_hit_count); | 1263 CHECK_EQ(2, break_point_hit_count); |
1269 | 1264 |
1270 v8::Debug::SetDebugEventListener(NULL); | 1265 v8::Debug::SetDebugEventListener2(NULL); |
1271 CheckDebuggerUnloaded(); | 1266 CheckDebuggerUnloaded(); |
1272 } | 1267 } |
1273 | 1268 |
1274 | 1269 |
1275 // Test that a break point can be set at an IC call location and survive a GC. | 1270 // Test that a break point can be set at an IC call location and survive a GC. |
1276 TEST(BreakPointICCallWithGC) { | 1271 TEST(BreakPointICCallWithGC) { |
1277 break_point_hit_count = 0; | 1272 break_point_hit_count = 0; |
1278 DebugLocalContext env; | 1273 DebugLocalContext env; |
1279 v8::HandleScope scope(env->GetIsolate()); | 1274 v8::HandleScope scope(env->GetIsolate()); |
1280 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, | 1275 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); |
1281 v8::Undefined()); | |
1282 v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run(); | 1276 v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run(); |
1283 v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run(); | 1277 v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run(); |
1284 v8::Local<v8::Function> foo = | 1278 v8::Local<v8::Function> foo = |
1285 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1279 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1286 | 1280 |
1287 // Run without breakpoints. | 1281 // Run without breakpoints. |
1288 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1282 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1289 CHECK_EQ(0, break_point_hit_count); | 1283 CHECK_EQ(0, break_point_hit_count); |
1290 | 1284 |
1291 // Run with breakpoint. | 1285 // Run with breakpoint. |
1292 int bp = SetBreakPoint(foo, 0); | 1286 int bp = SetBreakPoint(foo, 0); |
1293 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1287 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1294 CHECK_EQ(1, break_point_hit_count); | 1288 CHECK_EQ(1, break_point_hit_count); |
1295 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1289 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1296 CHECK_EQ(2, break_point_hit_count); | 1290 CHECK_EQ(2, break_point_hit_count); |
1297 | 1291 |
1298 // Run without breakpoints. | 1292 // Run without breakpoints. |
1299 ClearBreakPoint(bp); | 1293 ClearBreakPoint(bp); |
1300 foo->Call(env->Global(), 0, NULL); | 1294 foo->Call(env->Global(), 0, NULL); |
1301 CHECK_EQ(2, break_point_hit_count); | 1295 CHECK_EQ(2, break_point_hit_count); |
1302 | 1296 |
1303 v8::Debug::SetDebugEventListener(NULL); | 1297 v8::Debug::SetDebugEventListener2(NULL); |
1304 CheckDebuggerUnloaded(); | 1298 CheckDebuggerUnloaded(); |
1305 } | 1299 } |
1306 | 1300 |
1307 | 1301 |
1308 // Test that a break point can be set at an IC call location and survive a GC. | 1302 // Test that a break point can be set at an IC call location and survive a GC. |
1309 TEST(BreakPointConstructCallWithGC) { | 1303 TEST(BreakPointConstructCallWithGC) { |
1310 break_point_hit_count = 0; | 1304 break_point_hit_count = 0; |
1311 DebugLocalContext env; | 1305 DebugLocalContext env; |
1312 v8::HandleScope scope(env->GetIsolate()); | 1306 v8::HandleScope scope(env->GetIsolate()); |
1313 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, | 1307 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); |
1314 v8::Undefined()); | |
1315 v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run(); | 1308 v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run(); |
1316 v8::Script::Compile(v8::String::New( | 1309 v8::Script::Compile(v8::String::New( |
1317 "function foo(){return new bar(1).x;}"))->Run(); | 1310 "function foo(){return new bar(1).x;}"))->Run(); |
1318 v8::Local<v8::Function> foo = | 1311 v8::Local<v8::Function> foo = |
1319 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1312 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1320 | 1313 |
1321 // Run without breakpoints. | 1314 // Run without breakpoints. |
1322 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1315 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1323 CHECK_EQ(0, break_point_hit_count); | 1316 CHECK_EQ(0, break_point_hit_count); |
1324 | 1317 |
1325 // Run with breakpoint. | 1318 // Run with breakpoint. |
1326 int bp = SetBreakPoint(foo, 0); | 1319 int bp = SetBreakPoint(foo, 0); |
1327 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1320 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1328 CHECK_EQ(1, break_point_hit_count); | 1321 CHECK_EQ(1, break_point_hit_count); |
1329 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1322 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1330 CHECK_EQ(2, break_point_hit_count); | 1323 CHECK_EQ(2, break_point_hit_count); |
1331 | 1324 |
1332 // Run without breakpoints. | 1325 // Run without breakpoints. |
1333 ClearBreakPoint(bp); | 1326 ClearBreakPoint(bp); |
1334 foo->Call(env->Global(), 0, NULL); | 1327 foo->Call(env->Global(), 0, NULL); |
1335 CHECK_EQ(2, break_point_hit_count); | 1328 CHECK_EQ(2, break_point_hit_count); |
1336 | 1329 |
1337 v8::Debug::SetDebugEventListener(NULL); | 1330 v8::Debug::SetDebugEventListener2(NULL); |
1338 CheckDebuggerUnloaded(); | 1331 CheckDebuggerUnloaded(); |
1339 } | 1332 } |
1340 | 1333 |
1341 | 1334 |
1342 // Test that a break point can be set at a return store location. | 1335 // Test that a break point can be set at a return store location. |
1343 TEST(BreakPointReturn) { | 1336 TEST(BreakPointReturn) { |
1344 break_point_hit_count = 0; | 1337 break_point_hit_count = 0; |
1345 DebugLocalContext env; | 1338 DebugLocalContext env; |
1346 v8::HandleScope scope(env->GetIsolate()); | 1339 v8::HandleScope scope(env->GetIsolate()); |
1347 | 1340 |
1348 // Create a functions for checking the source line and column when hitting | 1341 // Create a functions for checking the source line and column when hitting |
1349 // a break point. | 1342 // a break point. |
1350 frame_source_line = CompileFunction(&env, | 1343 frame_source_line = CompileFunction(&env, |
1351 frame_source_line_source, | 1344 frame_source_line_source, |
1352 "frame_source_line"); | 1345 "frame_source_line"); |
1353 frame_source_column = CompileFunction(&env, | 1346 frame_source_column = CompileFunction(&env, |
1354 frame_source_column_source, | 1347 frame_source_column_source, |
1355 "frame_source_column"); | 1348 "frame_source_column"); |
1356 | 1349 |
1357 | 1350 |
1358 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1351 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1359 v8::Undefined()); | |
1360 v8::Script::Compile(v8::String::New("function foo(){}"))->Run(); | 1352 v8::Script::Compile(v8::String::New("function foo(){}"))->Run(); |
1361 v8::Local<v8::Function> foo = | 1353 v8::Local<v8::Function> foo = |
1362 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1354 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
1363 | 1355 |
1364 // Run without breakpoints. | 1356 // Run without breakpoints. |
1365 foo->Call(env->Global(), 0, NULL); | 1357 foo->Call(env->Global(), 0, NULL); |
1366 CHECK_EQ(0, break_point_hit_count); | 1358 CHECK_EQ(0, break_point_hit_count); |
1367 | 1359 |
1368 // Run with breakpoint | 1360 // Run with breakpoint |
1369 int bp = SetBreakPoint(foo, 0); | 1361 int bp = SetBreakPoint(foo, 0); |
1370 foo->Call(env->Global(), 0, NULL); | 1362 foo->Call(env->Global(), 0, NULL); |
1371 CHECK_EQ(1, break_point_hit_count); | 1363 CHECK_EQ(1, break_point_hit_count); |
1372 CHECK_EQ(0, last_source_line); | 1364 CHECK_EQ(0, last_source_line); |
1373 CHECK_EQ(15, last_source_column); | 1365 CHECK_EQ(15, last_source_column); |
1374 foo->Call(env->Global(), 0, NULL); | 1366 foo->Call(env->Global(), 0, NULL); |
1375 CHECK_EQ(2, break_point_hit_count); | 1367 CHECK_EQ(2, break_point_hit_count); |
1376 CHECK_EQ(0, last_source_line); | 1368 CHECK_EQ(0, last_source_line); |
1377 CHECK_EQ(15, last_source_column); | 1369 CHECK_EQ(15, last_source_column); |
1378 | 1370 |
1379 // Run without breakpoints. | 1371 // Run without breakpoints. |
1380 ClearBreakPoint(bp); | 1372 ClearBreakPoint(bp); |
1381 foo->Call(env->Global(), 0, NULL); | 1373 foo->Call(env->Global(), 0, NULL); |
1382 CHECK_EQ(2, break_point_hit_count); | 1374 CHECK_EQ(2, break_point_hit_count); |
1383 | 1375 |
1384 v8::Debug::SetDebugEventListener(NULL); | 1376 v8::Debug::SetDebugEventListener2(NULL); |
1385 CheckDebuggerUnloaded(); | 1377 CheckDebuggerUnloaded(); |
1386 } | 1378 } |
1387 | 1379 |
1388 | 1380 |
1389 static void CallWithBreakPoints(v8::Local<v8::Object> recv, | 1381 static void CallWithBreakPoints(v8::Local<v8::Object> recv, |
1390 v8::Local<v8::Function> f, | 1382 v8::Local<v8::Function> f, |
1391 int break_point_count, | 1383 int break_point_count, |
1392 int call_count) { | 1384 int call_count) { |
1393 break_point_hit_count = 0; | 1385 break_point_hit_count = 0; |
1394 for (int i = 0; i < call_count; i++) { | 1386 for (int i = 0; i < call_count; i++) { |
1395 f->Call(recv, 0, NULL); | 1387 f->Call(recv, 0, NULL); |
1396 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); | 1388 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); |
1397 } | 1389 } |
1398 } | 1390 } |
1399 | 1391 |
1400 | 1392 |
1401 // Test GC during break point processing. | 1393 // Test GC during break point processing. |
1402 TEST(GCDuringBreakPointProcessing) { | 1394 TEST(GCDuringBreakPointProcessing) { |
1403 break_point_hit_count = 0; | 1395 break_point_hit_count = 0; |
1404 DebugLocalContext env; | 1396 DebugLocalContext env; |
1405 v8::HandleScope scope(env->GetIsolate()); | 1397 v8::HandleScope scope(env->GetIsolate()); |
1406 | 1398 |
1407 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, | 1399 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); |
1408 v8::Undefined()); | |
1409 v8::Local<v8::Function> foo; | 1400 v8::Local<v8::Function> foo; |
1410 | 1401 |
1411 // Test IC store break point with garbage collection. | 1402 // Test IC store break point with garbage collection. |
1412 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1403 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
1413 SetBreakPoint(foo, 0); | 1404 SetBreakPoint(foo, 0); |
1414 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1405 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1415 | 1406 |
1416 // Test IC load break point with garbage collection. | 1407 // Test IC load break point with garbage collection. |
1417 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); | 1408 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); |
1418 SetBreakPoint(foo, 0); | 1409 SetBreakPoint(foo, 0); |
1419 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1410 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1420 | 1411 |
1421 // Test IC call break point with garbage collection. | 1412 // Test IC call break point with garbage collection. |
1422 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); | 1413 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); |
1423 SetBreakPoint(foo, 0); | 1414 SetBreakPoint(foo, 0); |
1424 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1415 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1425 | 1416 |
1426 // Test return break point with garbage collection. | 1417 // Test return break point with garbage collection. |
1427 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1418 foo = CompileFunction(&env, "function foo(){}", "foo"); |
1428 SetBreakPoint(foo, 0); | 1419 SetBreakPoint(foo, 0); |
1429 CallWithBreakPoints(env->Global(), foo, 1, 25); | 1420 CallWithBreakPoints(env->Global(), foo, 1, 25); |
1430 | 1421 |
1431 // Test debug break slot break point with garbage collection. | 1422 // Test debug break slot break point with garbage collection. |
1432 foo = CompileFunction(&env, "function foo(){var a;}", "foo"); | 1423 foo = CompileFunction(&env, "function foo(){var a;}", "foo"); |
1433 SetBreakPoint(foo, 0); | 1424 SetBreakPoint(foo, 0); |
1434 CallWithBreakPoints(env->Global(), foo, 1, 25); | 1425 CallWithBreakPoints(env->Global(), foo, 1, 25); |
1435 | 1426 |
1436 v8::Debug::SetDebugEventListener(NULL); | 1427 v8::Debug::SetDebugEventListener2(NULL); |
1437 CheckDebuggerUnloaded(); | 1428 CheckDebuggerUnloaded(); |
1438 } | 1429 } |
1439 | 1430 |
1440 | 1431 |
1441 // Call the function three times with different garbage collections in between | 1432 // Call the function three times with different garbage collections in between |
1442 // and make sure that the break point survives. | 1433 // and make sure that the break point survives. |
1443 static void CallAndGC(v8::Local<v8::Object> recv, | 1434 static void CallAndGC(v8::Local<v8::Object> recv, |
1444 v8::Local<v8::Function> f) { | 1435 v8::Local<v8::Function> f) { |
1445 break_point_hit_count = 0; | 1436 break_point_hit_count = 0; |
1446 | 1437 |
(...skipping 14 matching lines...) Expand all Loading... |
1461 } | 1452 } |
1462 } | 1453 } |
1463 | 1454 |
1464 | 1455 |
1465 // Test that a break point can be set at a return store location. | 1456 // Test that a break point can be set at a return store location. |
1466 TEST(BreakPointSurviveGC) { | 1457 TEST(BreakPointSurviveGC) { |
1467 break_point_hit_count = 0; | 1458 break_point_hit_count = 0; |
1468 DebugLocalContext env; | 1459 DebugLocalContext env; |
1469 v8::HandleScope scope(env->GetIsolate()); | 1460 v8::HandleScope scope(env->GetIsolate()); |
1470 | 1461 |
1471 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1462 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1472 v8::Undefined()); | |
1473 v8::Local<v8::Function> foo; | 1463 v8::Local<v8::Function> foo; |
1474 | 1464 |
1475 // Test IC store break point with garbage collection. | 1465 // Test IC store break point with garbage collection. |
1476 { | 1466 { |
1477 CompileFunction(&env, "function foo(){}", "foo"); | 1467 CompileFunction(&env, "function foo(){}", "foo"); |
1478 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1468 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
1479 SetBreakPoint(foo, 0); | 1469 SetBreakPoint(foo, 0); |
1480 } | 1470 } |
1481 CallAndGC(env->Global(), foo); | 1471 CallAndGC(env->Global(), foo); |
1482 | 1472 |
(...skipping 25 matching lines...) Expand all Loading... |
1508 | 1498 |
1509 // Test non IC break point with garbage collection. | 1499 // Test non IC break point with garbage collection. |
1510 { | 1500 { |
1511 CompileFunction(&env, "function foo(){}", "foo"); | 1501 CompileFunction(&env, "function foo(){}", "foo"); |
1512 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); | 1502 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); |
1513 SetBreakPoint(foo, 0); | 1503 SetBreakPoint(foo, 0); |
1514 } | 1504 } |
1515 CallAndGC(env->Global(), foo); | 1505 CallAndGC(env->Global(), foo); |
1516 | 1506 |
1517 | 1507 |
1518 v8::Debug::SetDebugEventListener(NULL); | 1508 v8::Debug::SetDebugEventListener2(NULL); |
1519 CheckDebuggerUnloaded(); | 1509 CheckDebuggerUnloaded(); |
1520 } | 1510 } |
1521 | 1511 |
1522 | 1512 |
1523 // Test that break points can be set using the global Debug object. | 1513 // Test that break points can be set using the global Debug object. |
1524 TEST(BreakPointThroughJavaScript) { | 1514 TEST(BreakPointThroughJavaScript) { |
1525 break_point_hit_count = 0; | 1515 break_point_hit_count = 0; |
1526 DebugLocalContext env; | 1516 DebugLocalContext env; |
1527 v8::HandleScope scope(env->GetIsolate()); | 1517 v8::HandleScope scope(env->GetIsolate()); |
1528 env.ExposeDebug(); | 1518 env.ExposeDebug(); |
1529 | 1519 |
1530 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1520 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1531 v8::Undefined()); | |
1532 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); | 1521 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); |
1533 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run(); | 1522 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run(); |
1534 // 012345678901234567890 | 1523 // 012345678901234567890 |
1535 // 1 2 | 1524 // 1 2 |
1536 // Break points are set at position 3 and 9 | 1525 // Break points are set at position 3 and 9 |
1537 v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()")); | 1526 v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()")); |
1538 | 1527 |
1539 // Run without breakpoints. | 1528 // Run without breakpoints. |
1540 foo->Run(); | 1529 foo->Run(); |
1541 CHECK_EQ(0, break_point_hit_count); | 1530 CHECK_EQ(0, break_point_hit_count); |
(...skipping 17 matching lines...) Expand all Loading... |
1559 foo->Run(); | 1548 foo->Run(); |
1560 CHECK_EQ(7, break_point_hit_count); | 1549 CHECK_EQ(7, break_point_hit_count); |
1561 foo->Run(); | 1550 foo->Run(); |
1562 CHECK_EQ(8, break_point_hit_count); | 1551 CHECK_EQ(8, break_point_hit_count); |
1563 | 1552 |
1564 // Run without breakpoints. | 1553 // Run without breakpoints. |
1565 ClearBreakPointFromJS(bp1); | 1554 ClearBreakPointFromJS(bp1); |
1566 foo->Run(); | 1555 foo->Run(); |
1567 CHECK_EQ(8, break_point_hit_count); | 1556 CHECK_EQ(8, break_point_hit_count); |
1568 | 1557 |
1569 v8::Debug::SetDebugEventListener(NULL); | 1558 v8::Debug::SetDebugEventListener2(NULL); |
1570 CheckDebuggerUnloaded(); | 1559 CheckDebuggerUnloaded(); |
1571 | 1560 |
1572 // Make sure that the break point numbers are consecutive. | 1561 // Make sure that the break point numbers are consecutive. |
1573 CHECK_EQ(1, bp1); | 1562 CHECK_EQ(1, bp1); |
1574 CHECK_EQ(2, bp2); | 1563 CHECK_EQ(2, bp2); |
1575 } | 1564 } |
1576 | 1565 |
1577 | 1566 |
1578 // Test that break points on scripts identified by name can be set using the | 1567 // Test that break points on scripts identified by name can be set using the |
1579 // global Debug object. | 1568 // global Debug object. |
1580 TEST(ScriptBreakPointByNameThroughJavaScript) { | 1569 TEST(ScriptBreakPointByNameThroughJavaScript) { |
1581 break_point_hit_count = 0; | 1570 break_point_hit_count = 0; |
1582 DebugLocalContext env; | 1571 DebugLocalContext env; |
1583 v8::HandleScope scope(env->GetIsolate()); | 1572 v8::HandleScope scope(env->GetIsolate()); |
1584 env.ExposeDebug(); | 1573 env.ExposeDebug(); |
1585 | 1574 |
1586 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1575 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1587 v8::Undefined()); | |
1588 | 1576 |
1589 v8::Local<v8::String> script = v8::String::New( | 1577 v8::Local<v8::String> script = v8::String::New( |
1590 "function f() {\n" | 1578 "function f() {\n" |
1591 " function h() {\n" | 1579 " function h() {\n" |
1592 " a = 0; // line 2\n" | 1580 " a = 0; // line 2\n" |
1593 " }\n" | 1581 " }\n" |
1594 " b = 1; // line 4\n" | 1582 " b = 1; // line 4\n" |
1595 " return h();\n" | 1583 " return h();\n" |
1596 "}\n" | 1584 "}\n" |
1597 "\n" | 1585 "\n" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 ClearBreakPointFromJS(sbp2); | 1649 ClearBreakPointFromJS(sbp2); |
1662 ClearBreakPointFromJS(sbp3); | 1650 ClearBreakPointFromJS(sbp3); |
1663 ClearBreakPointFromJS(sbp4); | 1651 ClearBreakPointFromJS(sbp4); |
1664 ClearBreakPointFromJS(sbp5); | 1652 ClearBreakPointFromJS(sbp5); |
1665 ClearBreakPointFromJS(sbp6); | 1653 ClearBreakPointFromJS(sbp6); |
1666 f->Call(env->Global(), 0, NULL); | 1654 f->Call(env->Global(), 0, NULL); |
1667 CHECK_EQ(0, break_point_hit_count); | 1655 CHECK_EQ(0, break_point_hit_count); |
1668 g->Call(env->Global(), 0, NULL); | 1656 g->Call(env->Global(), 0, NULL); |
1669 CHECK_EQ(0, break_point_hit_count); | 1657 CHECK_EQ(0, break_point_hit_count); |
1670 | 1658 |
1671 v8::Debug::SetDebugEventListener(NULL); | 1659 v8::Debug::SetDebugEventListener2(NULL); |
1672 CheckDebuggerUnloaded(); | 1660 CheckDebuggerUnloaded(); |
1673 | 1661 |
1674 // Make sure that the break point numbers are consecutive. | 1662 // Make sure that the break point numbers are consecutive. |
1675 CHECK_EQ(1, sbp1); | 1663 CHECK_EQ(1, sbp1); |
1676 CHECK_EQ(2, sbp2); | 1664 CHECK_EQ(2, sbp2); |
1677 CHECK_EQ(3, sbp3); | 1665 CHECK_EQ(3, sbp3); |
1678 CHECK_EQ(4, sbp4); | 1666 CHECK_EQ(4, sbp4); |
1679 CHECK_EQ(5, sbp5); | 1667 CHECK_EQ(5, sbp5); |
1680 CHECK_EQ(6, sbp6); | 1668 CHECK_EQ(6, sbp6); |
1681 } | 1669 } |
1682 | 1670 |
1683 | 1671 |
1684 TEST(ScriptBreakPointByIdThroughJavaScript) { | 1672 TEST(ScriptBreakPointByIdThroughJavaScript) { |
1685 break_point_hit_count = 0; | 1673 break_point_hit_count = 0; |
1686 DebugLocalContext env; | 1674 DebugLocalContext env; |
1687 v8::HandleScope scope(env->GetIsolate()); | 1675 v8::HandleScope scope(env->GetIsolate()); |
1688 env.ExposeDebug(); | 1676 env.ExposeDebug(); |
1689 | 1677 |
1690 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1678 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1691 v8::Undefined()); | |
1692 | 1679 |
1693 v8::Local<v8::String> source = v8::String::New( | 1680 v8::Local<v8::String> source = v8::String::New( |
1694 "function f() {\n" | 1681 "function f() {\n" |
1695 " function h() {\n" | 1682 " function h() {\n" |
1696 " a = 0; // line 2\n" | 1683 " a = 0; // line 2\n" |
1697 " }\n" | 1684 " }\n" |
1698 " b = 1; // line 4\n" | 1685 " b = 1; // line 4\n" |
1699 " return h();\n" | 1686 " return h();\n" |
1700 "}\n" | 1687 "}\n" |
1701 "\n" | 1688 "\n" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 ClearBreakPointFromJS(sbp2); | 1756 ClearBreakPointFromJS(sbp2); |
1770 ClearBreakPointFromJS(sbp3); | 1757 ClearBreakPointFromJS(sbp3); |
1771 ClearBreakPointFromJS(sbp4); | 1758 ClearBreakPointFromJS(sbp4); |
1772 ClearBreakPointFromJS(sbp5); | 1759 ClearBreakPointFromJS(sbp5); |
1773 ClearBreakPointFromJS(sbp6); | 1760 ClearBreakPointFromJS(sbp6); |
1774 f->Call(env->Global(), 0, NULL); | 1761 f->Call(env->Global(), 0, NULL); |
1775 CHECK_EQ(0, break_point_hit_count); | 1762 CHECK_EQ(0, break_point_hit_count); |
1776 g->Call(env->Global(), 0, NULL); | 1763 g->Call(env->Global(), 0, NULL); |
1777 CHECK_EQ(0, break_point_hit_count); | 1764 CHECK_EQ(0, break_point_hit_count); |
1778 | 1765 |
1779 v8::Debug::SetDebugEventListener(NULL); | 1766 v8::Debug::SetDebugEventListener2(NULL); |
1780 CheckDebuggerUnloaded(); | 1767 CheckDebuggerUnloaded(); |
1781 | 1768 |
1782 // Make sure that the break point numbers are consecutive. | 1769 // Make sure that the break point numbers are consecutive. |
1783 CHECK_EQ(1, sbp1); | 1770 CHECK_EQ(1, sbp1); |
1784 CHECK_EQ(2, sbp2); | 1771 CHECK_EQ(2, sbp2); |
1785 CHECK_EQ(3, sbp3); | 1772 CHECK_EQ(3, sbp3); |
1786 CHECK_EQ(4, sbp4); | 1773 CHECK_EQ(4, sbp4); |
1787 CHECK_EQ(5, sbp5); | 1774 CHECK_EQ(5, sbp5); |
1788 CHECK_EQ(6, sbp6); | 1775 CHECK_EQ(6, sbp6); |
1789 } | 1776 } |
1790 | 1777 |
1791 | 1778 |
1792 // Test conditional script break points. | 1779 // Test conditional script break points. |
1793 TEST(EnableDisableScriptBreakPoint) { | 1780 TEST(EnableDisableScriptBreakPoint) { |
1794 break_point_hit_count = 0; | 1781 break_point_hit_count = 0; |
1795 DebugLocalContext env; | 1782 DebugLocalContext env; |
1796 v8::HandleScope scope(env->GetIsolate()); | 1783 v8::HandleScope scope(env->GetIsolate()); |
1797 env.ExposeDebug(); | 1784 env.ExposeDebug(); |
1798 | 1785 |
1799 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1786 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1800 v8::Undefined()); | |
1801 | 1787 |
1802 v8::Local<v8::String> script = v8::String::New( | 1788 v8::Local<v8::String> script = v8::String::New( |
1803 "function f() {\n" | 1789 "function f() {\n" |
1804 " a = 0; // line 1\n" | 1790 " a = 0; // line 1\n" |
1805 "};"); | 1791 "};"); |
1806 | 1792 |
1807 // Compile the script and get function f. | 1793 // Compile the script and get function f. |
1808 v8::ScriptOrigin origin = | 1794 v8::ScriptOrigin origin = |
1809 v8::ScriptOrigin(v8::String::New("test")); | 1795 v8::ScriptOrigin(v8::String::New("test")); |
1810 v8::Script::Compile(script, &origin)->Run(); | 1796 v8::Script::Compile(script, &origin)->Run(); |
(...skipping 23 matching lines...) Expand all Loading... |
1834 // Reload the script and get f again checking that the disabeling survives. | 1820 // Reload the script and get f again checking that the disabeling survives. |
1835 v8::Script::Compile(script, &origin)->Run(); | 1821 v8::Script::Compile(script, &origin)->Run(); |
1836 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1822 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1837 f->Call(env->Global(), 0, NULL); | 1823 f->Call(env->Global(), 0, NULL); |
1838 CHECK_EQ(2, break_point_hit_count); | 1824 CHECK_EQ(2, break_point_hit_count); |
1839 | 1825 |
1840 EnableScriptBreakPointFromJS(sbp); | 1826 EnableScriptBreakPointFromJS(sbp); |
1841 f->Call(env->Global(), 0, NULL); | 1827 f->Call(env->Global(), 0, NULL); |
1842 CHECK_EQ(3, break_point_hit_count); | 1828 CHECK_EQ(3, break_point_hit_count); |
1843 | 1829 |
1844 v8::Debug::SetDebugEventListener(NULL); | 1830 v8::Debug::SetDebugEventListener2(NULL); |
1845 CheckDebuggerUnloaded(); | 1831 CheckDebuggerUnloaded(); |
1846 } | 1832 } |
1847 | 1833 |
1848 | 1834 |
1849 // Test conditional script break points. | 1835 // Test conditional script break points. |
1850 TEST(ConditionalScriptBreakPoint) { | 1836 TEST(ConditionalScriptBreakPoint) { |
1851 break_point_hit_count = 0; | 1837 break_point_hit_count = 0; |
1852 DebugLocalContext env; | 1838 DebugLocalContext env; |
1853 v8::HandleScope scope(env->GetIsolate()); | 1839 v8::HandleScope scope(env->GetIsolate()); |
1854 env.ExposeDebug(); | 1840 env.ExposeDebug(); |
1855 | 1841 |
1856 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1842 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1857 v8::Undefined()); | |
1858 | 1843 |
1859 v8::Local<v8::String> script = v8::String::New( | 1844 v8::Local<v8::String> script = v8::String::New( |
1860 "count = 0;\n" | 1845 "count = 0;\n" |
1861 "function f() {\n" | 1846 "function f() {\n" |
1862 " g(count++); // line 2\n" | 1847 " g(count++); // line 2\n" |
1863 "};\n" | 1848 "};\n" |
1864 "function g(x) {\n" | 1849 "function g(x) {\n" |
1865 " var a=x; // line 5\n" | 1850 " var a=x; // line 5\n" |
1866 "};"); | 1851 "};"); |
1867 | 1852 |
(...skipping 28 matching lines...) Expand all Loading... |
1896 // Reload the script and get f again checking that the condition survives. | 1881 // Reload the script and get f again checking that the condition survives. |
1897 v8::Script::Compile(script, &origin)->Run(); | 1882 v8::Script::Compile(script, &origin)->Run(); |
1898 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1883 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1899 | 1884 |
1900 break_point_hit_count = 0; | 1885 break_point_hit_count = 0; |
1901 for (int i = 0; i < 10; i++) { | 1886 for (int i = 0; i < 10; i++) { |
1902 f->Call(env->Global(), 0, NULL); | 1887 f->Call(env->Global(), 0, NULL); |
1903 } | 1888 } |
1904 CHECK_EQ(5, break_point_hit_count); | 1889 CHECK_EQ(5, break_point_hit_count); |
1905 | 1890 |
1906 v8::Debug::SetDebugEventListener(NULL); | 1891 v8::Debug::SetDebugEventListener2(NULL); |
1907 CheckDebuggerUnloaded(); | 1892 CheckDebuggerUnloaded(); |
1908 } | 1893 } |
1909 | 1894 |
1910 | 1895 |
1911 // Test ignore count on script break points. | 1896 // Test ignore count on script break points. |
1912 TEST(ScriptBreakPointIgnoreCount) { | 1897 TEST(ScriptBreakPointIgnoreCount) { |
1913 break_point_hit_count = 0; | 1898 break_point_hit_count = 0; |
1914 DebugLocalContext env; | 1899 DebugLocalContext env; |
1915 v8::HandleScope scope(env->GetIsolate()); | 1900 v8::HandleScope scope(env->GetIsolate()); |
1916 env.ExposeDebug(); | 1901 env.ExposeDebug(); |
1917 | 1902 |
1918 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1903 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1919 v8::Undefined()); | |
1920 | 1904 |
1921 v8::Local<v8::String> script = v8::String::New( | 1905 v8::Local<v8::String> script = v8::String::New( |
1922 "function f() {\n" | 1906 "function f() {\n" |
1923 " a = 0; // line 1\n" | 1907 " a = 0; // line 1\n" |
1924 "};"); | 1908 "};"); |
1925 | 1909 |
1926 // Compile the script and get function f. | 1910 // Compile the script and get function f. |
1927 v8::ScriptOrigin origin = | 1911 v8::ScriptOrigin origin = |
1928 v8::ScriptOrigin(v8::String::New("test")); | 1912 v8::ScriptOrigin(v8::String::New("test")); |
1929 v8::Script::Compile(script, &origin)->Run(); | 1913 v8::Script::Compile(script, &origin)->Run(); |
(...skipping 21 matching lines...) Expand all Loading... |
1951 // Reload the script and get f again checking that the ignore survives. | 1935 // Reload the script and get f again checking that the ignore survives. |
1952 v8::Script::Compile(script, &origin)->Run(); | 1936 v8::Script::Compile(script, &origin)->Run(); |
1953 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1937 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1954 | 1938 |
1955 break_point_hit_count = 0; | 1939 break_point_hit_count = 0; |
1956 for (int i = 0; i < 10; i++) { | 1940 for (int i = 0; i < 10; i++) { |
1957 f->Call(env->Global(), 0, NULL); | 1941 f->Call(env->Global(), 0, NULL); |
1958 } | 1942 } |
1959 CHECK_EQ(5, break_point_hit_count); | 1943 CHECK_EQ(5, break_point_hit_count); |
1960 | 1944 |
1961 v8::Debug::SetDebugEventListener(NULL); | 1945 v8::Debug::SetDebugEventListener2(NULL); |
1962 CheckDebuggerUnloaded(); | 1946 CheckDebuggerUnloaded(); |
1963 } | 1947 } |
1964 | 1948 |
1965 | 1949 |
1966 // Test that script break points survive when a script is reloaded. | 1950 // Test that script break points survive when a script is reloaded. |
1967 TEST(ScriptBreakPointReload) { | 1951 TEST(ScriptBreakPointReload) { |
1968 break_point_hit_count = 0; | 1952 break_point_hit_count = 0; |
1969 DebugLocalContext env; | 1953 DebugLocalContext env; |
1970 v8::HandleScope scope(env->GetIsolate()); | 1954 v8::HandleScope scope(env->GetIsolate()); |
1971 env.ExposeDebug(); | 1955 env.ExposeDebug(); |
1972 | 1956 |
1973 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1957 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
1974 v8::Undefined()); | |
1975 | 1958 |
1976 v8::Local<v8::Function> f; | 1959 v8::Local<v8::Function> f; |
1977 v8::Local<v8::String> script = v8::String::New( | 1960 v8::Local<v8::String> script = v8::String::New( |
1978 "function f() {\n" | 1961 "function f() {\n" |
1979 " function h() {\n" | 1962 " function h() {\n" |
1980 " a = 0; // line 2\n" | 1963 " a = 0; // line 2\n" |
1981 " }\n" | 1964 " }\n" |
1982 " b = 1; // line 4\n" | 1965 " b = 1; // line 4\n" |
1983 " return h();\n" | 1966 " return h();\n" |
1984 "}"); | 1967 "}"); |
(...skipping 25 matching lines...) Expand all Loading... |
2010 | 1993 |
2011 // Compile the script again and get the function. | 1994 // Compile the script again and get the function. |
2012 v8::Script::Compile(script, &origin_1)->Run(); | 1995 v8::Script::Compile(script, &origin_1)->Run(); |
2013 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1996 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
2014 | 1997 |
2015 // Call f and check that the script break point is active. | 1998 // Call f and check that the script break point is active. |
2016 break_point_hit_count = 0; | 1999 break_point_hit_count = 0; |
2017 f->Call(env->Global(), 0, NULL); | 2000 f->Call(env->Global(), 0, NULL); |
2018 CHECK_EQ(1, break_point_hit_count); | 2001 CHECK_EQ(1, break_point_hit_count); |
2019 | 2002 |
2020 v8::Debug::SetDebugEventListener(NULL); | 2003 v8::Debug::SetDebugEventListener2(NULL); |
2021 CheckDebuggerUnloaded(); | 2004 CheckDebuggerUnloaded(); |
2022 } | 2005 } |
2023 | 2006 |
2024 | 2007 |
2025 // Test when several scripts has the same script data | 2008 // Test when several scripts has the same script data |
2026 TEST(ScriptBreakPointMultiple) { | 2009 TEST(ScriptBreakPointMultiple) { |
2027 break_point_hit_count = 0; | 2010 break_point_hit_count = 0; |
2028 DebugLocalContext env; | 2011 DebugLocalContext env; |
2029 v8::HandleScope scope(env->GetIsolate()); | 2012 v8::HandleScope scope(env->GetIsolate()); |
2030 env.ExposeDebug(); | 2013 env.ExposeDebug(); |
2031 | 2014 |
2032 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2015 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2033 v8::Undefined()); | |
2034 | 2016 |
2035 v8::Local<v8::Function> f; | 2017 v8::Local<v8::Function> f; |
2036 v8::Local<v8::String> script_f = v8::String::New( | 2018 v8::Local<v8::String> script_f = v8::String::New( |
2037 "function f() {\n" | 2019 "function f() {\n" |
2038 " a = 0; // line 1\n" | 2020 " a = 0; // line 1\n" |
2039 "}"); | 2021 "}"); |
2040 | 2022 |
2041 v8::Local<v8::Function> g; | 2023 v8::Local<v8::Function> g; |
2042 v8::Local<v8::String> script_g = v8::String::New( | 2024 v8::Local<v8::String> script_g = v8::String::New( |
2043 "function g() {\n" | 2025 "function g() {\n" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2076 // Set script break point with the scripts loaded. | 2058 // Set script break point with the scripts loaded. |
2077 sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); | 2059 sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); |
2078 | 2060 |
2079 // Call f and g and check that the script break point is active. | 2061 // Call f and g and check that the script break point is active. |
2080 break_point_hit_count = 0; | 2062 break_point_hit_count = 0; |
2081 f->Call(env->Global(), 0, NULL); | 2063 f->Call(env->Global(), 0, NULL); |
2082 CHECK_EQ(1, break_point_hit_count); | 2064 CHECK_EQ(1, break_point_hit_count); |
2083 g->Call(env->Global(), 0, NULL); | 2065 g->Call(env->Global(), 0, NULL); |
2084 CHECK_EQ(2, break_point_hit_count); | 2066 CHECK_EQ(2, break_point_hit_count); |
2085 | 2067 |
2086 v8::Debug::SetDebugEventListener(NULL); | 2068 v8::Debug::SetDebugEventListener2(NULL); |
2087 CheckDebuggerUnloaded(); | 2069 CheckDebuggerUnloaded(); |
2088 } | 2070 } |
2089 | 2071 |
2090 | 2072 |
2091 // Test the script origin which has both name and line offset. | 2073 // Test the script origin which has both name and line offset. |
2092 TEST(ScriptBreakPointLineOffset) { | 2074 TEST(ScriptBreakPointLineOffset) { |
2093 break_point_hit_count = 0; | 2075 break_point_hit_count = 0; |
2094 DebugLocalContext env; | 2076 DebugLocalContext env; |
2095 v8::HandleScope scope(env->GetIsolate()); | 2077 v8::HandleScope scope(env->GetIsolate()); |
2096 env.ExposeDebug(); | 2078 env.ExposeDebug(); |
2097 | 2079 |
2098 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2080 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2099 v8::Undefined()); | |
2100 | 2081 |
2101 v8::Local<v8::Function> f; | 2082 v8::Local<v8::Function> f; |
2102 v8::Local<v8::String> script = v8::String::New( | 2083 v8::Local<v8::String> script = v8::String::New( |
2103 "function f() {\n" | 2084 "function f() {\n" |
2104 " a = 0; // line 8 as this script has line offset 7\n" | 2085 " a = 0; // line 8 as this script has line offset 7\n" |
2105 " b = 0; // line 9 as this script has line offset 7\n" | 2086 " b = 0; // line 9 as this script has line offset 7\n" |
2106 "}"); | 2087 "}"); |
2107 | 2088 |
2108 // Create script origin both name and line offset. | 2089 // Create script origin both name and line offset. |
2109 v8::ScriptOrigin origin(v8::String::New("test.html"), | 2090 v8::ScriptOrigin origin(v8::String::New("test.html"), |
(...skipping 22 matching lines...) Expand all Loading... |
2132 CHECK_EQ(0, break_point_hit_count); | 2113 CHECK_EQ(0, break_point_hit_count); |
2133 | 2114 |
2134 // Set a script break point with the script loaded. | 2115 // Set a script break point with the script loaded. |
2135 sbp1 = SetScriptBreakPointByNameFromJS("test.html", 9, 0); | 2116 sbp1 = SetScriptBreakPointByNameFromJS("test.html", 9, 0); |
2136 | 2117 |
2137 // Call f and check that the script break point is active. | 2118 // Call f and check that the script break point is active. |
2138 break_point_hit_count = 0; | 2119 break_point_hit_count = 0; |
2139 f->Call(env->Global(), 0, NULL); | 2120 f->Call(env->Global(), 0, NULL); |
2140 CHECK_EQ(1, break_point_hit_count); | 2121 CHECK_EQ(1, break_point_hit_count); |
2141 | 2122 |
2142 v8::Debug::SetDebugEventListener(NULL); | 2123 v8::Debug::SetDebugEventListener2(NULL); |
2143 CheckDebuggerUnloaded(); | 2124 CheckDebuggerUnloaded(); |
2144 } | 2125 } |
2145 | 2126 |
2146 | 2127 |
2147 // Test script break points set on lines. | 2128 // Test script break points set on lines. |
2148 TEST(ScriptBreakPointLine) { | 2129 TEST(ScriptBreakPointLine) { |
2149 DebugLocalContext env; | 2130 DebugLocalContext env; |
2150 v8::HandleScope scope(env->GetIsolate()); | 2131 v8::HandleScope scope(env->GetIsolate()); |
2151 env.ExposeDebug(); | 2132 env.ExposeDebug(); |
2152 | 2133 |
2153 // Create a function for checking the function when hitting a break point. | 2134 // Create a function for checking the function when hitting a break point. |
2154 frame_function_name = CompileFunction(&env, | 2135 frame_function_name = CompileFunction(&env, |
2155 frame_function_name_source, | 2136 frame_function_name_source, |
2156 "frame_function_name"); | 2137 "frame_function_name"); |
2157 | 2138 |
2158 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2139 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2159 v8::Undefined()); | |
2160 | 2140 |
2161 v8::Local<v8::Function> f; | 2141 v8::Local<v8::Function> f; |
2162 v8::Local<v8::Function> g; | 2142 v8::Local<v8::Function> g; |
2163 v8::Local<v8::String> script = v8::String::New( | 2143 v8::Local<v8::String> script = v8::String::New( |
2164 "a = 0 // line 0\n" | 2144 "a = 0 // line 0\n" |
2165 "function f() {\n" | 2145 "function f() {\n" |
2166 " a = 1; // line 2\n" | 2146 " a = 1; // line 2\n" |
2167 "}\n" | 2147 "}\n" |
2168 " a = 2; // line 4\n" | 2148 " a = 2; // line 4\n" |
2169 " /* xx */ function g() { // line 5\n" | 2149 " /* xx */ function g() { // line 5\n" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 | 2218 |
2239 // Clear the last break points, and reload the script which should not hit any | 2219 // Clear the last break points, and reload the script which should not hit any |
2240 // break points. | 2220 // break points. |
2241 ClearBreakPointFromJS(sbp1); | 2221 ClearBreakPointFromJS(sbp1); |
2242 ClearBreakPointFromJS(sbp5); | 2222 ClearBreakPointFromJS(sbp5); |
2243 ClearBreakPointFromJS(sbp6); | 2223 ClearBreakPointFromJS(sbp6); |
2244 break_point_hit_count = 0; | 2224 break_point_hit_count = 0; |
2245 v8::Script::Compile(script, &origin)->Run(); | 2225 v8::Script::Compile(script, &origin)->Run(); |
2246 CHECK_EQ(0, break_point_hit_count); | 2226 CHECK_EQ(0, break_point_hit_count); |
2247 | 2227 |
2248 v8::Debug::SetDebugEventListener(NULL); | 2228 v8::Debug::SetDebugEventListener2(NULL); |
2249 CheckDebuggerUnloaded(); | 2229 CheckDebuggerUnloaded(); |
2250 } | 2230 } |
2251 | 2231 |
2252 | 2232 |
2253 // Test top level script break points set on lines. | 2233 // Test top level script break points set on lines. |
2254 TEST(ScriptBreakPointLineTopLevel) { | 2234 TEST(ScriptBreakPointLineTopLevel) { |
2255 DebugLocalContext env; | 2235 DebugLocalContext env; |
2256 v8::HandleScope scope(env->GetIsolate()); | 2236 v8::HandleScope scope(env->GetIsolate()); |
2257 env.ExposeDebug(); | 2237 env.ExposeDebug(); |
2258 | 2238 |
2259 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2239 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2260 v8::Undefined()); | |
2261 | 2240 |
2262 v8::Local<v8::String> script = v8::String::New( | 2241 v8::Local<v8::String> script = v8::String::New( |
2263 "function f() {\n" | 2242 "function f() {\n" |
2264 " a = 1; // line 1\n" | 2243 " a = 1; // line 1\n" |
2265 "}\n" | 2244 "}\n" |
2266 "a = 2; // line 3\n"); | 2245 "a = 2; // line 3\n"); |
2267 v8::Local<v8::Function> f; | 2246 v8::Local<v8::Function> f; |
2268 { | 2247 { |
2269 v8::HandleScope scope(env->GetIsolate()); | 2248 v8::HandleScope scope(env->GetIsolate()); |
2270 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); | 2249 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); |
(...skipping 12 matching lines...) Expand all Loading... |
2283 // Recompile and run script and check that break point was hit. | 2262 // Recompile and run script and check that break point was hit. |
2284 break_point_hit_count = 0; | 2263 break_point_hit_count = 0; |
2285 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); | 2264 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); |
2286 CHECK_EQ(1, break_point_hit_count); | 2265 CHECK_EQ(1, break_point_hit_count); |
2287 | 2266 |
2288 // Call f and check that there are still no break points. | 2267 // Call f and check that there are still no break points. |
2289 break_point_hit_count = 0; | 2268 break_point_hit_count = 0; |
2290 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 2269 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
2291 CHECK_EQ(0, break_point_hit_count); | 2270 CHECK_EQ(0, break_point_hit_count); |
2292 | 2271 |
2293 v8::Debug::SetDebugEventListener(NULL); | 2272 v8::Debug::SetDebugEventListener2(NULL); |
2294 CheckDebuggerUnloaded(); | 2273 CheckDebuggerUnloaded(); |
2295 } | 2274 } |
2296 | 2275 |
2297 | 2276 |
2298 // Test that it is possible to add and remove break points in a top level | 2277 // Test that it is possible to add and remove break points in a top level |
2299 // function which has no references but has not been collected yet. | 2278 // function which has no references but has not been collected yet. |
2300 TEST(ScriptBreakPointTopLevelCrash) { | 2279 TEST(ScriptBreakPointTopLevelCrash) { |
2301 DebugLocalContext env; | 2280 DebugLocalContext env; |
2302 v8::HandleScope scope(env->GetIsolate()); | 2281 v8::HandleScope scope(env->GetIsolate()); |
2303 env.ExposeDebug(); | 2282 env.ExposeDebug(); |
2304 | 2283 |
2305 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2284 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2306 v8::Undefined()); | |
2307 | 2285 |
2308 v8::Local<v8::String> script_source = v8::String::New( | 2286 v8::Local<v8::String> script_source = v8::String::New( |
2309 "function f() {\n" | 2287 "function f() {\n" |
2310 " return 0;\n" | 2288 " return 0;\n" |
2311 "}\n" | 2289 "}\n" |
2312 "f()"); | 2290 "f()"); |
2313 | 2291 |
2314 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); | 2292 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); |
2315 { | 2293 { |
2316 v8::HandleScope scope(env->GetIsolate()); | 2294 v8::HandleScope scope(env->GetIsolate()); |
2317 break_point_hit_count = 0; | 2295 break_point_hit_count = 0; |
2318 v8::Script::Compile(script_source, v8::String::New("test.html"))->Run(); | 2296 v8::Script::Compile(script_source, v8::String::New("test.html"))->Run(); |
2319 CHECK_EQ(1, break_point_hit_count); | 2297 CHECK_EQ(1, break_point_hit_count); |
2320 } | 2298 } |
2321 | 2299 |
2322 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); | 2300 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); |
2323 ClearBreakPointFromJS(sbp1); | 2301 ClearBreakPointFromJS(sbp1); |
2324 ClearBreakPointFromJS(sbp2); | 2302 ClearBreakPointFromJS(sbp2); |
2325 | 2303 |
2326 v8::Debug::SetDebugEventListener(NULL); | 2304 v8::Debug::SetDebugEventListener2(NULL); |
2327 CheckDebuggerUnloaded(); | 2305 CheckDebuggerUnloaded(); |
2328 } | 2306 } |
2329 | 2307 |
2330 | 2308 |
2331 // Test that it is possible to remove the last break point for a function | 2309 // Test that it is possible to remove the last break point for a function |
2332 // inside the break handling of that break point. | 2310 // inside the break handling of that break point. |
2333 TEST(RemoveBreakPointInBreak) { | 2311 TEST(RemoveBreakPointInBreak) { |
2334 DebugLocalContext env; | 2312 DebugLocalContext env; |
2335 v8::HandleScope scope(env->GetIsolate()); | 2313 v8::HandleScope scope(env->GetIsolate()); |
2336 | 2314 |
2337 v8::Local<v8::Function> foo = | 2315 v8::Local<v8::Function> foo = |
2338 CompileFunction(&env, "function foo(){a=1;}", "foo"); | 2316 CompileFunction(&env, "function foo(){a=1;}", "foo"); |
2339 debug_event_remove_break_point = SetBreakPoint(foo, 0); | 2317 debug_event_remove_break_point = SetBreakPoint(foo, 0); |
2340 | 2318 |
2341 // Register the debug event listener pasing the function | 2319 // Register the debug event listener pasing the function |
2342 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); | 2320 v8::Debug::SetDebugEventListener2(DebugEventRemoveBreakPoint, foo); |
2343 | 2321 |
2344 break_point_hit_count = 0; | 2322 break_point_hit_count = 0; |
2345 foo->Call(env->Global(), 0, NULL); | 2323 foo->Call(env->Global(), 0, NULL); |
2346 CHECK_EQ(1, break_point_hit_count); | 2324 CHECK_EQ(1, break_point_hit_count); |
2347 | 2325 |
2348 break_point_hit_count = 0; | 2326 break_point_hit_count = 0; |
2349 foo->Call(env->Global(), 0, NULL); | 2327 foo->Call(env->Global(), 0, NULL); |
2350 CHECK_EQ(0, break_point_hit_count); | 2328 CHECK_EQ(0, break_point_hit_count); |
2351 | 2329 |
2352 v8::Debug::SetDebugEventListener(NULL); | 2330 v8::Debug::SetDebugEventListener2(NULL); |
2353 CheckDebuggerUnloaded(); | 2331 CheckDebuggerUnloaded(); |
2354 } | 2332 } |
2355 | 2333 |
2356 | 2334 |
2357 // Test that the debugger statement causes a break. | 2335 // Test that the debugger statement causes a break. |
2358 TEST(DebuggerStatement) { | 2336 TEST(DebuggerStatement) { |
2359 break_point_hit_count = 0; | 2337 break_point_hit_count = 0; |
2360 DebugLocalContext env; | 2338 DebugLocalContext env; |
2361 v8::HandleScope scope(env->GetIsolate()); | 2339 v8::HandleScope scope(env->GetIsolate()); |
2362 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2340 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2363 v8::Undefined()); | |
2364 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run(); | 2341 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run(); |
2365 v8::Script::Compile(v8::String::New( | 2342 v8::Script::Compile(v8::String::New( |
2366 "function foo(){debugger;debugger;}"))->Run(); | 2343 "function foo(){debugger;debugger;}"))->Run(); |
2367 v8::Local<v8::Function> foo = | 2344 v8::Local<v8::Function> foo = |
2368 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 2345 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
2369 v8::Local<v8::Function> bar = | 2346 v8::Local<v8::Function> bar = |
2370 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar"))); | 2347 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar"))); |
2371 | 2348 |
2372 // Run function with debugger statement | 2349 // Run function with debugger statement |
2373 bar->Call(env->Global(), 0, NULL); | 2350 bar->Call(env->Global(), 0, NULL); |
2374 CHECK_EQ(1, break_point_hit_count); | 2351 CHECK_EQ(1, break_point_hit_count); |
2375 | 2352 |
2376 // Run function with two debugger statement | 2353 // Run function with two debugger statement |
2377 foo->Call(env->Global(), 0, NULL); | 2354 foo->Call(env->Global(), 0, NULL); |
2378 CHECK_EQ(3, break_point_hit_count); | 2355 CHECK_EQ(3, break_point_hit_count); |
2379 | 2356 |
2380 v8::Debug::SetDebugEventListener(NULL); | 2357 v8::Debug::SetDebugEventListener2(NULL); |
2381 CheckDebuggerUnloaded(); | 2358 CheckDebuggerUnloaded(); |
2382 } | 2359 } |
2383 | 2360 |
2384 | 2361 |
2385 // Test setting a breakpoint on the debugger statement. | 2362 // Test setting a breakpoint on the debugger statement. |
2386 TEST(DebuggerStatementBreakpoint) { | 2363 TEST(DebuggerStatementBreakpoint) { |
2387 break_point_hit_count = 0; | 2364 break_point_hit_count = 0; |
2388 DebugLocalContext env; | 2365 DebugLocalContext env; |
2389 v8::HandleScope scope(env->GetIsolate()); | 2366 v8::HandleScope scope(env->GetIsolate()); |
2390 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 2367 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2391 v8::Undefined()); | |
2392 v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run(); | 2368 v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run(); |
2393 v8::Local<v8::Function> foo = | 2369 v8::Local<v8::Function> foo = |
2394 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 2370 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
2395 | 2371 |
2396 // The debugger statement triggers breakpint hit | 2372 // The debugger statement triggers breakpint hit |
2397 foo->Call(env->Global(), 0, NULL); | 2373 foo->Call(env->Global(), 0, NULL); |
2398 CHECK_EQ(1, break_point_hit_count); | 2374 CHECK_EQ(1, break_point_hit_count); |
2399 | 2375 |
2400 int bp = SetBreakPoint(foo, 0); | 2376 int bp = SetBreakPoint(foo, 0); |
2401 | 2377 |
2402 // Set breakpoint does not duplicate hits | 2378 // Set breakpoint does not duplicate hits |
2403 foo->Call(env->Global(), 0, NULL); | 2379 foo->Call(env->Global(), 0, NULL); |
2404 CHECK_EQ(2, break_point_hit_count); | 2380 CHECK_EQ(2, break_point_hit_count); |
2405 | 2381 |
2406 ClearBreakPoint(bp); | 2382 ClearBreakPoint(bp); |
2407 v8::Debug::SetDebugEventListener(NULL); | 2383 v8::Debug::SetDebugEventListener2(NULL); |
2408 CheckDebuggerUnloaded(); | 2384 CheckDebuggerUnloaded(); |
2409 } | 2385 } |
2410 | 2386 |
2411 | 2387 |
2412 // Test that the evaluation of expressions when a break point is hit generates | 2388 // Test that the evaluation of expressions when a break point is hit generates |
2413 // the correct results. | 2389 // the correct results. |
2414 TEST(DebugEvaluate) { | 2390 TEST(DebugEvaluate) { |
2415 DebugLocalContext env; | 2391 DebugLocalContext env; |
2416 v8::HandleScope scope(env->GetIsolate()); | 2392 v8::HandleScope scope(env->GetIsolate()); |
2417 env.ExposeDebug(); | 2393 env.ExposeDebug(); |
2418 | 2394 |
2419 // Create a function for checking the evaluation when hitting a break point. | 2395 // Create a function for checking the evaluation when hitting a break point. |
2420 evaluate_check_function = CompileFunction(&env, | 2396 evaluate_check_function = CompileFunction(&env, |
2421 evaluate_check_source, | 2397 evaluate_check_source, |
2422 "evaluate_check"); | 2398 "evaluate_check"); |
2423 // Register the debug event listener | 2399 // Register the debug event listener |
2424 v8::Debug::SetDebugEventListener(DebugEventEvaluate); | 2400 v8::Debug::SetDebugEventListener2(DebugEventEvaluate); |
2425 | 2401 |
2426 // Different expected vaules of x and a when in a break point (u = undefined, | 2402 // Different expected vaules of x and a when in a break point (u = undefined, |
2427 // d = Hello, world!). | 2403 // d = Hello, world!). |
2428 struct EvaluateCheck checks_uu[] = { | 2404 struct EvaluateCheck checks_uu[] = { |
2429 {"x", v8::Undefined()}, | 2405 {"x", v8::Undefined()}, |
2430 {"a", v8::Undefined()}, | 2406 {"a", v8::Undefined()}, |
2431 {NULL, v8::Handle<v8::Value>()} | 2407 {NULL, v8::Handle<v8::Value>()} |
2432 }; | 2408 }; |
2433 struct EvaluateCheck checks_hu[] = { | 2409 struct EvaluateCheck checks_hu[] = { |
2434 {"x", v8::String::New("Hello, world!")}, | 2410 {"x", v8::String::New("Hello, world!")}, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 | 2490 |
2515 // Call bar setting breakpoint after a=x in barbar and parameter | 2491 // Call bar setting breakpoint after a=x in barbar and parameter |
2516 // "Hello, world!". | 2492 // "Hello, world!". |
2517 checks = checks_hh; | 2493 checks = checks_hh; |
2518 v8::Handle<v8::Value> argv_bar_3[2] = { | 2494 v8::Handle<v8::Value> argv_bar_3[2] = { |
2519 v8::String::New("Hello, world!"), | 2495 v8::String::New("Hello, world!"), |
2520 v8::Number::New(barbar_break_position + 1) | 2496 v8::Number::New(barbar_break_position + 1) |
2521 }; | 2497 }; |
2522 bar->Call(env->Global(), 2, argv_bar_3); | 2498 bar->Call(env->Global(), 2, argv_bar_3); |
2523 | 2499 |
2524 v8::Debug::SetDebugEventListener(NULL); | 2500 v8::Debug::SetDebugEventListener2(NULL); |
2525 CheckDebuggerUnloaded(); | 2501 CheckDebuggerUnloaded(); |
2526 } | 2502 } |
2527 | 2503 |
2528 | 2504 |
2529 int debugEventCount = 0; | 2505 int debugEventCount = 0; |
2530 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { | 2506 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { |
2531 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; | 2507 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; |
2532 } | 2508 } |
2533 | 2509 |
2534 | 2510 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2695 return &results[counter % kArraySize]; | 2671 return &results[counter % kArraySize]; |
2696 } | 2672 } |
2697 void next() { | 2673 void next() { |
2698 counter++; | 2674 counter++; |
2699 } | 2675 } |
2700 }; | 2676 }; |
2701 | 2677 |
2702 DebugProcessDebugMessagesData process_debug_messages_data; | 2678 DebugProcessDebugMessagesData process_debug_messages_data; |
2703 | 2679 |
2704 static void DebugProcessDebugMessagesHandler( | 2680 static void DebugProcessDebugMessagesHandler( |
2705 const uint16_t* message, | 2681 const v8::Debug::Message& message) { |
2706 int length, | 2682 v8::Handle<v8::String> json = message.GetJSON(); |
2707 v8::Debug::ClientData* client_data) { | 2683 v8::String::AsciiValue ascii(json); |
2708 | |
2709 const int kBufferSize = 100000; | |
2710 char print_buffer[kBufferSize]; | |
2711 Utf16ToAscii(message, length, print_buffer, kBufferSize); | |
2712 | |
2713 EvaluateResult* array_item = process_debug_messages_data.current(); | 2684 EvaluateResult* array_item = process_debug_messages_data.current(); |
2714 | 2685 |
2715 bool res = GetEvaluateStringResult(print_buffer, | 2686 bool res = GetEvaluateStringResult(*ascii, |
2716 array_item->buffer, | 2687 array_item->buffer, |
2717 EvaluateResult::kBufferSize); | 2688 EvaluateResult::kBufferSize); |
2718 if (res) { | 2689 if (res) { |
2719 process_debug_messages_data.next(); | 2690 process_debug_messages_data.next(); |
2720 } | 2691 } |
2721 } | 2692 } |
2722 | 2693 |
2723 | 2694 |
2724 // Test that the evaluation of expressions works even from ProcessDebugMessages | 2695 // Test that the evaluation of expressions works even from ProcessDebugMessages |
2725 // i.e. with empty stack. | 2696 // i.e. with empty stack. |
2726 TEST(DebugEvaluateWithoutStack) { | 2697 TEST(DebugEvaluateWithoutStack) { |
2727 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler); | 2698 v8::Debug::SetMessageHandler2(DebugProcessDebugMessagesHandler); |
2728 | 2699 |
2729 DebugLocalContext env; | 2700 DebugLocalContext env; |
2730 v8::HandleScope scope(env->GetIsolate()); | 2701 v8::HandleScope scope(env->GetIsolate()); |
2731 | 2702 |
2732 const char* source = | 2703 const char* source = |
2733 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; | 2704 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; |
2734 | 2705 |
2735 v8::Script::Compile(v8::String::New(source))->Run(); | 2706 v8::Script::Compile(v8::String::New(source))->Run(); |
2736 | 2707 |
2737 v8::Debug::ProcessDebugMessages(); | 2708 v8::Debug::ProcessDebugMessages(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2771 | 2742 |
2772 v8::Debug::ProcessDebugMessages(); | 2743 v8::Debug::ProcessDebugMessages(); |
2773 | 2744 |
2774 CHECK_EQ(3, process_debug_messages_data.counter); | 2745 CHECK_EQ(3, process_debug_messages_data.counter); |
2775 | 2746 |
2776 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); | 2747 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); |
2777 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), | 2748 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), |
2778 0); | 2749 0); |
2779 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); | 2750 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); |
2780 | 2751 |
2781 v8::Debug::SetMessageHandler(NULL); | 2752 v8::Debug::SetMessageHandler2(NULL); |
2782 v8::Debug::SetDebugEventListener(NULL); | 2753 v8::Debug::SetDebugEventListener2(NULL); |
2783 CheckDebuggerUnloaded(); | 2754 CheckDebuggerUnloaded(); |
2784 } | 2755 } |
2785 | 2756 |
2786 | 2757 |
2787 // Simple test of the stepping mechanism using only store ICs. | 2758 // Simple test of the stepping mechanism using only store ICs. |
2788 TEST(DebugStepLinear) { | 2759 TEST(DebugStepLinear) { |
2789 DebugLocalContext env; | 2760 DebugLocalContext env; |
2790 v8::HandleScope scope(env->GetIsolate()); | 2761 v8::HandleScope scope(env->GetIsolate()); |
2791 | 2762 |
2792 // Create a function for testing stepping. | 2763 // Create a function for testing stepping. |
2793 v8::Local<v8::Function> foo = CompileFunction(&env, | 2764 v8::Local<v8::Function> foo = CompileFunction(&env, |
2794 "function foo(){a=1;b=1;c=1;}", | 2765 "function foo(){a=1;b=1;c=1;}", |
2795 "foo"); | 2766 "foo"); |
2796 | 2767 |
2797 // Run foo to allow it to get optimized. | 2768 // Run foo to allow it to get optimized. |
2798 CompileRun("a=0; b=0; c=0; foo();"); | 2769 CompileRun("a=0; b=0; c=0; foo();"); |
2799 | 2770 |
2800 SetBreakPoint(foo, 3); | 2771 SetBreakPoint(foo, 3); |
2801 | 2772 |
2802 // Register a debug event listener which steps and counts. | 2773 // Register a debug event listener which steps and counts. |
2803 v8::Debug::SetDebugEventListener(DebugEventStep); | 2774 v8::Debug::SetDebugEventListener2(DebugEventStep); |
2804 | 2775 |
2805 step_action = StepIn; | 2776 step_action = StepIn; |
2806 break_point_hit_count = 0; | 2777 break_point_hit_count = 0; |
2807 foo->Call(env->Global(), 0, NULL); | 2778 foo->Call(env->Global(), 0, NULL); |
2808 | 2779 |
2809 // With stepping all break locations are hit. | 2780 // With stepping all break locations are hit. |
2810 CHECK_EQ(4, break_point_hit_count); | 2781 CHECK_EQ(4, break_point_hit_count); |
2811 | 2782 |
2812 v8::Debug::SetDebugEventListener(NULL); | 2783 v8::Debug::SetDebugEventListener2(NULL); |
2813 CheckDebuggerUnloaded(); | 2784 CheckDebuggerUnloaded(); |
2814 | 2785 |
2815 // Register a debug event listener which just counts. | 2786 // Register a debug event listener which just counts. |
2816 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 2787 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
2817 | 2788 |
2818 SetBreakPoint(foo, 3); | 2789 SetBreakPoint(foo, 3); |
2819 break_point_hit_count = 0; | 2790 break_point_hit_count = 0; |
2820 foo->Call(env->Global(), 0, NULL); | 2791 foo->Call(env->Global(), 0, NULL); |
2821 | 2792 |
2822 // Without stepping only active break points are hit. | 2793 // Without stepping only active break points are hit. |
2823 CHECK_EQ(1, break_point_hit_count); | 2794 CHECK_EQ(1, break_point_hit_count); |
2824 | 2795 |
2825 v8::Debug::SetDebugEventListener(NULL); | 2796 v8::Debug::SetDebugEventListener2(NULL); |
2826 CheckDebuggerUnloaded(); | 2797 CheckDebuggerUnloaded(); |
2827 } | 2798 } |
2828 | 2799 |
2829 | 2800 |
2830 // Test of the stepping mechanism for keyed load in a loop. | 2801 // Test of the stepping mechanism for keyed load in a loop. |
2831 TEST(DebugStepKeyedLoadLoop) { | 2802 TEST(DebugStepKeyedLoadLoop) { |
2832 DebugLocalContext env; | 2803 DebugLocalContext env; |
2833 v8::HandleScope scope(env->GetIsolate()); | 2804 v8::HandleScope scope(env->GetIsolate()); |
2834 | 2805 |
2835 // Register a debug event listener which steps and counts. | 2806 // Register a debug event listener which steps and counts. |
2836 v8::Debug::SetDebugEventListener(DebugEventStep); | 2807 v8::Debug::SetDebugEventListener2(DebugEventStep); |
2837 | 2808 |
2838 // Create a function for testing stepping of keyed load. The statement 'y=1' | 2809 // Create a function for testing stepping of keyed load. The statement 'y=1' |
2839 // is there to have more than one breakable statement in the loop, TODO(315). | 2810 // is there to have more than one breakable statement in the loop, TODO(315). |
2840 v8::Local<v8::Function> foo = CompileFunction( | 2811 v8::Local<v8::Function> foo = CompileFunction( |
2841 &env, | 2812 &env, |
2842 "function foo(a) {\n" | 2813 "function foo(a) {\n" |
2843 " var x;\n" | 2814 " var x;\n" |
2844 " var len = a.length;\n" | 2815 " var len = a.length;\n" |
2845 " for (var i = 0; i < len; i++) {\n" | 2816 " for (var i = 0; i < len; i++) {\n" |
2846 " y = 1;\n" | 2817 " y = 1;\n" |
(...skipping 16 matching lines...) Expand all Loading... |
2863 | 2834 |
2864 // Set up break point and step through the function. | 2835 // Set up break point and step through the function. |
2865 SetBreakPoint(foo, 3); | 2836 SetBreakPoint(foo, 3); |
2866 step_action = StepNext; | 2837 step_action = StepNext; |
2867 break_point_hit_count = 0; | 2838 break_point_hit_count = 0; |
2868 foo->Call(env->Global(), kArgc, args); | 2839 foo->Call(env->Global(), kArgc, args); |
2869 | 2840 |
2870 // With stepping all break locations are hit. | 2841 // With stepping all break locations are hit. |
2871 CHECK_EQ(34, break_point_hit_count); | 2842 CHECK_EQ(34, break_point_hit_count); |
2872 | 2843 |
2873 v8::Debug::SetDebugEventListener(NULL); | 2844 v8::Debug::SetDebugEventListener2(NULL); |
2874 CheckDebuggerUnloaded(); | 2845 CheckDebuggerUnloaded(); |
2875 } | 2846 } |
2876 | 2847 |
2877 | 2848 |
2878 // Test of the stepping mechanism for keyed store in a loop. | 2849 // Test of the stepping mechanism for keyed store in a loop. |
2879 TEST(DebugStepKeyedStoreLoop) { | 2850 TEST(DebugStepKeyedStoreLoop) { |
2880 DebugLocalContext env; | 2851 DebugLocalContext env; |
2881 v8::HandleScope scope(env->GetIsolate()); | 2852 v8::HandleScope scope(env->GetIsolate()); |
2882 | 2853 |
2883 // Register a debug event listener which steps and counts. | 2854 // Register a debug event listener which steps and counts. |
2884 v8::Debug::SetDebugEventListener(DebugEventStep); | 2855 v8::Debug::SetDebugEventListener2(DebugEventStep); |
2885 | 2856 |
2886 // Create a function for testing stepping of keyed store. The statement 'y=1' | 2857 // Create a function for testing stepping of keyed store. The statement 'y=1' |
2887 // is there to have more than one breakable statement in the loop, TODO(315). | 2858 // is there to have more than one breakable statement in the loop, TODO(315). |
2888 v8::Local<v8::Function> foo = CompileFunction( | 2859 v8::Local<v8::Function> foo = CompileFunction( |
2889 &env, | 2860 &env, |
2890 "function foo(a) {\n" | 2861 "function foo(a) {\n" |
2891 " var len = a.length;\n" | 2862 " var len = a.length;\n" |
2892 " for (var i = 0; i < len; i++) {\n" | 2863 " for (var i = 0; i < len; i++) {\n" |
2893 " y = 1;\n" | 2864 " y = 1;\n" |
2894 " a[i] = 42;\n" | 2865 " a[i] = 42;\n" |
(...skipping 15 matching lines...) Expand all Loading... |
2910 | 2881 |
2911 // Set up break point and step through the function. | 2882 // Set up break point and step through the function. |
2912 SetBreakPoint(foo, 3); | 2883 SetBreakPoint(foo, 3); |
2913 step_action = StepNext; | 2884 step_action = StepNext; |
2914 break_point_hit_count = 0; | 2885 break_point_hit_count = 0; |
2915 foo->Call(env->Global(), kArgc, args); | 2886 foo->Call(env->Global(), kArgc, args); |
2916 | 2887 |
2917 // With stepping all break locations are hit. | 2888 // With stepping all break locations are hit. |
2918 CHECK_EQ(33, break_point_hit_count); | 2889 CHECK_EQ(33, break_point_hit_count); |
2919 | 2890 |
2920 v8::Debug::SetDebugEventListener(NULL); | 2891 v8::Debug::SetDebugEventListener2(NULL); |
2921 CheckDebuggerUnloaded(); | 2892 CheckDebuggerUnloaded(); |
2922 } | 2893 } |
2923 | 2894 |
2924 | 2895 |
2925 // Test of the stepping mechanism for named load in a loop. | 2896 // Test of the stepping mechanism for named load in a loop. |
2926 TEST(DebugStepNamedLoadLoop) { | 2897 TEST(DebugStepNamedLoadLoop) { |
2927 DebugLocalContext env; | 2898 DebugLocalContext env; |
2928 v8::HandleScope scope(env->GetIsolate()); | 2899 v8::HandleScope scope(env->GetIsolate()); |
2929 | 2900 |
2930 // Register a debug event listener which steps and counts. | 2901 // Register a debug event listener which steps and counts. |
2931 v8::Debug::SetDebugEventListener(DebugEventStep); | 2902 v8::Debug::SetDebugEventListener2(DebugEventStep); |
2932 | 2903 |
2933 // Create a function for testing stepping of named load. | 2904 // Create a function for testing stepping of named load. |
2934 v8::Local<v8::Function> foo = CompileFunction( | 2905 v8::Local<v8::Function> foo = CompileFunction( |
2935 &env, | 2906 &env, |
2936 "function foo() {\n" | 2907 "function foo() {\n" |
2937 " var a = [];\n" | 2908 " var a = [];\n" |
2938 " var s = \"\";\n" | 2909 " var s = \"\";\n" |
2939 " for (var i = 0; i < 10; i++) {\n" | 2910 " for (var i = 0; i < 10; i++) {\n" |
2940 " var v = new V(i, i + 1);\n" | 2911 " var v = new V(i, i + 1);\n" |
2941 " v.y;\n" | 2912 " v.y;\n" |
(...skipping 12 matching lines...) Expand all Loading... |
2954 | 2925 |
2955 // Set up break point and step through the function. | 2926 // Set up break point and step through the function. |
2956 SetBreakPoint(foo, 4); | 2927 SetBreakPoint(foo, 4); |
2957 step_action = StepNext; | 2928 step_action = StepNext; |
2958 break_point_hit_count = 0; | 2929 break_point_hit_count = 0; |
2959 foo->Call(env->Global(), 0, NULL); | 2930 foo->Call(env->Global(), 0, NULL); |
2960 | 2931 |
2961 // With stepping all break locations are hit. | 2932 // With stepping all break locations are hit. |
2962 CHECK_EQ(54, break_point_hit_count); | 2933 CHECK_EQ(54, break_point_hit_count); |
2963 | 2934 |
2964 v8::Debug::SetDebugEventListener(NULL); | 2935 v8::Debug::SetDebugEventListener2(NULL); |
2965 CheckDebuggerUnloaded(); | 2936 CheckDebuggerUnloaded(); |
2966 } | 2937 } |
2967 | 2938 |
2968 | 2939 |
2969 static void DoDebugStepNamedStoreLoop(int expected) { | 2940 static void DoDebugStepNamedStoreLoop(int expected) { |
2970 DebugLocalContext env; | 2941 DebugLocalContext env; |
2971 v8::HandleScope scope(env->GetIsolate()); | 2942 v8::HandleScope scope(env->GetIsolate()); |
2972 | 2943 |
2973 // Register a debug event listener which steps and counts. | 2944 // Register a debug event listener which steps and counts. |
2974 v8::Debug::SetDebugEventListener(DebugEventStep); | 2945 v8::Debug::SetDebugEventListener2(DebugEventStep); |
2975 | 2946 |
2976 // Create a function for testing stepping of named store. | 2947 // Create a function for testing stepping of named store. |
2977 v8::Local<v8::Function> foo = CompileFunction( | 2948 v8::Local<v8::Function> foo = CompileFunction( |
2978 &env, | 2949 &env, |
2979 "function foo() {\n" | 2950 "function foo() {\n" |
2980 " var a = {a:1};\n" | 2951 " var a = {a:1};\n" |
2981 " for (var i = 0; i < 10; i++) {\n" | 2952 " for (var i = 0; i < 10; i++) {\n" |
2982 " a.a = 2\n" | 2953 " a.a = 2\n" |
2983 " }\n" | 2954 " }\n" |
2984 "}\n", | 2955 "}\n", |
2985 "foo"); | 2956 "foo"); |
2986 | 2957 |
2987 // Call function without any break points to ensure inlining is in place. | 2958 // Call function without any break points to ensure inlining is in place. |
2988 foo->Call(env->Global(), 0, NULL); | 2959 foo->Call(env->Global(), 0, NULL); |
2989 | 2960 |
2990 // Set up break point and step through the function. | 2961 // Set up break point and step through the function. |
2991 SetBreakPoint(foo, 3); | 2962 SetBreakPoint(foo, 3); |
2992 step_action = StepNext; | 2963 step_action = StepNext; |
2993 break_point_hit_count = 0; | 2964 break_point_hit_count = 0; |
2994 foo->Call(env->Global(), 0, NULL); | 2965 foo->Call(env->Global(), 0, NULL); |
2995 | 2966 |
2996 // With stepping all expected break locations are hit. | 2967 // With stepping all expected break locations are hit. |
2997 CHECK_EQ(expected, break_point_hit_count); | 2968 CHECK_EQ(expected, break_point_hit_count); |
2998 | 2969 |
2999 v8::Debug::SetDebugEventListener(NULL); | 2970 v8::Debug::SetDebugEventListener2(NULL); |
3000 CheckDebuggerUnloaded(); | 2971 CheckDebuggerUnloaded(); |
3001 } | 2972 } |
3002 | 2973 |
3003 | 2974 |
3004 // Test of the stepping mechanism for named load in a loop. | 2975 // Test of the stepping mechanism for named load in a loop. |
3005 TEST(DebugStepNamedStoreLoop) { | 2976 TEST(DebugStepNamedStoreLoop) { |
3006 DoDebugStepNamedStoreLoop(23); | 2977 DoDebugStepNamedStoreLoop(23); |
3007 } | 2978 } |
3008 | 2979 |
3009 | 2980 |
3010 // Test the stepping mechanism with different ICs. | 2981 // Test the stepping mechanism with different ICs. |
3011 TEST(DebugStepLinearMixedICs) { | 2982 TEST(DebugStepLinearMixedICs) { |
3012 DebugLocalContext env; | 2983 DebugLocalContext env; |
3013 v8::HandleScope scope(env->GetIsolate()); | 2984 v8::HandleScope scope(env->GetIsolate()); |
3014 | 2985 |
3015 // Register a debug event listener which steps and counts. | 2986 // Register a debug event listener which steps and counts. |
3016 v8::Debug::SetDebugEventListener(DebugEventStep); | 2987 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3017 | 2988 |
3018 // Create a function for testing stepping. | 2989 // Create a function for testing stepping. |
3019 v8::Local<v8::Function> foo = CompileFunction(&env, | 2990 v8::Local<v8::Function> foo = CompileFunction(&env, |
3020 "function bar() {};" | 2991 "function bar() {};" |
3021 "function foo() {" | 2992 "function foo() {" |
3022 " var x;" | 2993 " var x;" |
3023 " var index='name';" | 2994 " var index='name';" |
3024 " var y = {};" | 2995 " var y = {};" |
3025 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo"); | 2996 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo"); |
3026 | 2997 |
3027 // Run functions to allow them to get optimized. | 2998 // Run functions to allow them to get optimized. |
3028 CompileRun("a=0; b=0; bar(); foo();"); | 2999 CompileRun("a=0; b=0; bar(); foo();"); |
3029 | 3000 |
3030 SetBreakPoint(foo, 0); | 3001 SetBreakPoint(foo, 0); |
3031 | 3002 |
3032 step_action = StepIn; | 3003 step_action = StepIn; |
3033 break_point_hit_count = 0; | 3004 break_point_hit_count = 0; |
3034 foo->Call(env->Global(), 0, NULL); | 3005 foo->Call(env->Global(), 0, NULL); |
3035 | 3006 |
3036 // With stepping all break locations are hit. | 3007 // With stepping all break locations are hit. |
3037 CHECK_EQ(11, break_point_hit_count); | 3008 CHECK_EQ(11, break_point_hit_count); |
3038 | 3009 |
3039 v8::Debug::SetDebugEventListener(NULL); | 3010 v8::Debug::SetDebugEventListener2(NULL); |
3040 CheckDebuggerUnloaded(); | 3011 CheckDebuggerUnloaded(); |
3041 | 3012 |
3042 // Register a debug event listener which just counts. | 3013 // Register a debug event listener which just counts. |
3043 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 3014 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
3044 | 3015 |
3045 SetBreakPoint(foo, 0); | 3016 SetBreakPoint(foo, 0); |
3046 break_point_hit_count = 0; | 3017 break_point_hit_count = 0; |
3047 foo->Call(env->Global(), 0, NULL); | 3018 foo->Call(env->Global(), 0, NULL); |
3048 | 3019 |
3049 // Without stepping only active break points are hit. | 3020 // Without stepping only active break points are hit. |
3050 CHECK_EQ(1, break_point_hit_count); | 3021 CHECK_EQ(1, break_point_hit_count); |
3051 | 3022 |
3052 v8::Debug::SetDebugEventListener(NULL); | 3023 v8::Debug::SetDebugEventListener2(NULL); |
3053 CheckDebuggerUnloaded(); | 3024 CheckDebuggerUnloaded(); |
3054 } | 3025 } |
3055 | 3026 |
3056 | 3027 |
3057 TEST(DebugStepDeclarations) { | 3028 TEST(DebugStepDeclarations) { |
3058 DebugLocalContext env; | 3029 DebugLocalContext env; |
3059 v8::HandleScope scope(env->GetIsolate()); | 3030 v8::HandleScope scope(env->GetIsolate()); |
3060 | 3031 |
3061 // Register a debug event listener which steps and counts. | 3032 // Register a debug event listener which steps and counts. |
3062 v8::Debug::SetDebugEventListener(DebugEventStep); | 3033 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3063 | 3034 |
3064 // Create a function for testing stepping. Run it to allow it to get | 3035 // Create a function for testing stepping. Run it to allow it to get |
3065 // optimized. | 3036 // optimized. |
3066 const char* src = "function foo() { " | 3037 const char* src = "function foo() { " |
3067 " var a;" | 3038 " var a;" |
3068 " var b = 1;" | 3039 " var b = 1;" |
3069 " var c = foo;" | 3040 " var c = foo;" |
3070 " var d = Math.floor;" | 3041 " var d = Math.floor;" |
3071 " var e = b + d(1.2);" | 3042 " var e = b + d(1.2);" |
3072 "}" | 3043 "}" |
3073 "foo()"; | 3044 "foo()"; |
3074 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3045 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3075 | 3046 |
3076 SetBreakPoint(foo, 0); | 3047 SetBreakPoint(foo, 0); |
3077 | 3048 |
3078 // Stepping through the declarations. | 3049 // Stepping through the declarations. |
3079 step_action = StepIn; | 3050 step_action = StepIn; |
3080 break_point_hit_count = 0; | 3051 break_point_hit_count = 0; |
3081 foo->Call(env->Global(), 0, NULL); | 3052 foo->Call(env->Global(), 0, NULL); |
3082 CHECK_EQ(6, break_point_hit_count); | 3053 CHECK_EQ(6, break_point_hit_count); |
3083 | 3054 |
3084 // Get rid of the debug event listener. | 3055 // Get rid of the debug event listener. |
3085 v8::Debug::SetDebugEventListener(NULL); | 3056 v8::Debug::SetDebugEventListener2(NULL); |
3086 CheckDebuggerUnloaded(); | 3057 CheckDebuggerUnloaded(); |
3087 } | 3058 } |
3088 | 3059 |
3089 | 3060 |
3090 TEST(DebugStepLocals) { | 3061 TEST(DebugStepLocals) { |
3091 DebugLocalContext env; | 3062 DebugLocalContext env; |
3092 v8::HandleScope scope(env->GetIsolate()); | 3063 v8::HandleScope scope(env->GetIsolate()); |
3093 | 3064 |
3094 // Register a debug event listener which steps and counts. | 3065 // Register a debug event listener which steps and counts. |
3095 v8::Debug::SetDebugEventListener(DebugEventStep); | 3066 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3096 | 3067 |
3097 // Create a function for testing stepping. Run it to allow it to get | 3068 // Create a function for testing stepping. Run it to allow it to get |
3098 // optimized. | 3069 // optimized. |
3099 const char* src = "function foo() { " | 3070 const char* src = "function foo() { " |
3100 " var a,b;" | 3071 " var a,b;" |
3101 " a = 1;" | 3072 " a = 1;" |
3102 " b = a + 2;" | 3073 " b = a + 2;" |
3103 " b = 1 + 2 + 3;" | 3074 " b = 1 + 2 + 3;" |
3104 " a = Math.floor(b);" | 3075 " a = Math.floor(b);" |
3105 "}" | 3076 "}" |
3106 "foo()"; | 3077 "foo()"; |
3107 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3078 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3108 | 3079 |
3109 SetBreakPoint(foo, 0); | 3080 SetBreakPoint(foo, 0); |
3110 | 3081 |
3111 // Stepping through the declarations. | 3082 // Stepping through the declarations. |
3112 step_action = StepIn; | 3083 step_action = StepIn; |
3113 break_point_hit_count = 0; | 3084 break_point_hit_count = 0; |
3114 foo->Call(env->Global(), 0, NULL); | 3085 foo->Call(env->Global(), 0, NULL); |
3115 CHECK_EQ(6, break_point_hit_count); | 3086 CHECK_EQ(6, break_point_hit_count); |
3116 | 3087 |
3117 // Get rid of the debug event listener. | 3088 // Get rid of the debug event listener. |
3118 v8::Debug::SetDebugEventListener(NULL); | 3089 v8::Debug::SetDebugEventListener2(NULL); |
3119 CheckDebuggerUnloaded(); | 3090 CheckDebuggerUnloaded(); |
3120 } | 3091 } |
3121 | 3092 |
3122 | 3093 |
3123 TEST(DebugStepIf) { | 3094 TEST(DebugStepIf) { |
3124 DebugLocalContext env; | 3095 DebugLocalContext env; |
3125 v8::HandleScope scope(env->GetIsolate()); | 3096 v8::HandleScope scope(env->GetIsolate()); |
3126 | 3097 |
3127 // Register a debug event listener which steps and counts. | 3098 // Register a debug event listener which steps and counts. |
3128 v8::Debug::SetDebugEventListener(DebugEventStep); | 3099 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3129 | 3100 |
3130 // Create a function for testing stepping. Run it to allow it to get | 3101 // Create a function for testing stepping. Run it to allow it to get |
3131 // optimized. | 3102 // optimized. |
3132 const int argc = 1; | 3103 const int argc = 1; |
3133 const char* src = "function foo(x) { " | 3104 const char* src = "function foo(x) { " |
3134 " a = 1;" | 3105 " a = 1;" |
3135 " if (x) {" | 3106 " if (x) {" |
3136 " b = 1;" | 3107 " b = 1;" |
3137 " } else {" | 3108 " } else {" |
3138 " c = 1;" | 3109 " c = 1;" |
(...skipping 12 matching lines...) Expand all Loading... |
3151 CHECK_EQ(4, break_point_hit_count); | 3122 CHECK_EQ(4, break_point_hit_count); |
3152 | 3123 |
3153 // Stepping through the false part. | 3124 // Stepping through the false part. |
3154 step_action = StepIn; | 3125 step_action = StepIn; |
3155 break_point_hit_count = 0; | 3126 break_point_hit_count = 0; |
3156 v8::Handle<v8::Value> argv_false[argc] = { v8::False() }; | 3127 v8::Handle<v8::Value> argv_false[argc] = { v8::False() }; |
3157 foo->Call(env->Global(), argc, argv_false); | 3128 foo->Call(env->Global(), argc, argv_false); |
3158 CHECK_EQ(5, break_point_hit_count); | 3129 CHECK_EQ(5, break_point_hit_count); |
3159 | 3130 |
3160 // Get rid of the debug event listener. | 3131 // Get rid of the debug event listener. |
3161 v8::Debug::SetDebugEventListener(NULL); | 3132 v8::Debug::SetDebugEventListener2(NULL); |
3162 CheckDebuggerUnloaded(); | 3133 CheckDebuggerUnloaded(); |
3163 } | 3134 } |
3164 | 3135 |
3165 | 3136 |
3166 TEST(DebugStepSwitch) { | 3137 TEST(DebugStepSwitch) { |
3167 DebugLocalContext env; | 3138 DebugLocalContext env; |
3168 v8::HandleScope scope(env->GetIsolate()); | 3139 v8::HandleScope scope(env->GetIsolate()); |
3169 | 3140 |
3170 // Register a debug event listener which steps and counts. | 3141 // Register a debug event listener which steps and counts. |
3171 v8::Debug::SetDebugEventListener(DebugEventStep); | 3142 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3172 | 3143 |
3173 // Create a function for testing stepping. Run it to allow it to get | 3144 // Create a function for testing stepping. Run it to allow it to get |
3174 // optimized. | 3145 // optimized. |
3175 const int argc = 1; | 3146 const int argc = 1; |
3176 const char* src = "function foo(x) { " | 3147 const char* src = "function foo(x) { " |
3177 " a = 1;" | 3148 " a = 1;" |
3178 " switch (x) {" | 3149 " switch (x) {" |
3179 " case 1:" | 3150 " case 1:" |
3180 " b = 1;" | 3151 " b = 1;" |
3181 " case 2:" | 3152 " case 2:" |
(...skipping 25 matching lines...) Expand all Loading... |
3207 CHECK_EQ(5, break_point_hit_count); | 3178 CHECK_EQ(5, break_point_hit_count); |
3208 | 3179 |
3209 // Last case. | 3180 // Last case. |
3210 step_action = StepIn; | 3181 step_action = StepIn; |
3211 break_point_hit_count = 0; | 3182 break_point_hit_count = 0; |
3212 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) }; | 3183 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) }; |
3213 foo->Call(env->Global(), argc, argv_3); | 3184 foo->Call(env->Global(), argc, argv_3); |
3214 CHECK_EQ(7, break_point_hit_count); | 3185 CHECK_EQ(7, break_point_hit_count); |
3215 | 3186 |
3216 // Get rid of the debug event listener. | 3187 // Get rid of the debug event listener. |
3217 v8::Debug::SetDebugEventListener(NULL); | 3188 v8::Debug::SetDebugEventListener2(NULL); |
3218 CheckDebuggerUnloaded(); | 3189 CheckDebuggerUnloaded(); |
3219 } | 3190 } |
3220 | 3191 |
3221 | 3192 |
3222 TEST(DebugStepWhile) { | 3193 TEST(DebugStepWhile) { |
3223 DebugLocalContext env; | 3194 DebugLocalContext env; |
3224 v8::HandleScope scope(env->GetIsolate()); | 3195 v8::HandleScope scope(env->GetIsolate()); |
3225 | 3196 |
3226 // Register a debug event listener which steps and counts. | 3197 // Register a debug event listener which steps and counts. |
3227 v8::Debug::SetDebugEventListener(DebugEventStep); | 3198 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3228 | 3199 |
3229 // Create a function for testing stepping. Run it to allow it to get | 3200 // Create a function for testing stepping. Run it to allow it to get |
3230 // optimized. | 3201 // optimized. |
3231 const int argc = 1; | 3202 const int argc = 1; |
3232 const char* src = "function foo(x) { " | 3203 const char* src = "function foo(x) { " |
3233 " var a = 0;" | 3204 " var a = 0;" |
3234 " while (a < x) {" | 3205 " while (a < x) {" |
3235 " a++;" | 3206 " a++;" |
3236 " }" | 3207 " }" |
3237 "}" | 3208 "}" |
3238 "foo()"; | 3209 "foo()"; |
3239 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3210 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3240 SetBreakPoint(foo, 8); // "var a = 0;" | 3211 SetBreakPoint(foo, 8); // "var a = 0;" |
3241 | 3212 |
3242 // Looping 10 times. | 3213 // Looping 10 times. |
3243 step_action = StepIn; | 3214 step_action = StepIn; |
3244 break_point_hit_count = 0; | 3215 break_point_hit_count = 0; |
3245 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; | 3216 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; |
3246 foo->Call(env->Global(), argc, argv_10); | 3217 foo->Call(env->Global(), argc, argv_10); |
3247 CHECK_EQ(22, break_point_hit_count); | 3218 CHECK_EQ(22, break_point_hit_count); |
3248 | 3219 |
3249 // Looping 100 times. | 3220 // Looping 100 times. |
3250 step_action = StepIn; | 3221 step_action = StepIn; |
3251 break_point_hit_count = 0; | 3222 break_point_hit_count = 0; |
3252 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 3223 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
3253 foo->Call(env->Global(), argc, argv_100); | 3224 foo->Call(env->Global(), argc, argv_100); |
3254 CHECK_EQ(202, break_point_hit_count); | 3225 CHECK_EQ(202, break_point_hit_count); |
3255 | 3226 |
3256 // Get rid of the debug event listener. | 3227 // Get rid of the debug event listener. |
3257 v8::Debug::SetDebugEventListener(NULL); | 3228 v8::Debug::SetDebugEventListener2(NULL); |
3258 CheckDebuggerUnloaded(); | 3229 CheckDebuggerUnloaded(); |
3259 } | 3230 } |
3260 | 3231 |
3261 | 3232 |
3262 TEST(DebugStepDoWhile) { | 3233 TEST(DebugStepDoWhile) { |
3263 DebugLocalContext env; | 3234 DebugLocalContext env; |
3264 v8::HandleScope scope(env->GetIsolate()); | 3235 v8::HandleScope scope(env->GetIsolate()); |
3265 | 3236 |
3266 // Register a debug event listener which steps and counts. | 3237 // Register a debug event listener which steps and counts. |
3267 v8::Debug::SetDebugEventListener(DebugEventStep); | 3238 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3268 | 3239 |
3269 // Create a function for testing stepping. Run it to allow it to get | 3240 // Create a function for testing stepping. Run it to allow it to get |
3270 // optimized. | 3241 // optimized. |
3271 const int argc = 1; | 3242 const int argc = 1; |
3272 const char* src = "function foo(x) { " | 3243 const char* src = "function foo(x) { " |
3273 " var a = 0;" | 3244 " var a = 0;" |
3274 " do {" | 3245 " do {" |
3275 " a++;" | 3246 " a++;" |
3276 " } while (a < x)" | 3247 " } while (a < x)" |
3277 "}" | 3248 "}" |
3278 "foo()"; | 3249 "foo()"; |
3279 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3250 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3280 SetBreakPoint(foo, 8); // "var a = 0;" | 3251 SetBreakPoint(foo, 8); // "var a = 0;" |
3281 | 3252 |
3282 // Looping 10 times. | 3253 // Looping 10 times. |
3283 step_action = StepIn; | 3254 step_action = StepIn; |
3284 break_point_hit_count = 0; | 3255 break_point_hit_count = 0; |
3285 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; | 3256 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; |
3286 foo->Call(env->Global(), argc, argv_10); | 3257 foo->Call(env->Global(), argc, argv_10); |
3287 CHECK_EQ(22, break_point_hit_count); | 3258 CHECK_EQ(22, break_point_hit_count); |
3288 | 3259 |
3289 // Looping 100 times. | 3260 // Looping 100 times. |
3290 step_action = StepIn; | 3261 step_action = StepIn; |
3291 break_point_hit_count = 0; | 3262 break_point_hit_count = 0; |
3292 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 3263 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
3293 foo->Call(env->Global(), argc, argv_100); | 3264 foo->Call(env->Global(), argc, argv_100); |
3294 CHECK_EQ(202, break_point_hit_count); | 3265 CHECK_EQ(202, break_point_hit_count); |
3295 | 3266 |
3296 // Get rid of the debug event listener. | 3267 // Get rid of the debug event listener. |
3297 v8::Debug::SetDebugEventListener(NULL); | 3268 v8::Debug::SetDebugEventListener2(NULL); |
3298 CheckDebuggerUnloaded(); | 3269 CheckDebuggerUnloaded(); |
3299 } | 3270 } |
3300 | 3271 |
3301 | 3272 |
3302 TEST(DebugStepFor) { | 3273 TEST(DebugStepFor) { |
3303 DebugLocalContext env; | 3274 DebugLocalContext env; |
3304 v8::HandleScope scope(env->GetIsolate()); | 3275 v8::HandleScope scope(env->GetIsolate()); |
3305 | 3276 |
3306 // Register a debug event listener which steps and counts. | 3277 // Register a debug event listener which steps and counts. |
3307 v8::Debug::SetDebugEventListener(DebugEventStep); | 3278 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3308 | 3279 |
3309 // Create a function for testing stepping. Run it to allow it to get | 3280 // Create a function for testing stepping. Run it to allow it to get |
3310 // optimized. | 3281 // optimized. |
3311 const int argc = 1; | 3282 const int argc = 1; |
3312 const char* src = "function foo(x) { " | 3283 const char* src = "function foo(x) { " |
3313 " a = 1;" | 3284 " a = 1;" |
3314 " for (i = 0; i < x; i++) {" | 3285 " for (i = 0; i < x; i++) {" |
3315 " b = 1;" | 3286 " b = 1;" |
3316 " }" | 3287 " }" |
3317 "}" | 3288 "}" |
(...skipping 10 matching lines...) Expand all Loading... |
3328 CHECK_EQ(23, break_point_hit_count); | 3299 CHECK_EQ(23, break_point_hit_count); |
3329 | 3300 |
3330 // Looping 100 times. | 3301 // Looping 100 times. |
3331 step_action = StepIn; | 3302 step_action = StepIn; |
3332 break_point_hit_count = 0; | 3303 break_point_hit_count = 0; |
3333 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 3304 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
3334 foo->Call(env->Global(), argc, argv_100); | 3305 foo->Call(env->Global(), argc, argv_100); |
3335 CHECK_EQ(203, break_point_hit_count); | 3306 CHECK_EQ(203, break_point_hit_count); |
3336 | 3307 |
3337 // Get rid of the debug event listener. | 3308 // Get rid of the debug event listener. |
3338 v8::Debug::SetDebugEventListener(NULL); | 3309 v8::Debug::SetDebugEventListener2(NULL); |
3339 CheckDebuggerUnloaded(); | 3310 CheckDebuggerUnloaded(); |
3340 } | 3311 } |
3341 | 3312 |
3342 | 3313 |
3343 TEST(DebugStepForContinue) { | 3314 TEST(DebugStepForContinue) { |
3344 DebugLocalContext env; | 3315 DebugLocalContext env; |
3345 v8::HandleScope scope(env->GetIsolate()); | 3316 v8::HandleScope scope(env->GetIsolate()); |
3346 | 3317 |
3347 // Register a debug event listener which steps and counts. | 3318 // Register a debug event listener which steps and counts. |
3348 v8::Debug::SetDebugEventListener(DebugEventStep); | 3319 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3349 | 3320 |
3350 // Create a function for testing stepping. Run it to allow it to get | 3321 // Create a function for testing stepping. Run it to allow it to get |
3351 // optimized. | 3322 // optimized. |
3352 const int argc = 1; | 3323 const int argc = 1; |
3353 const char* src = "function foo(x) { " | 3324 const char* src = "function foo(x) { " |
3354 " var a = 0;" | 3325 " var a = 0;" |
3355 " var b = 0;" | 3326 " var b = 0;" |
3356 " var c = 0;" | 3327 " var c = 0;" |
3357 " for (var i = 0; i < x; i++) {" | 3328 " for (var i = 0; i < x; i++) {" |
3358 " a++;" | 3329 " a++;" |
(...skipping 20 matching lines...) Expand all Loading... |
3379 | 3350 |
3380 // Looping 100 times. | 3351 // Looping 100 times. |
3381 step_action = StepIn; | 3352 step_action = StepIn; |
3382 break_point_hit_count = 0; | 3353 break_point_hit_count = 0; |
3383 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 3354 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
3384 result = foo->Call(env->Global(), argc, argv_100); | 3355 result = foo->Call(env->Global(), argc, argv_100); |
3385 CHECK_EQ(50, result->Int32Value()); | 3356 CHECK_EQ(50, result->Int32Value()); |
3386 CHECK_EQ(456, break_point_hit_count); | 3357 CHECK_EQ(456, break_point_hit_count); |
3387 | 3358 |
3388 // Get rid of the debug event listener. | 3359 // Get rid of the debug event listener. |
3389 v8::Debug::SetDebugEventListener(NULL); | 3360 v8::Debug::SetDebugEventListener2(NULL); |
3390 CheckDebuggerUnloaded(); | 3361 CheckDebuggerUnloaded(); |
3391 } | 3362 } |
3392 | 3363 |
3393 | 3364 |
3394 TEST(DebugStepForBreak) { | 3365 TEST(DebugStepForBreak) { |
3395 DebugLocalContext env; | 3366 DebugLocalContext env; |
3396 v8::HandleScope scope(env->GetIsolate()); | 3367 v8::HandleScope scope(env->GetIsolate()); |
3397 | 3368 |
3398 // Register a debug event listener which steps and counts. | 3369 // Register a debug event listener which steps and counts. |
3399 v8::Debug::SetDebugEventListener(DebugEventStep); | 3370 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3400 | 3371 |
3401 // Create a function for testing stepping. Run it to allow it to get | 3372 // Create a function for testing stepping. Run it to allow it to get |
3402 // optimized. | 3373 // optimized. |
3403 const int argc = 1; | 3374 const int argc = 1; |
3404 const char* src = "function foo(x) { " | 3375 const char* src = "function foo(x) { " |
3405 " var a = 0;" | 3376 " var a = 0;" |
3406 " var b = 0;" | 3377 " var b = 0;" |
3407 " var c = 0;" | 3378 " var c = 0;" |
3408 " for (var i = 0; i < 1000; i++) {" | 3379 " for (var i = 0; i < 1000; i++) {" |
3409 " a++;" | 3380 " a++;" |
(...skipping 21 matching lines...) Expand all Loading... |
3431 | 3402 |
3432 // Looping 100 times. | 3403 // Looping 100 times. |
3433 step_action = StepIn; | 3404 step_action = StepIn; |
3434 break_point_hit_count = 0; | 3405 break_point_hit_count = 0; |
3435 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 3406 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
3436 result = foo->Call(env->Global(), argc, argv_100); | 3407 result = foo->Call(env->Global(), argc, argv_100); |
3437 CHECK_EQ(99, result->Int32Value()); | 3408 CHECK_EQ(99, result->Int32Value()); |
3438 CHECK_EQ(504, break_point_hit_count); | 3409 CHECK_EQ(504, break_point_hit_count); |
3439 | 3410 |
3440 // Get rid of the debug event listener. | 3411 // Get rid of the debug event listener. |
3441 v8::Debug::SetDebugEventListener(NULL); | 3412 v8::Debug::SetDebugEventListener2(NULL); |
3442 CheckDebuggerUnloaded(); | 3413 CheckDebuggerUnloaded(); |
3443 } | 3414 } |
3444 | 3415 |
3445 | 3416 |
3446 TEST(DebugStepForIn) { | 3417 TEST(DebugStepForIn) { |
3447 DebugLocalContext env; | 3418 DebugLocalContext env; |
3448 v8::HandleScope scope(env->GetIsolate()); | 3419 v8::HandleScope scope(env->GetIsolate()); |
3449 | 3420 |
3450 // Register a debug event listener which steps and counts. | 3421 // Register a debug event listener which steps and counts. |
3451 v8::Debug::SetDebugEventListener(DebugEventStep); | 3422 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3452 | 3423 |
3453 // Create a function for testing stepping. Run it to allow it to get | 3424 // Create a function for testing stepping. Run it to allow it to get |
3454 // optimized. | 3425 // optimized. |
3455 v8::Local<v8::Function> foo; | 3426 v8::Local<v8::Function> foo; |
3456 const char* src_1 = "function foo() { " | 3427 const char* src_1 = "function foo() { " |
3457 " var a = [1, 2];" | 3428 " var a = [1, 2];" |
3458 " for (x in a) {" | 3429 " for (x in a) {" |
3459 " b = 0;" | 3430 " b = 0;" |
3460 " }" | 3431 " }" |
3461 "}" | 3432 "}" |
(...skipping 17 matching lines...) Expand all Loading... |
3479 "foo()"; | 3450 "foo()"; |
3480 foo = CompileFunction(&env, src_2, "foo"); | 3451 foo = CompileFunction(&env, src_2, "foo"); |
3481 SetBreakPoint(foo, 0); // "var a = ..." | 3452 SetBreakPoint(foo, 0); // "var a = ..." |
3482 | 3453 |
3483 step_action = StepIn; | 3454 step_action = StepIn; |
3484 break_point_hit_count = 0; | 3455 break_point_hit_count = 0; |
3485 foo->Call(env->Global(), 0, NULL); | 3456 foo->Call(env->Global(), 0, NULL); |
3486 CHECK_EQ(8, break_point_hit_count); | 3457 CHECK_EQ(8, break_point_hit_count); |
3487 | 3458 |
3488 // Get rid of the debug event listener. | 3459 // Get rid of the debug event listener. |
3489 v8::Debug::SetDebugEventListener(NULL); | 3460 v8::Debug::SetDebugEventListener2(NULL); |
3490 CheckDebuggerUnloaded(); | 3461 CheckDebuggerUnloaded(); |
3491 } | 3462 } |
3492 | 3463 |
3493 | 3464 |
3494 TEST(DebugStepWith) { | 3465 TEST(DebugStepWith) { |
3495 DebugLocalContext env; | 3466 DebugLocalContext env; |
3496 v8::HandleScope scope(env->GetIsolate()); | 3467 v8::HandleScope scope(env->GetIsolate()); |
3497 | 3468 |
3498 // Register a debug event listener which steps and counts. | 3469 // Register a debug event listener which steps and counts. |
3499 v8::Debug::SetDebugEventListener(DebugEventStep); | 3470 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3500 | 3471 |
3501 // Create a function for testing stepping. Run it to allow it to get | 3472 // Create a function for testing stepping. Run it to allow it to get |
3502 // optimized. | 3473 // optimized. |
3503 const char* src = "function foo(x) { " | 3474 const char* src = "function foo(x) { " |
3504 " var a = {};" | 3475 " var a = {};" |
3505 " with (a) {}" | 3476 " with (a) {}" |
3506 " with (b) {}" | 3477 " with (b) {}" |
3507 "}" | 3478 "}" |
3508 "foo()"; | 3479 "foo()"; |
3509 env->Global()->Set(v8::String::New("b"), v8::Object::New()); | 3480 env->Global()->Set(v8::String::New("b"), v8::Object::New()); |
3510 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3481 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3511 v8::Handle<v8::Value> result; | 3482 v8::Handle<v8::Value> result; |
3512 SetBreakPoint(foo, 8); // "var a = {};" | 3483 SetBreakPoint(foo, 8); // "var a = {};" |
3513 | 3484 |
3514 step_action = StepIn; | 3485 step_action = StepIn; |
3515 break_point_hit_count = 0; | 3486 break_point_hit_count = 0; |
3516 foo->Call(env->Global(), 0, NULL); | 3487 foo->Call(env->Global(), 0, NULL); |
3517 CHECK_EQ(4, break_point_hit_count); | 3488 CHECK_EQ(4, break_point_hit_count); |
3518 | 3489 |
3519 // Get rid of the debug event listener. | 3490 // Get rid of the debug event listener. |
3520 v8::Debug::SetDebugEventListener(NULL); | 3491 v8::Debug::SetDebugEventListener2(NULL); |
3521 CheckDebuggerUnloaded(); | 3492 CheckDebuggerUnloaded(); |
3522 } | 3493 } |
3523 | 3494 |
3524 | 3495 |
3525 TEST(DebugConditional) { | 3496 TEST(DebugConditional) { |
3526 DebugLocalContext env; | 3497 DebugLocalContext env; |
3527 v8::HandleScope scope(env->GetIsolate()); | 3498 v8::HandleScope scope(env->GetIsolate()); |
3528 | 3499 |
3529 // Register a debug event listener which steps and counts. | 3500 // Register a debug event listener which steps and counts. |
3530 v8::Debug::SetDebugEventListener(DebugEventStep); | 3501 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3531 | 3502 |
3532 // Create a function for testing stepping. Run it to allow it to get | 3503 // Create a function for testing stepping. Run it to allow it to get |
3533 // optimized. | 3504 // optimized. |
3534 const char* src = "function foo(x) { " | 3505 const char* src = "function foo(x) { " |
3535 " var a;" | 3506 " var a;" |
3536 " a = x ? 1 : 2;" | 3507 " a = x ? 1 : 2;" |
3537 " return a;" | 3508 " return a;" |
3538 "}" | 3509 "}" |
3539 "foo()"; | 3510 "foo()"; |
3540 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3511 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3541 SetBreakPoint(foo, 0); // "var a;" | 3512 SetBreakPoint(foo, 0); // "var a;" |
3542 | 3513 |
3543 step_action = StepIn; | 3514 step_action = StepIn; |
3544 break_point_hit_count = 0; | 3515 break_point_hit_count = 0; |
3545 foo->Call(env->Global(), 0, NULL); | 3516 foo->Call(env->Global(), 0, NULL); |
3546 CHECK_EQ(5, break_point_hit_count); | 3517 CHECK_EQ(5, break_point_hit_count); |
3547 | 3518 |
3548 step_action = StepIn; | 3519 step_action = StepIn; |
3549 break_point_hit_count = 0; | 3520 break_point_hit_count = 0; |
3550 const int argc = 1; | 3521 const int argc = 1; |
3551 v8::Handle<v8::Value> argv_true[argc] = { v8::True() }; | 3522 v8::Handle<v8::Value> argv_true[argc] = { v8::True() }; |
3552 foo->Call(env->Global(), argc, argv_true); | 3523 foo->Call(env->Global(), argc, argv_true); |
3553 CHECK_EQ(5, break_point_hit_count); | 3524 CHECK_EQ(5, break_point_hit_count); |
3554 | 3525 |
3555 // Get rid of the debug event listener. | 3526 // Get rid of the debug event listener. |
3556 v8::Debug::SetDebugEventListener(NULL); | 3527 v8::Debug::SetDebugEventListener2(NULL); |
3557 CheckDebuggerUnloaded(); | 3528 CheckDebuggerUnloaded(); |
3558 } | 3529 } |
3559 | 3530 |
3560 | 3531 |
3561 TEST(StepInOutSimple) { | 3532 TEST(StepInOutSimple) { |
3562 DebugLocalContext env; | 3533 DebugLocalContext env; |
3563 v8::HandleScope scope(env->GetIsolate()); | 3534 v8::HandleScope scope(env->GetIsolate()); |
3564 | 3535 |
3565 // Create a function for checking the function when hitting a break point. | 3536 // Create a function for checking the function when hitting a break point. |
3566 frame_function_name = CompileFunction(&env, | 3537 frame_function_name = CompileFunction(&env, |
3567 frame_function_name_source, | 3538 frame_function_name_source, |
3568 "frame_function_name"); | 3539 "frame_function_name"); |
3569 | 3540 |
3570 // Register a debug event listener which steps and counts. | 3541 // Register a debug event listener which steps and counts. |
3571 v8::Debug::SetDebugEventListener(DebugEventStepSequence); | 3542 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); |
3572 | 3543 |
3573 // Create a function for testing stepping. Run it to allow it to get | 3544 // Create a function for testing stepping. Run it to allow it to get |
3574 // optimized. | 3545 // optimized. |
3575 const char* src = "function a() {b();c();}; " | 3546 const char* src = "function a() {b();c();}; " |
3576 "function b() {c();}; " | 3547 "function b() {c();}; " |
3577 "function c() {}; " | 3548 "function c() {}; " |
3578 "a(); b(); c()"; | 3549 "a(); b(); c()"; |
3579 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3550 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3580 SetBreakPoint(a, 0); | 3551 SetBreakPoint(a, 0); |
3581 | 3552 |
(...skipping 15 matching lines...) Expand all Loading... |
3597 | 3568 |
3598 // Step through invocation of a with step out. | 3569 // Step through invocation of a with step out. |
3599 step_action = StepOut; | 3570 step_action = StepOut; |
3600 break_point_hit_count = 0; | 3571 break_point_hit_count = 0; |
3601 expected_step_sequence = "a"; | 3572 expected_step_sequence = "a"; |
3602 a->Call(env->Global(), 0, NULL); | 3573 a->Call(env->Global(), 0, NULL); |
3603 CHECK_EQ(StrLength(expected_step_sequence), | 3574 CHECK_EQ(StrLength(expected_step_sequence), |
3604 break_point_hit_count); | 3575 break_point_hit_count); |
3605 | 3576 |
3606 // Get rid of the debug event listener. | 3577 // Get rid of the debug event listener. |
3607 v8::Debug::SetDebugEventListener(NULL); | 3578 v8::Debug::SetDebugEventListener2(NULL); |
3608 CheckDebuggerUnloaded(); | 3579 CheckDebuggerUnloaded(); |
3609 } | 3580 } |
3610 | 3581 |
3611 | 3582 |
3612 TEST(StepInOutTree) { | 3583 TEST(StepInOutTree) { |
3613 DebugLocalContext env; | 3584 DebugLocalContext env; |
3614 v8::HandleScope scope(env->GetIsolate()); | 3585 v8::HandleScope scope(env->GetIsolate()); |
3615 | 3586 |
3616 // Create a function for checking the function when hitting a break point. | 3587 // Create a function for checking the function when hitting a break point. |
3617 frame_function_name = CompileFunction(&env, | 3588 frame_function_name = CompileFunction(&env, |
3618 frame_function_name_source, | 3589 frame_function_name_source, |
3619 "frame_function_name"); | 3590 "frame_function_name"); |
3620 | 3591 |
3621 // Register a debug event listener which steps and counts. | 3592 // Register a debug event listener which steps and counts. |
3622 v8::Debug::SetDebugEventListener(DebugEventStepSequence); | 3593 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); |
3623 | 3594 |
3624 // Create a function for testing stepping. Run it to allow it to get | 3595 // Create a function for testing stepping. Run it to allow it to get |
3625 // optimized. | 3596 // optimized. |
3626 const char* src = "function a() {b(c(d()),d());c(d());d()}; " | 3597 const char* src = "function a() {b(c(d()),d());c(d());d()}; " |
3627 "function b(x,y) {c();}; " | 3598 "function b(x,y) {c();}; " |
3628 "function c(x) {}; " | 3599 "function c(x) {}; " |
3629 "function d() {}; " | 3600 "function d() {}; " |
3630 "a(); b(); c(); d()"; | 3601 "a(); b(); c(); d()"; |
3631 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3602 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3632 SetBreakPoint(a, 0); | 3603 SetBreakPoint(a, 0); |
(...skipping 16 matching lines...) Expand all Loading... |
3649 | 3620 |
3650 // Step through invocation of a with step out. | 3621 // Step through invocation of a with step out. |
3651 step_action = StepOut; | 3622 step_action = StepOut; |
3652 break_point_hit_count = 0; | 3623 break_point_hit_count = 0; |
3653 expected_step_sequence = "a"; | 3624 expected_step_sequence = "a"; |
3654 a->Call(env->Global(), 0, NULL); | 3625 a->Call(env->Global(), 0, NULL); |
3655 CHECK_EQ(StrLength(expected_step_sequence), | 3626 CHECK_EQ(StrLength(expected_step_sequence), |
3656 break_point_hit_count); | 3627 break_point_hit_count); |
3657 | 3628 |
3658 // Get rid of the debug event listener. | 3629 // Get rid of the debug event listener. |
3659 v8::Debug::SetDebugEventListener(NULL); | 3630 v8::Debug::SetDebugEventListener2(NULL); |
3660 CheckDebuggerUnloaded(true); | 3631 CheckDebuggerUnloaded(true); |
3661 } | 3632 } |
3662 | 3633 |
3663 | 3634 |
3664 TEST(StepInOutBranch) { | 3635 TEST(StepInOutBranch) { |
3665 DebugLocalContext env; | 3636 DebugLocalContext env; |
3666 v8::HandleScope scope(env->GetIsolate()); | 3637 v8::HandleScope scope(env->GetIsolate()); |
3667 | 3638 |
3668 // Create a function for checking the function when hitting a break point. | 3639 // Create a function for checking the function when hitting a break point. |
3669 frame_function_name = CompileFunction(&env, | 3640 frame_function_name = CompileFunction(&env, |
3670 frame_function_name_source, | 3641 frame_function_name_source, |
3671 "frame_function_name"); | 3642 "frame_function_name"); |
3672 | 3643 |
3673 // Register a debug event listener which steps and counts. | 3644 // Register a debug event listener which steps and counts. |
3674 v8::Debug::SetDebugEventListener(DebugEventStepSequence); | 3645 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); |
3675 | 3646 |
3676 // Create a function for testing stepping. Run it to allow it to get | 3647 // Create a function for testing stepping. Run it to allow it to get |
3677 // optimized. | 3648 // optimized. |
3678 const char* src = "function a() {b(false);c();}; " | 3649 const char* src = "function a() {b(false);c();}; " |
3679 "function b(x) {if(x){c();};}; " | 3650 "function b(x) {if(x){c();};}; " |
3680 "function c() {}; " | 3651 "function c() {}; " |
3681 "a(); b(); c()"; | 3652 "a(); b(); c()"; |
3682 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3653 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3683 SetBreakPoint(a, 0); | 3654 SetBreakPoint(a, 0); |
3684 | 3655 |
3685 // Step through invocation of a. | 3656 // Step through invocation of a. |
3686 step_action = StepIn; | 3657 step_action = StepIn; |
3687 break_point_hit_count = 0; | 3658 break_point_hit_count = 0; |
3688 expected_step_sequence = "abbaca"; | 3659 expected_step_sequence = "abbaca"; |
3689 a->Call(env->Global(), 0, NULL); | 3660 a->Call(env->Global(), 0, NULL); |
3690 CHECK_EQ(StrLength(expected_step_sequence), | 3661 CHECK_EQ(StrLength(expected_step_sequence), |
3691 break_point_hit_count); | 3662 break_point_hit_count); |
3692 | 3663 |
3693 // Get rid of the debug event listener. | 3664 // Get rid of the debug event listener. |
3694 v8::Debug::SetDebugEventListener(NULL); | 3665 v8::Debug::SetDebugEventListener2(NULL); |
3695 CheckDebuggerUnloaded(); | 3666 CheckDebuggerUnloaded(); |
3696 } | 3667 } |
3697 | 3668 |
3698 | 3669 |
3699 // Test that step in does not step into native functions. | 3670 // Test that step in does not step into native functions. |
3700 TEST(DebugStepNatives) { | 3671 TEST(DebugStepNatives) { |
3701 DebugLocalContext env; | 3672 DebugLocalContext env; |
3702 v8::HandleScope scope(env->GetIsolate()); | 3673 v8::HandleScope scope(env->GetIsolate()); |
3703 | 3674 |
3704 // Create a function for testing stepping. | 3675 // Create a function for testing stepping. |
3705 v8::Local<v8::Function> foo = CompileFunction( | 3676 v8::Local<v8::Function> foo = CompileFunction( |
3706 &env, | 3677 &env, |
3707 "function foo(){debugger;Math.sin(1);}", | 3678 "function foo(){debugger;Math.sin(1);}", |
3708 "foo"); | 3679 "foo"); |
3709 | 3680 |
3710 // Register a debug event listener which steps and counts. | 3681 // Register a debug event listener which steps and counts. |
3711 v8::Debug::SetDebugEventListener(DebugEventStep); | 3682 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3712 | 3683 |
3713 step_action = StepIn; | 3684 step_action = StepIn; |
3714 break_point_hit_count = 0; | 3685 break_point_hit_count = 0; |
3715 foo->Call(env->Global(), 0, NULL); | 3686 foo->Call(env->Global(), 0, NULL); |
3716 | 3687 |
3717 // With stepping all break locations are hit. | 3688 // With stepping all break locations are hit. |
3718 CHECK_EQ(3, break_point_hit_count); | 3689 CHECK_EQ(3, break_point_hit_count); |
3719 | 3690 |
3720 v8::Debug::SetDebugEventListener(NULL); | 3691 v8::Debug::SetDebugEventListener2(NULL); |
3721 CheckDebuggerUnloaded(); | 3692 CheckDebuggerUnloaded(); |
3722 | 3693 |
3723 // Register a debug event listener which just counts. | 3694 // Register a debug event listener which just counts. |
3724 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 3695 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
3725 | 3696 |
3726 break_point_hit_count = 0; | 3697 break_point_hit_count = 0; |
3727 foo->Call(env->Global(), 0, NULL); | 3698 foo->Call(env->Global(), 0, NULL); |
3728 | 3699 |
3729 // Without stepping only active break points are hit. | 3700 // Without stepping only active break points are hit. |
3730 CHECK_EQ(1, break_point_hit_count); | 3701 CHECK_EQ(1, break_point_hit_count); |
3731 | 3702 |
3732 v8::Debug::SetDebugEventListener(NULL); | 3703 v8::Debug::SetDebugEventListener2(NULL); |
3733 CheckDebuggerUnloaded(); | 3704 CheckDebuggerUnloaded(); |
3734 } | 3705 } |
3735 | 3706 |
3736 | 3707 |
3737 // Test that step in works with function.apply. | 3708 // Test that step in works with function.apply. |
3738 TEST(DebugStepFunctionApply) { | 3709 TEST(DebugStepFunctionApply) { |
3739 DebugLocalContext env; | 3710 DebugLocalContext env; |
3740 v8::HandleScope scope(env->GetIsolate()); | 3711 v8::HandleScope scope(env->GetIsolate()); |
3741 | 3712 |
3742 // Create a function for testing stepping. | 3713 // Create a function for testing stepping. |
3743 v8::Local<v8::Function> foo = CompileFunction( | 3714 v8::Local<v8::Function> foo = CompileFunction( |
3744 &env, | 3715 &env, |
3745 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" | 3716 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" |
3746 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", | 3717 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", |
3747 "foo"); | 3718 "foo"); |
3748 | 3719 |
3749 // Register a debug event listener which steps and counts. | 3720 // Register a debug event listener which steps and counts. |
3750 v8::Debug::SetDebugEventListener(DebugEventStep); | 3721 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3751 | 3722 |
3752 step_action = StepIn; | 3723 step_action = StepIn; |
3753 break_point_hit_count = 0; | 3724 break_point_hit_count = 0; |
3754 foo->Call(env->Global(), 0, NULL); | 3725 foo->Call(env->Global(), 0, NULL); |
3755 | 3726 |
3756 // With stepping all break locations are hit. | 3727 // With stepping all break locations are hit. |
3757 CHECK_EQ(7, break_point_hit_count); | 3728 CHECK_EQ(7, break_point_hit_count); |
3758 | 3729 |
3759 v8::Debug::SetDebugEventListener(NULL); | 3730 v8::Debug::SetDebugEventListener2(NULL); |
3760 CheckDebuggerUnloaded(); | 3731 CheckDebuggerUnloaded(); |
3761 | 3732 |
3762 // Register a debug event listener which just counts. | 3733 // Register a debug event listener which just counts. |
3763 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 3734 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
3764 | 3735 |
3765 break_point_hit_count = 0; | 3736 break_point_hit_count = 0; |
3766 foo->Call(env->Global(), 0, NULL); | 3737 foo->Call(env->Global(), 0, NULL); |
3767 | 3738 |
3768 // Without stepping only the debugger statement is hit. | 3739 // Without stepping only the debugger statement is hit. |
3769 CHECK_EQ(1, break_point_hit_count); | 3740 CHECK_EQ(1, break_point_hit_count); |
3770 | 3741 |
3771 v8::Debug::SetDebugEventListener(NULL); | 3742 v8::Debug::SetDebugEventListener2(NULL); |
3772 CheckDebuggerUnloaded(); | 3743 CheckDebuggerUnloaded(); |
3773 } | 3744 } |
3774 | 3745 |
3775 | 3746 |
3776 // Test that step in works with function.call. | 3747 // Test that step in works with function.call. |
3777 TEST(DebugStepFunctionCall) { | 3748 TEST(DebugStepFunctionCall) { |
3778 DebugLocalContext env; | 3749 DebugLocalContext env; |
3779 v8::HandleScope scope(env->GetIsolate()); | 3750 v8::HandleScope scope(env->GetIsolate()); |
3780 | 3751 |
3781 // Create a function for testing stepping. | 3752 // Create a function for testing stepping. |
3782 v8::Local<v8::Function> foo = CompileFunction( | 3753 v8::Local<v8::Function> foo = CompileFunction( |
3783 &env, | 3754 &env, |
3784 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" | 3755 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" |
3785 "function foo(a){ debugger;" | 3756 "function foo(a){ debugger;" |
3786 " if (a) {" | 3757 " if (a) {" |
3787 " bar.call(this, 1, 2, 3);" | 3758 " bar.call(this, 1, 2, 3);" |
3788 " } else {" | 3759 " } else {" |
3789 " bar.call(this, 0);" | 3760 " bar.call(this, 0);" |
3790 " }" | 3761 " }" |
3791 "}", | 3762 "}", |
3792 "foo"); | 3763 "foo"); |
3793 | 3764 |
3794 // Register a debug event listener which steps and counts. | 3765 // Register a debug event listener which steps and counts. |
3795 v8::Debug::SetDebugEventListener(DebugEventStep); | 3766 v8::Debug::SetDebugEventListener2(DebugEventStep); |
3796 step_action = StepIn; | 3767 step_action = StepIn; |
3797 | 3768 |
3798 // Check stepping where the if condition in bar is false. | 3769 // Check stepping where the if condition in bar is false. |
3799 break_point_hit_count = 0; | 3770 break_point_hit_count = 0; |
3800 foo->Call(env->Global(), 0, NULL); | 3771 foo->Call(env->Global(), 0, NULL); |
3801 CHECK_EQ(6, break_point_hit_count); | 3772 CHECK_EQ(6, break_point_hit_count); |
3802 | 3773 |
3803 // Check stepping where the if condition in bar is true. | 3774 // Check stepping where the if condition in bar is true. |
3804 break_point_hit_count = 0; | 3775 break_point_hit_count = 0; |
3805 const int argc = 1; | 3776 const int argc = 1; |
3806 v8::Handle<v8::Value> argv[argc] = { v8::True() }; | 3777 v8::Handle<v8::Value> argv[argc] = { v8::True() }; |
3807 foo->Call(env->Global(), argc, argv); | 3778 foo->Call(env->Global(), argc, argv); |
3808 CHECK_EQ(8, break_point_hit_count); | 3779 CHECK_EQ(8, break_point_hit_count); |
3809 | 3780 |
3810 v8::Debug::SetDebugEventListener(NULL); | 3781 v8::Debug::SetDebugEventListener2(NULL); |
3811 CheckDebuggerUnloaded(); | 3782 CheckDebuggerUnloaded(); |
3812 | 3783 |
3813 // Register a debug event listener which just counts. | 3784 // Register a debug event listener which just counts. |
3814 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 3785 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
3815 | 3786 |
3816 break_point_hit_count = 0; | 3787 break_point_hit_count = 0; |
3817 foo->Call(env->Global(), 0, NULL); | 3788 foo->Call(env->Global(), 0, NULL); |
3818 | 3789 |
3819 // Without stepping only the debugger statement is hit. | 3790 // Without stepping only the debugger statement is hit. |
3820 CHECK_EQ(1, break_point_hit_count); | 3791 CHECK_EQ(1, break_point_hit_count); |
3821 | 3792 |
3822 v8::Debug::SetDebugEventListener(NULL); | 3793 v8::Debug::SetDebugEventListener2(NULL); |
3823 CheckDebuggerUnloaded(); | 3794 CheckDebuggerUnloaded(); |
3824 } | 3795 } |
3825 | 3796 |
3826 | 3797 |
3827 // Tests that breakpoint will be hit if it's set in script. | 3798 // Tests that breakpoint will be hit if it's set in script. |
3828 TEST(PauseInScript) { | 3799 TEST(PauseInScript) { |
3829 DebugLocalContext env; | 3800 DebugLocalContext env; |
3830 v8::HandleScope scope(env->GetIsolate()); | 3801 v8::HandleScope scope(env->GetIsolate()); |
3831 env.ExposeDebug(); | 3802 env.ExposeDebug(); |
3832 | 3803 |
3833 // Register a debug event listener which counts. | 3804 // Register a debug event listener which counts. |
3834 v8::Debug::SetDebugEventListener(DebugEventCounter); | 3805 v8::Debug::SetDebugEventListener2(DebugEventCounter); |
3835 | 3806 |
3836 // Create a script that returns a function. | 3807 // Create a script that returns a function. |
3837 const char* src = "(function (evt) {})"; | 3808 const char* src = "(function (evt) {})"; |
3838 const char* script_name = "StepInHandlerTest"; | 3809 const char* script_name = "StepInHandlerTest"; |
3839 | 3810 |
3840 // Set breakpoint in the script. | 3811 // Set breakpoint in the script. |
3841 SetScriptBreakPointByNameFromJS(script_name, 0, -1); | 3812 SetScriptBreakPointByNameFromJS(script_name, 0, -1); |
3842 break_point_hit_count = 0; | 3813 break_point_hit_count = 0; |
3843 | 3814 |
3844 v8::ScriptOrigin origin(v8::String::New(script_name), v8::Integer::New(0)); | 3815 v8::ScriptOrigin origin(v8::String::New(script_name), v8::Integer::New(0)); |
3845 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(src), | 3816 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(src), |
3846 &origin); | 3817 &origin); |
3847 v8::Local<v8::Value> r = script->Run(); | 3818 v8::Local<v8::Value> r = script->Run(); |
3848 | 3819 |
3849 CHECK(r->IsFunction()); | 3820 CHECK(r->IsFunction()); |
3850 CHECK_EQ(1, break_point_hit_count); | 3821 CHECK_EQ(1, break_point_hit_count); |
3851 | 3822 |
3852 // Get rid of the debug event listener. | 3823 // Get rid of the debug event listener. |
3853 v8::Debug::SetDebugEventListener(NULL); | 3824 v8::Debug::SetDebugEventListener2(NULL); |
3854 CheckDebuggerUnloaded(); | 3825 CheckDebuggerUnloaded(); |
3855 } | 3826 } |
3856 | 3827 |
3857 | 3828 |
3858 // Test break on exceptions. For each exception break combination the number | 3829 // Test break on exceptions. For each exception break combination the number |
3859 // of debug event exception callbacks and message callbacks are collected. The | 3830 // of debug event exception callbacks and message callbacks are collected. The |
3860 // number of debug event exception callbacks are used to check that the | 3831 // number of debug event exception callbacks are used to check that the |
3861 // debugger is called correctly and the number of message callbacks is used to | 3832 // debugger is called correctly and the number of message callbacks is used to |
3862 // check that uncaught exceptions are still returned even if there is a break | 3833 // check that uncaught exceptions are still returned even if there is a break |
3863 // for them. | 3834 // for them. |
3864 TEST(BreakOnException) { | 3835 TEST(BreakOnException) { |
3865 DebugLocalContext env; | 3836 DebugLocalContext env; |
3866 v8::HandleScope scope(env->GetIsolate()); | 3837 v8::HandleScope scope(env->GetIsolate()); |
3867 env.ExposeDebug(); | 3838 env.ExposeDebug(); |
3868 | 3839 |
3869 v8::internal::Isolate::Current()->TraceException(false); | 3840 v8::internal::Isolate::Current()->TraceException(false); |
3870 | 3841 |
3871 // Create functions for testing break on exception. | 3842 // Create functions for testing break on exception. |
3872 CompileFunction(&env, "function throws(){throw 1;}", "throws"); | 3843 CompileFunction(&env, "function throws(){throw 1;}", "throws"); |
3873 v8::Local<v8::Function> caught = | 3844 v8::Local<v8::Function> caught = |
3874 CompileFunction(&env, | 3845 CompileFunction(&env, |
3875 "function caught(){try {throws();} catch(e) {};}", | 3846 "function caught(){try {throws();} catch(e) {};}", |
3876 "caught"); | 3847 "caught"); |
3877 v8::Local<v8::Function> notCaught = | 3848 v8::Local<v8::Function> notCaught = |
3878 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); | 3849 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); |
3879 | 3850 |
3880 v8::V8::AddMessageListener(MessageCallbackCount); | 3851 v8::V8::AddMessageListener(MessageCallbackCount); |
3881 v8::Debug::SetDebugEventListener(DebugEventCounter); | 3852 v8::Debug::SetDebugEventListener2(DebugEventCounter); |
3882 | 3853 |
3883 // Initial state should be no break on exceptions. | 3854 // Initial state should be no break on exceptions. |
3884 DebugEventCounterClear(); | 3855 DebugEventCounterClear(); |
3885 MessageCallbackCountClear(); | 3856 MessageCallbackCountClear(); |
3886 caught->Call(env->Global(), 0, NULL); | 3857 caught->Call(env->Global(), 0, NULL); |
3887 CHECK_EQ(0, exception_hit_count); | 3858 CHECK_EQ(0, exception_hit_count); |
3888 CHECK_EQ(0, uncaught_exception_hit_count); | 3859 CHECK_EQ(0, uncaught_exception_hit_count); |
3889 CHECK_EQ(0, message_callback_count); | 3860 CHECK_EQ(0, message_callback_count); |
3890 notCaught->Call(env->Global(), 0, NULL); | 3861 notCaught->Call(env->Global(), 0, NULL); |
3891 CHECK_EQ(0, exception_hit_count); | 3862 CHECK_EQ(0, exception_hit_count); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3989 ChangeBreakOnExceptionFromJS(true, false); | 3960 ChangeBreakOnExceptionFromJS(true, false); |
3990 caught->Call(env->Global(), 0, NULL); | 3961 caught->Call(env->Global(), 0, NULL); |
3991 CHECK_EQ(1, exception_hit_count); | 3962 CHECK_EQ(1, exception_hit_count); |
3992 CHECK_EQ(0, uncaught_exception_hit_count); | 3963 CHECK_EQ(0, uncaught_exception_hit_count); |
3993 CHECK_EQ(0, message_callback_count); | 3964 CHECK_EQ(0, message_callback_count); |
3994 notCaught->Call(env->Global(), 0, NULL); | 3965 notCaught->Call(env->Global(), 0, NULL); |
3995 CHECK_EQ(2, exception_hit_count); | 3966 CHECK_EQ(2, exception_hit_count); |
3996 CHECK_EQ(1, uncaught_exception_hit_count); | 3967 CHECK_EQ(1, uncaught_exception_hit_count); |
3997 CHECK_EQ(1, message_callback_count); | 3968 CHECK_EQ(1, message_callback_count); |
3998 | 3969 |
3999 v8::Debug::SetDebugEventListener(NULL); | 3970 v8::Debug::SetDebugEventListener2(NULL); |
4000 CheckDebuggerUnloaded(); | 3971 CheckDebuggerUnloaded(); |
4001 v8::V8::RemoveMessageListeners(MessageCallbackCount); | 3972 v8::V8::RemoveMessageListeners(MessageCallbackCount); |
4002 } | 3973 } |
4003 | 3974 |
4004 | 3975 |
4005 // Test break on exception from compiler errors. When compiling using | 3976 // Test break on exception from compiler errors. When compiling using |
4006 // v8::Script::Compile there is no JavaScript stack whereas when compiling using | 3977 // v8::Script::Compile there is no JavaScript stack whereas when compiling using |
4007 // eval there are JavaScript frames. | 3978 // eval there are JavaScript frames. |
4008 TEST(BreakOnCompileException) { | 3979 TEST(BreakOnCompileException) { |
4009 DebugLocalContext env; | 3980 DebugLocalContext env; |
4010 v8::HandleScope scope(env->GetIsolate()); | 3981 v8::HandleScope scope(env->GetIsolate()); |
4011 | 3982 |
4012 // For this test, we want to break on uncaught exceptions: | 3983 // For this test, we want to break on uncaught exceptions: |
4013 ChangeBreakOnException(false, true); | 3984 ChangeBreakOnException(false, true); |
4014 | 3985 |
4015 v8::internal::Isolate::Current()->TraceException(false); | 3986 v8::internal::Isolate::Current()->TraceException(false); |
4016 | 3987 |
4017 // Create a function for checking the function when hitting a break point. | 3988 // Create a function for checking the function when hitting a break point. |
4018 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); | 3989 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); |
4019 | 3990 |
4020 v8::V8::AddMessageListener(MessageCallbackCount); | 3991 v8::V8::AddMessageListener(MessageCallbackCount); |
4021 v8::Debug::SetDebugEventListener(DebugEventCounter); | 3992 v8::Debug::SetDebugEventListener2(DebugEventCounter); |
4022 | 3993 |
4023 DebugEventCounterClear(); | 3994 DebugEventCounterClear(); |
4024 MessageCallbackCountClear(); | 3995 MessageCallbackCountClear(); |
4025 | 3996 |
4026 // Check initial state. | 3997 // Check initial state. |
4027 CHECK_EQ(0, exception_hit_count); | 3998 CHECK_EQ(0, exception_hit_count); |
4028 CHECK_EQ(0, uncaught_exception_hit_count); | 3999 CHECK_EQ(0, uncaught_exception_hit_count); |
4029 CHECK_EQ(0, message_callback_count); | 4000 CHECK_EQ(0, message_callback_count); |
4030 CHECK_EQ(-1, last_js_stack_height); | 4001 CHECK_EQ(-1, last_js_stack_height); |
4031 | 4002 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4065 | 4036 |
4066 // For this test, we want to break on uncaught exceptions: | 4037 // For this test, we want to break on uncaught exceptions: |
4067 ChangeBreakOnException(false, true); | 4038 ChangeBreakOnException(false, true); |
4068 | 4039 |
4069 // Create a function for checking the function when hitting a break point. | 4040 // Create a function for checking the function when hitting a break point. |
4070 frame_function_name = CompileFunction(&env, | 4041 frame_function_name = CompileFunction(&env, |
4071 frame_function_name_source, | 4042 frame_function_name_source, |
4072 "frame_function_name"); | 4043 "frame_function_name"); |
4073 | 4044 |
4074 // Register a debug event listener which steps and counts. | 4045 // Register a debug event listener which steps and counts. |
4075 v8::Debug::SetDebugEventListener(DebugEventStepSequence); | 4046 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); |
4076 | 4047 |
4077 // Create functions for testing stepping. | 4048 // Create functions for testing stepping. |
4078 const char* src = "function a() { n(); }; " | 4049 const char* src = "function a() { n(); }; " |
4079 "function b() { c(); }; " | 4050 "function b() { c(); }; " |
4080 "function c() { n(); }; " | 4051 "function c() { n(); }; " |
4081 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; " | 4052 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; " |
4082 "function e() { n(); }; " | 4053 "function e() { n(); }; " |
4083 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; " | 4054 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; " |
4084 "function g() { h(); }; " | 4055 "function g() { h(); }; " |
4085 "function h() { x = 1; throw 1; }; "; | 4056 "function h() { x = 1; throw 1; }; "; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4137 // Step through invocation of f + g + h now with break on caught exceptions. | 4108 // Step through invocation of f + g + h now with break on caught exceptions. |
4138 ChangeBreakOnException(true, true); | 4109 ChangeBreakOnException(true, true); |
4139 step_action = StepIn; | 4110 step_action = StepIn; |
4140 break_point_hit_count = 0; | 4111 break_point_hit_count = 0; |
4141 expected_step_sequence = "ffghhhff"; | 4112 expected_step_sequence = "ffghhhff"; |
4142 f->Call(env->Global(), 0, NULL); | 4113 f->Call(env->Global(), 0, NULL); |
4143 CHECK_EQ(StrLength(expected_step_sequence), | 4114 CHECK_EQ(StrLength(expected_step_sequence), |
4144 break_point_hit_count); | 4115 break_point_hit_count); |
4145 | 4116 |
4146 // Get rid of the debug event listener. | 4117 // Get rid of the debug event listener. |
4147 v8::Debug::SetDebugEventListener(NULL); | 4118 v8::Debug::SetDebugEventListener2(NULL); |
4148 CheckDebuggerUnloaded(); | 4119 CheckDebuggerUnloaded(); |
4149 } | 4120 } |
4150 | 4121 |
4151 | 4122 |
4152 TEST(DebugBreak) { | 4123 TEST(DebugBreak) { |
4153 i::FLAG_stress_compaction = false; | 4124 i::FLAG_stress_compaction = false; |
4154 #ifdef VERIFY_HEAP | 4125 #ifdef VERIFY_HEAP |
4155 i::FLAG_verify_heap = true; | 4126 i::FLAG_verify_heap = true; |
4156 #endif | 4127 #endif |
4157 DebugLocalContext env; | 4128 DebugLocalContext env; |
4158 v8::HandleScope scope(env->GetIsolate()); | 4129 v8::HandleScope scope(env->GetIsolate()); |
4159 | 4130 |
4160 // Register a debug event listener which sets the break flag and counts. | 4131 // Register a debug event listener which sets the break flag and counts. |
4161 v8::Debug::SetDebugEventListener(DebugEventBreak); | 4132 v8::Debug::SetDebugEventListener2(DebugEventBreak); |
4162 | 4133 |
4163 // Create a function for testing stepping. | 4134 // Create a function for testing stepping. |
4164 const char* src = "function f0() {}" | 4135 const char* src = "function f0() {}" |
4165 "function f1(x1) {}" | 4136 "function f1(x1) {}" |
4166 "function f2(x1,x2) {}" | 4137 "function f2(x1,x2) {}" |
4167 "function f3(x1,x2,x3) {}"; | 4138 "function f3(x1,x2,x3) {}"; |
4168 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); | 4139 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); |
4169 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1"); | 4140 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1"); |
4170 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2"); | 4141 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2"); |
4171 v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3"); | 4142 v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3"); |
(...skipping 19 matching lines...) Expand all Loading... |
4191 f0->Call(env->Global(), i, argv); | 4162 f0->Call(env->Global(), i, argv); |
4192 f1->Call(env->Global(), i, argv); | 4163 f1->Call(env->Global(), i, argv); |
4193 f2->Call(env->Global(), i, argv); | 4164 f2->Call(env->Global(), i, argv); |
4194 f3->Call(env->Global(), i, argv); | 4165 f3->Call(env->Global(), i, argv); |
4195 } | 4166 } |
4196 | 4167 |
4197 // One break for each function called. | 4168 // One break for each function called. |
4198 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); | 4169 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); |
4199 | 4170 |
4200 // Get rid of the debug event listener. | 4171 // Get rid of the debug event listener. |
4201 v8::Debug::SetDebugEventListener(NULL); | 4172 v8::Debug::SetDebugEventListener2(NULL); |
4202 CheckDebuggerUnloaded(); | 4173 CheckDebuggerUnloaded(); |
4203 } | 4174 } |
4204 | 4175 |
4205 | 4176 |
4206 // Test to ensure that JavaScript code keeps running while the debug break | 4177 // Test to ensure that JavaScript code keeps running while the debug break |
4207 // through the stack limit flag is set but breaks are disabled. | 4178 // through the stack limit flag is set but breaks are disabled. |
4208 TEST(DisableBreak) { | 4179 TEST(DisableBreak) { |
4209 DebugLocalContext env; | 4180 DebugLocalContext env; |
4210 v8::HandleScope scope(env->GetIsolate()); | 4181 v8::HandleScope scope(env->GetIsolate()); |
4211 | 4182 |
4212 // Register a debug event listener which sets the break flag and counts. | 4183 // Register a debug event listener which sets the break flag and counts. |
4213 v8::Debug::SetDebugEventListener(DebugEventCounter); | 4184 v8::Debug::SetDebugEventListener2(DebugEventCounter); |
4214 | 4185 |
4215 // Create a function for testing stepping. | 4186 // Create a function for testing stepping. |
4216 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; | 4187 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; |
4217 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 4188 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
4218 | 4189 |
4219 // Set the debug break flag. | 4190 // Set the debug break flag. |
4220 v8::Debug::DebugBreak(); | 4191 v8::Debug::DebugBreak(); |
4221 | 4192 |
4222 // Call all functions with different argument count. | 4193 // Call all functions with different argument count. |
4223 break_point_hit_count = 0; | 4194 break_point_hit_count = 0; |
4224 f->Call(env->Global(), 0, NULL); | 4195 f->Call(env->Global(), 0, NULL); |
4225 CHECK_EQ(1, break_point_hit_count); | 4196 CHECK_EQ(1, break_point_hit_count); |
4226 | 4197 |
4227 { | 4198 { |
4228 v8::Debug::DebugBreak(); | 4199 v8::Debug::DebugBreak(); |
4229 v8::internal::DisableBreak disable_break(true); | 4200 v8::internal::DisableBreak disable_break(true); |
4230 f->Call(env->Global(), 0, NULL); | 4201 f->Call(env->Global(), 0, NULL); |
4231 CHECK_EQ(1, break_point_hit_count); | 4202 CHECK_EQ(1, break_point_hit_count); |
4232 } | 4203 } |
4233 | 4204 |
4234 f->Call(env->Global(), 0, NULL); | 4205 f->Call(env->Global(), 0, NULL); |
4235 CHECK_EQ(2, break_point_hit_count); | 4206 CHECK_EQ(2, break_point_hit_count); |
4236 | 4207 |
4237 // Get rid of the debug event listener. | 4208 // Get rid of the debug event listener. |
4238 v8::Debug::SetDebugEventListener(NULL); | 4209 v8::Debug::SetDebugEventListener2(NULL); |
4239 CheckDebuggerUnloaded(); | 4210 CheckDebuggerUnloaded(); |
4240 } | 4211 } |
4241 | 4212 |
4242 static const char* kSimpleExtensionSource = | 4213 static const char* kSimpleExtensionSource = |
4243 "(function Foo() {" | 4214 "(function Foo() {" |
4244 " return 4;" | 4215 " return 4;" |
4245 "})() "; | 4216 "})() "; |
4246 | 4217 |
4247 // http://crbug.com/28933 | 4218 // http://crbug.com/28933 |
4248 // Test that debug break is disabled when bootstrapper is active. | 4219 // Test that debug break is disabled when bootstrapper is active. |
4249 TEST(NoBreakWhenBootstrapping) { | 4220 TEST(NoBreakWhenBootstrapping) { |
4250 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 4221 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
4251 v8::HandleScope scope(isolate); | 4222 v8::HandleScope scope(isolate); |
4252 | 4223 |
4253 // Register a debug event listener which sets the break flag and counts. | 4224 // Register a debug event listener which sets the break flag and counts. |
4254 v8::Debug::SetDebugEventListener(DebugEventCounter); | 4225 v8::Debug::SetDebugEventListener2(DebugEventCounter); |
4255 | 4226 |
4256 // Set the debug break flag. | 4227 // Set the debug break flag. |
4257 v8::Debug::DebugBreak(); | 4228 v8::Debug::DebugBreak(); |
4258 break_point_hit_count = 0; | 4229 break_point_hit_count = 0; |
4259 { | 4230 { |
4260 // Create a context with an extension to make sure that some JavaScript | 4231 // Create a context with an extension to make sure that some JavaScript |
4261 // code is executed during bootstrapping. | 4232 // code is executed during bootstrapping. |
4262 v8::RegisterExtension(new v8::Extension("simpletest", | 4233 v8::RegisterExtension(new v8::Extension("simpletest", |
4263 kSimpleExtensionSource)); | 4234 kSimpleExtensionSource)); |
4264 const char* extension_names[] = { "simpletest" }; | 4235 const char* extension_names[] = { "simpletest" }; |
4265 v8::ExtensionConfiguration extensions(1, extension_names); | 4236 v8::ExtensionConfiguration extensions(1, extension_names); |
4266 v8::HandleScope handle_scope(isolate); | 4237 v8::HandleScope handle_scope(isolate); |
4267 v8::Context::New(isolate, &extensions); | 4238 v8::Context::New(isolate, &extensions); |
4268 } | 4239 } |
4269 // Check that no DebugBreak events occured during the context creation. | 4240 // Check that no DebugBreak events occured during the context creation. |
4270 CHECK_EQ(0, break_point_hit_count); | 4241 CHECK_EQ(0, break_point_hit_count); |
4271 | 4242 |
4272 // Get rid of the debug event listener. | 4243 // Get rid of the debug event listener. |
4273 v8::Debug::SetDebugEventListener(NULL); | 4244 v8::Debug::SetDebugEventListener2(NULL); |
4274 CheckDebuggerUnloaded(); | 4245 CheckDebuggerUnloaded(); |
4275 } | 4246 } |
4276 | 4247 |
4277 | 4248 |
4278 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { | 4249 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { |
4279 v8::Handle<v8::Array> result = v8::Array::New(3); | 4250 v8::Handle<v8::Array> result = v8::Array::New(3); |
4280 result->Set(v8::Integer::New(0), v8::String::New("a")); | 4251 result->Set(v8::Integer::New(0), v8::String::New("a")); |
4281 result->Set(v8::Integer::New(1), v8::String::New("b")); | 4252 result->Set(v8::Integer::New(1), v8::String::New("b")); |
4282 result->Set(v8::Integer::New(2), v8::String::New("c")); | 4253 result->Set(v8::Integer::New(2), v8::String::New("c")); |
4283 info.GetReturnValue().Set(result); | 4254 info.GetReturnValue().Set(result); |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4868 | 4839 |
4869 // This is the debugger thread, that executes no v8 calls except | 4840 // This is the debugger thread, that executes no v8 calls except |
4870 // placing JSON debugger commands in the queue. | 4841 // placing JSON debugger commands in the queue. |
4871 class MessageQueueDebuggerThread : public v8::internal::Thread { | 4842 class MessageQueueDebuggerThread : public v8::internal::Thread { |
4872 public: | 4843 public: |
4873 MessageQueueDebuggerThread() | 4844 MessageQueueDebuggerThread() |
4874 : Thread("MessageQueueDebuggerThread") { } | 4845 : Thread("MessageQueueDebuggerThread") { } |
4875 void Run(); | 4846 void Run(); |
4876 }; | 4847 }; |
4877 | 4848 |
4878 static void MessageHandler(const uint16_t* message, int length, | 4849 |
4879 v8::Debug::ClientData* client_data) { | 4850 static void MessageHandler(const v8::Debug::Message& message) { |
4880 static char print_buffer[1000]; | 4851 v8::Handle<v8::String> json = message.GetJSON(); |
4881 Utf16ToAscii(message, length, print_buffer); | 4852 v8::String::AsciiValue ascii(json); |
4882 if (IsBreakEventMessage(print_buffer)) { | 4853 if (IsBreakEventMessage(*ascii)) { |
4883 // Lets test script wait until break occurs to send commands. | 4854 // Lets test script wait until break occurs to send commands. |
4884 // Signals when a break is reported. | 4855 // Signals when a break is reported. |
4885 message_queue_barriers.semaphore_2->Signal(); | 4856 message_queue_barriers.semaphore_2->Signal(); |
4886 } | 4857 } |
4887 | 4858 |
4888 // Allow message handler to block on a semaphore, to test queueing of | 4859 // Allow message handler to block on a semaphore, to test queueing of |
4889 // messages while blocked. | 4860 // messages while blocked. |
4890 message_queue_barriers.semaphore_1->Wait(); | 4861 message_queue_barriers.semaphore_1->Wait(); |
4891 } | 4862 } |
4892 | 4863 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4974 | 4945 |
4975 | 4946 |
4976 // This thread runs the v8 engine. | 4947 // This thread runs the v8 engine. |
4977 TEST(MessageQueues) { | 4948 TEST(MessageQueues) { |
4978 MessageQueueDebuggerThread message_queue_debugger_thread; | 4949 MessageQueueDebuggerThread message_queue_debugger_thread; |
4979 | 4950 |
4980 // Create a V8 environment | 4951 // Create a V8 environment |
4981 DebugLocalContext env; | 4952 DebugLocalContext env; |
4982 v8::HandleScope scope(env->GetIsolate()); | 4953 v8::HandleScope scope(env->GetIsolate()); |
4983 message_queue_barriers.Initialize(); | 4954 message_queue_barriers.Initialize(); |
4984 v8::Debug::SetMessageHandler(MessageHandler); | 4955 v8::Debug::SetMessageHandler2(MessageHandler); |
4985 message_queue_debugger_thread.Start(); | 4956 message_queue_debugger_thread.Start(); |
4986 | 4957 |
4987 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; | 4958 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; |
4988 const char* source_2 = "e = 17;"; | 4959 const char* source_2 = "e = 17;"; |
4989 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; | 4960 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; |
4990 | 4961 |
4991 // See MessageQueueDebuggerThread::Run for interleaved sequence of | 4962 // See MessageQueueDebuggerThread::Run for interleaved sequence of |
4992 // API calls and events in the two threads. | 4963 // API calls and events in the two threads. |
4993 CompileRun(source_1); | 4964 CompileRun(source_1); |
4994 message_queue_barriers.barrier_1.Wait(); | 4965 message_queue_barriers.barrier_1.Wait(); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5440 TEST(RecursiveBreakpoints) { | 5411 TEST(RecursiveBreakpoints) { |
5441 TestRecursiveBreakpointsGeneric(false); | 5412 TestRecursiveBreakpointsGeneric(false); |
5442 } | 5413 } |
5443 | 5414 |
5444 | 5415 |
5445 TEST(RecursiveBreakpointsGlobal) { | 5416 TEST(RecursiveBreakpointsGlobal) { |
5446 TestRecursiveBreakpointsGeneric(true); | 5417 TestRecursiveBreakpointsGeneric(true); |
5447 } | 5418 } |
5448 | 5419 |
5449 | 5420 |
5450 static void DummyDebugEventListener(v8::DebugEvent event, | 5421 static void DummyDebugEventListener( |
5451 v8::Handle<v8::Object> exec_state, | 5422 const v8::Debug::EventDetails& event_details) { |
5452 v8::Handle<v8::Object> event_data, | |
5453 v8::Handle<v8::Value> data) { | |
5454 } | 5423 } |
5455 | 5424 |
5456 | 5425 |
5457 TEST(SetDebugEventListenerOnUninitializedVM) { | 5426 TEST(SetDebugEventListenerOnUninitializedVM) { |
5458 v8::Debug::SetDebugEventListener(DummyDebugEventListener); | 5427 v8::Debug::SetDebugEventListener2(DummyDebugEventListener); |
5459 } | 5428 } |
5460 | 5429 |
5461 | 5430 |
5462 static void DummyMessageHandler(const v8::Debug::Message& message) { | 5431 static void DummyMessageHandler(const v8::Debug::Message& message) { |
5463 } | 5432 } |
5464 | 5433 |
5465 | 5434 |
5466 TEST(SetMessageHandlerOnUninitializedVM) { | 5435 TEST(SetMessageHandlerOnUninitializedVM) { |
5467 v8::Debug::SetMessageHandler2(DummyMessageHandler); | 5436 v8::Debug::SetMessageHandler2(DummyMessageHandler); |
5468 } | 5437 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5639 // Test that clearing the debug event listener actually clears all break points | 5608 // Test that clearing the debug event listener actually clears all break points |
5640 // and related information. | 5609 // and related information. |
5641 TEST(DebuggerUnload) { | 5610 TEST(DebuggerUnload) { |
5642 DebugLocalContext env; | 5611 DebugLocalContext env; |
5643 | 5612 |
5644 // Check debugger is unloaded before it is used. | 5613 // Check debugger is unloaded before it is used. |
5645 CheckDebuggerUnloaded(); | 5614 CheckDebuggerUnloaded(); |
5646 | 5615 |
5647 // Set a debug event listener. | 5616 // Set a debug event listener. |
5648 break_point_hit_count = 0; | 5617 break_point_hit_count = 0; |
5649 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 5618 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
5650 v8::Undefined()); | |
5651 { | 5619 { |
5652 v8::HandleScope scope(env->GetIsolate()); | 5620 v8::HandleScope scope(env->GetIsolate()); |
5653 // Create a couple of functions for the test. | 5621 // Create a couple of functions for the test. |
5654 v8::Local<v8::Function> foo = | 5622 v8::Local<v8::Function> foo = |
5655 CompileFunction(&env, "function foo(){x=1}", "foo"); | 5623 CompileFunction(&env, "function foo(){x=1}", "foo"); |
5656 v8::Local<v8::Function> bar = | 5624 v8::Local<v8::Function> bar = |
5657 CompileFunction(&env, "function bar(){y=2}", "bar"); | 5625 CompileFunction(&env, "function bar(){y=2}", "bar"); |
5658 | 5626 |
5659 // Set some break points. | 5627 // Set some break points. |
5660 SetBreakPoint(foo, 0); | 5628 SetBreakPoint(foo, 0); |
5661 SetBreakPoint(foo, 4); | 5629 SetBreakPoint(foo, 4); |
5662 SetBreakPoint(bar, 0); | 5630 SetBreakPoint(bar, 0); |
5663 SetBreakPoint(bar, 4); | 5631 SetBreakPoint(bar, 4); |
5664 | 5632 |
5665 // Make sure that the break points are there. | 5633 // Make sure that the break points are there. |
5666 break_point_hit_count = 0; | 5634 break_point_hit_count = 0; |
5667 foo->Call(env->Global(), 0, NULL); | 5635 foo->Call(env->Global(), 0, NULL); |
5668 CHECK_EQ(2, break_point_hit_count); | 5636 CHECK_EQ(2, break_point_hit_count); |
5669 bar->Call(env->Global(), 0, NULL); | 5637 bar->Call(env->Global(), 0, NULL); |
5670 CHECK_EQ(4, break_point_hit_count); | 5638 CHECK_EQ(4, break_point_hit_count); |
5671 } | 5639 } |
5672 | 5640 |
5673 // Remove the debug event listener without clearing breakpoints. Do this | 5641 // Remove the debug event listener without clearing breakpoints. Do this |
5674 // outside a handle scope. | 5642 // outside a handle scope. |
5675 v8::Debug::SetDebugEventListener(NULL); | 5643 v8::Debug::SetDebugEventListener2(NULL); |
5676 CheckDebuggerUnloaded(true); | 5644 CheckDebuggerUnloaded(true); |
5677 | 5645 |
5678 // Now set a debug message handler. | 5646 // Now set a debug message handler. |
5679 break_point_hit_count = 0; | 5647 break_point_hit_count = 0; |
5680 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); | 5648 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); |
5681 { | 5649 { |
5682 v8::HandleScope scope(env->GetIsolate()); | 5650 v8::HandleScope scope(env->GetIsolate()); |
5683 | 5651 |
5684 // Get the test functions again. | 5652 // Get the test functions again. |
5685 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( | 5653 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5743 | 5711 |
5744 // Run code to throw a unhandled exception. This should end up in the message | 5712 // Run code to throw a unhandled exception. This should end up in the message |
5745 // handler. | 5713 // handler. |
5746 CompileRun("throw 1"); | 5714 CompileRun("throw 1"); |
5747 | 5715 |
5748 // The message handler should be called. | 5716 // The message handler should be called. |
5749 CHECK_GT(message_handler_hit_count, 0); | 5717 CHECK_GT(message_handler_hit_count, 0); |
5750 | 5718 |
5751 // Clear debug message handler. | 5719 // Clear debug message handler. |
5752 message_handler_hit_count = 0; | 5720 message_handler_hit_count = 0; |
5753 v8::Debug::SetMessageHandler(NULL); | 5721 v8::Debug::SetMessageHandler2(NULL); |
5754 | 5722 |
5755 // Run code to throw a unhandled exception. This should end up in the message | 5723 // Run code to throw a unhandled exception. This should end up in the message |
5756 // handler. | 5724 // handler. |
5757 CompileRun("throw 1"); | 5725 CompileRun("throw 1"); |
5758 | 5726 |
5759 // The message handler should not be called more. | 5727 // The message handler should not be called more. |
5760 CHECK_EQ(0, message_handler_hit_count); | 5728 CHECK_EQ(0, message_handler_hit_count); |
5761 | 5729 |
5762 CheckDebuggerUnloaded(true); | 5730 CheckDebuggerUnloaded(true); |
5763 } | 5731 } |
5764 | 5732 |
5765 | 5733 |
5766 // Debugger message handler which clears the message handler while active. | 5734 // Debugger message handler which clears the message handler while active. |
5767 static void MessageHandlerClearingMessageHandler( | 5735 static void MessageHandlerClearingMessageHandler( |
5768 const v8::Debug::Message& message) { | 5736 const v8::Debug::Message& message) { |
5769 message_handler_hit_count++; | 5737 message_handler_hit_count++; |
5770 | 5738 |
5771 // Clear debug message handler. | 5739 // Clear debug message handler. |
5772 v8::Debug::SetMessageHandler(NULL); | 5740 v8::Debug::SetMessageHandler2(NULL); |
5773 } | 5741 } |
5774 | 5742 |
5775 | 5743 |
5776 // Test clearing the debug message handler while processing a debug event. | 5744 // Test clearing the debug message handler while processing a debug event. |
5777 TEST(DebuggerClearMessageHandlerWhileActive) { | 5745 TEST(DebuggerClearMessageHandlerWhileActive) { |
5778 DebugLocalContext env; | 5746 DebugLocalContext env; |
5779 v8::HandleScope scope(env->GetIsolate()); | 5747 v8::HandleScope scope(env->GetIsolate()); |
5780 | 5748 |
5781 // Check debugger is unloaded before it is used. | 5749 // Check debugger is unloaded before it is used. |
5782 CheckDebuggerUnloaded(); | 5750 CheckDebuggerUnloaded(); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6196 frame_script_name = CompileFunction(&env, | 6164 frame_script_name = CompileFunction(&env, |
6197 frame_script_name_source, | 6165 frame_script_name_source, |
6198 "frame_script_name"); | 6166 "frame_script_name"); |
6199 frame_script_data = CompileFunction(&env, | 6167 frame_script_data = CompileFunction(&env, |
6200 frame_script_data_source, | 6168 frame_script_data_source, |
6201 "frame_script_data"); | 6169 "frame_script_data"); |
6202 compiled_script_data = CompileFunction(&env, | 6170 compiled_script_data = CompileFunction(&env, |
6203 compiled_script_data_source, | 6171 compiled_script_data_source, |
6204 "compiled_script_data"); | 6172 "compiled_script_data"); |
6205 | 6173 |
6206 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 6174 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); |
6207 v8::Undefined()); | |
6208 | 6175 |
6209 // Test function source. | 6176 // Test function source. |
6210 v8::Local<v8::String> script = v8::String::New( | 6177 v8::Local<v8::String> script = v8::String::New( |
6211 "function f() {\n" | 6178 "function f() {\n" |
6212 " debugger;\n" | 6179 " debugger;\n" |
6213 "}\n"); | 6180 "}\n"); |
6214 | 6181 |
6215 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name")); | 6182 v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8::String::New("name")); |
6216 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); | 6183 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); |
6217 script1->SetData(v8::String::New("data")); | 6184 script1->SetData(v8::String::New("data")); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6384 // Calling g will not cause any additional breaks. | 6351 // Calling g will not cause any additional breaks. |
6385 g->Call(env->Global(), 0, NULL); | 6352 g->Call(env->Global(), 0, NULL); |
6386 CHECK_EQ(2, message_handler_break_hit_count); | 6353 CHECK_EQ(2, message_handler_break_hit_count); |
6387 } | 6354 } |
6388 | 6355 |
6389 | 6356 |
6390 #ifndef V8_INTERPRETED_REGEXP | 6357 #ifndef V8_INTERPRETED_REGEXP |
6391 // Debug event handler which gets the function on the top frame and schedules a | 6358 // Debug event handler which gets the function on the top frame and schedules a |
6392 // break a number of times. | 6359 // break a number of times. |
6393 static void DebugEventDebugBreak( | 6360 static void DebugEventDebugBreak( |
6394 v8::DebugEvent event, | 6361 const v8::Debug::EventDetails& event_details) { |
6395 v8::Handle<v8::Object> exec_state, | 6362 v8::DebugEvent event = event_details.GetEvent(); |
6396 v8::Handle<v8::Object> event_data, | 6363 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
6397 v8::Handle<v8::Value> data) { | |
6398 | 6364 |
6399 if (event == v8::Break) { | 6365 if (event == v8::Break) { |
6400 break_point_hit_count++; | 6366 break_point_hit_count++; |
6401 | 6367 |
6402 // Get the name of the top frame function. | 6368 // Get the name of the top frame function. |
6403 if (!frame_function_name.IsEmpty()) { | 6369 if (!frame_function_name.IsEmpty()) { |
6404 // Get the name of the function. | 6370 // Get the name of the function. |
6405 const int argc = 2; | 6371 const int argc = 2; |
6406 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; | 6372 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; |
6407 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, | 6373 v8::Handle<v8::Value> result = frame_function_name->Call(exec_state, |
(...skipping 30 matching lines...) Expand all Loading... |
6438 const char* script = | 6404 const char* script = |
6439 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" | 6405 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" |
6440 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; | 6406 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; |
6441 | 6407 |
6442 v8::Local<v8::Function> f = CompileFunction(script, "f"); | 6408 v8::Local<v8::Function> f = CompileFunction(script, "f"); |
6443 const int argc = 1; | 6409 const int argc = 1; |
6444 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") }; | 6410 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") }; |
6445 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); | 6411 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); |
6446 CHECK_EQ(12, result->Int32Value()); | 6412 CHECK_EQ(12, result->Int32Value()); |
6447 | 6413 |
6448 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); | 6414 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak); |
6449 v8::Debug::DebugBreak(); | 6415 v8::Debug::DebugBreak(); |
6450 result = f->Call(env->Global(), argc, argv); | 6416 result = f->Call(env->Global(), argc, argv); |
6451 | 6417 |
6452 // Check that there was only one break event. Matching RegExp should not | 6418 // Check that there was only one break event. Matching RegExp should not |
6453 // cause Break events. | 6419 // cause Break events. |
6454 CHECK_EQ(1, break_point_hit_count); | 6420 CHECK_EQ(1, break_point_hit_count); |
6455 CHECK_EQ("f", last_function_hit); | 6421 CHECK_EQ("f", last_function_hit); |
6456 } | 6422 } |
6457 #endif // V8_INTERPRETED_REGEXP | 6423 #endif // V8_INTERPRETED_REGEXP |
6458 | 6424 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6569 CHECK_GT(message_handler_hit_count, 3); | 6535 CHECK_GT(message_handler_hit_count, 3); |
6570 | 6536 |
6571 // One break from the source and another from the evaluate request. | 6537 // One break from the source and another from the evaluate request. |
6572 CHECK_EQ(break_count, 2); | 6538 CHECK_EQ(break_count, 2); |
6573 CheckDebuggerUnloaded(); | 6539 CheckDebuggerUnloaded(); |
6574 } | 6540 } |
6575 | 6541 |
6576 | 6542 |
6577 // Debug event listener which counts the script collected events. | 6543 // Debug event listener which counts the script collected events. |
6578 int script_collected_count = 0; | 6544 int script_collected_count = 0; |
6579 static void DebugEventScriptCollectedEvent(v8::DebugEvent event, | 6545 static void DebugEventScriptCollectedEvent( |
6580 v8::Handle<v8::Object> exec_state, | 6546 const v8::Debug::EventDetails& event_details) { |
6581 v8::Handle<v8::Object> event_data, | 6547 v8::DebugEvent event = event_details.GetEvent(); |
6582 v8::Handle<v8::Value> data) { | |
6583 // Count the number of breaks. | 6548 // Count the number of breaks. |
6584 if (event == v8::ScriptCollected) { | 6549 if (event == v8::ScriptCollected) { |
6585 script_collected_count++; | 6550 script_collected_count++; |
6586 } | 6551 } |
6587 } | 6552 } |
6588 | 6553 |
6589 | 6554 |
6590 // Test that scripts collected are reported through the debug event listener. | 6555 // Test that scripts collected are reported through the debug event listener. |
6591 TEST(ScriptCollectedEvent) { | 6556 TEST(ScriptCollectedEvent) { |
6592 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 6557 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
6593 break_point_hit_count = 0; | 6558 break_point_hit_count = 0; |
6594 script_collected_count = 0; | 6559 script_collected_count = 0; |
6595 DebugLocalContext env; | 6560 DebugLocalContext env; |
6596 v8::HandleScope scope(env->GetIsolate()); | 6561 v8::HandleScope scope(env->GetIsolate()); |
6597 | 6562 |
6598 // Request the loaded scripts to initialize the debugger script cache. | 6563 // Request the loaded scripts to initialize the debugger script cache. |
6599 debug->GetLoadedScripts(); | 6564 debug->GetLoadedScripts(); |
6600 | 6565 |
6601 // Do garbage collection to ensure that only the script in this test will be | 6566 // Do garbage collection to ensure that only the script in this test will be |
6602 // collected afterwards. | 6567 // collected afterwards. |
6603 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6568 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6604 | 6569 |
6605 script_collected_count = 0; | 6570 script_collected_count = 0; |
6606 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent, | 6571 v8::Debug::SetDebugEventListener2(DebugEventScriptCollectedEvent); |
6607 v8::Undefined()); | |
6608 { | 6572 { |
6609 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); | 6573 v8::Script::Compile(v8::String::New("eval('a=1')"))->Run(); |
6610 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); | 6574 v8::Script::Compile(v8::String::New("eval('a=2')"))->Run(); |
6611 } | 6575 } |
6612 | 6576 |
6613 // Do garbage collection to collect the script above which is no longer | 6577 // Do garbage collection to collect the script above which is no longer |
6614 // referenced. | 6578 // referenced. |
6615 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6579 HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6616 | 6580 |
6617 CHECK_EQ(2, script_collected_count); | 6581 CHECK_EQ(2, script_collected_count); |
6618 | 6582 |
6619 v8::Debug::SetDebugEventListener(NULL); | 6583 v8::Debug::SetDebugEventListener2(NULL); |
6620 CheckDebuggerUnloaded(); | 6584 CheckDebuggerUnloaded(); |
6621 } | 6585 } |
6622 | 6586 |
6623 | 6587 |
6624 // Debug event listener which counts the script collected events. | 6588 // Debug event listener which counts the script collected events. |
6625 int script_collected_message_count = 0; | 6589 int script_collected_message_count = 0; |
6626 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { | 6590 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { |
6627 // Count the number of scripts collected. | 6591 // Count the number of scripts collected. |
6628 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { | 6592 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { |
6629 script_collected_message_count++; | 6593 script_collected_message_count++; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7010 | 6974 |
7011 // Create a function for testing breaking in apply. | 6975 // Create a function for testing breaking in apply. |
7012 v8::Local<v8::Function> foo = CompileFunction( | 6976 v8::Local<v8::Function> foo = CompileFunction( |
7013 &env, | 6977 &env, |
7014 "function baz(x) { }" | 6978 "function baz(x) { }" |
7015 "function bar(x) { baz(); }" | 6979 "function bar(x) { baz(); }" |
7016 "function foo(){ bar.apply(this, [1]); }", | 6980 "function foo(){ bar.apply(this, [1]); }", |
7017 "foo"); | 6981 "foo"); |
7018 | 6982 |
7019 // Register a debug event listener which steps and counts. | 6983 // Register a debug event listener which steps and counts. |
7020 v8::Debug::SetDebugEventListener(DebugEventBreakMax); | 6984 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); |
7021 | 6985 |
7022 // Set the debug break flag before calling the code using function.apply. | 6986 // Set the debug break flag before calling the code using function.apply. |
7023 v8::Debug::DebugBreak(); | 6987 v8::Debug::DebugBreak(); |
7024 | 6988 |
7025 // Limit the number of debug breaks. This is a regression test for issue 493 | 6989 // Limit the number of debug breaks. This is a regression test for issue 493 |
7026 // where this test would enter an infinite loop. | 6990 // where this test would enter an infinite loop. |
7027 break_point_hit_count = 0; | 6991 break_point_hit_count = 0; |
7028 max_break_point_hit_count = 10000; // 10000 => infinite loop. | 6992 max_break_point_hit_count = 10000; // 10000 => infinite loop. |
7029 foo->Call(env->Global(), 0, NULL); | 6993 foo->Call(env->Global(), 0, NULL); |
7030 | 6994 |
7031 // When keeping the debug break several break will happen. | 6995 // When keeping the debug break several break will happen. |
7032 CHECK_GT(break_point_hit_count, 1); | 6996 CHECK_GT(break_point_hit_count, 1); |
7033 | 6997 |
7034 v8::Debug::SetDebugEventListener(NULL); | 6998 v8::Debug::SetDebugEventListener2(NULL); |
7035 CheckDebuggerUnloaded(); | 6999 CheckDebuggerUnloaded(); |
7036 } | 7000 } |
7037 | 7001 |
7038 | 7002 |
7039 v8::Handle<v8::Context> debugee_context; | 7003 v8::Handle<v8::Context> debugee_context; |
7040 v8::Handle<v8::Context> debugger_context; | 7004 v8::Handle<v8::Context> debugger_context; |
7041 | 7005 |
7042 | 7006 |
7043 // Property getter that checks that current and calling contexts | 7007 // Property getter that checks that current and calling contexts |
7044 // are both the debugee contexts. | 7008 // are both the debugee contexts. |
7045 static void NamedGetterWithCallingContextCheck( | 7009 static void NamedGetterWithCallingContextCheck( |
7046 v8::Local<v8::String> name, | 7010 v8::Local<v8::String> name, |
7047 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7011 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7048 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(name), "a")); | 7012 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(name), "a")); |
7049 v8::Handle<v8::Context> current = v8::Context::GetCurrent(); | 7013 v8::Handle<v8::Context> current = v8::Context::GetCurrent(); |
7050 CHECK(current == debugee_context); | 7014 CHECK(current == debugee_context); |
7051 CHECK(current != debugger_context); | 7015 CHECK(current != debugger_context); |
7052 v8::Handle<v8::Context> calling = v8::Context::GetCalling(); | 7016 v8::Handle<v8::Context> calling = v8::Context::GetCalling(); |
7053 CHECK(calling == debugee_context); | 7017 CHECK(calling == debugee_context); |
7054 CHECK(calling != debugger_context); | 7018 CHECK(calling != debugger_context); |
7055 info.GetReturnValue().Set(1); | 7019 info.GetReturnValue().Set(1); |
7056 } | 7020 } |
7057 | 7021 |
7058 | 7022 |
7059 // Debug event listener that checks if the first argument of a function is | 7023 // Debug event listener that checks if the first argument of a function is |
7060 // an object with property 'a' == 1. If the property has custom accessor | 7024 // an object with property 'a' == 1. If the property has custom accessor |
7061 // this handler will eventually invoke it. | 7025 // this handler will eventually invoke it. |
7062 static void DebugEventGetAtgumentPropertyValue( | 7026 static void DebugEventGetAtgumentPropertyValue( |
7063 v8::DebugEvent event, | 7027 const v8::Debug::EventDetails& event_details) { |
7064 v8::Handle<v8::Object> exec_state, | 7028 v8::DebugEvent event = event_details.GetEvent(); |
7065 v8::Handle<v8::Object> event_data, | 7029 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
7066 v8::Handle<v8::Value> data) { | |
7067 if (event == v8::Break) { | 7030 if (event == v8::Break) { |
7068 break_point_hit_count++; | 7031 break_point_hit_count++; |
7069 CHECK(debugger_context == v8::Context::GetCurrent()); | 7032 CHECK(debugger_context == v8::Context::GetCurrent()); |
7070 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(CompileRun( | 7033 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(CompileRun( |
7071 "(function(exec_state) {\n" | 7034 "(function(exec_state) {\n" |
7072 " return (exec_state.frame(0).argumentValue(0).property('a').\n" | 7035 " return (exec_state.frame(0).argumentValue(0).property('a').\n" |
7073 " value().value() == 1);\n" | 7036 " value().value() == 1);\n" |
7074 "})")); | 7037 "})")); |
7075 const int argc = 1; | 7038 const int argc = 1; |
7076 v8::Handle<v8::Value> argv[argc] = { exec_state }; | 7039 v8::Handle<v8::Value> argv[argc] = { exec_state }; |
(...skipping 16 matching lines...) Expand all Loading... |
7093 debugger_context = v8::Utils::ToLocal(debug->debug_context()); | 7056 debugger_context = v8::Utils::ToLocal(debug->debug_context()); |
7094 | 7057 |
7095 // Create object with 'a' property accessor. | 7058 // Create object with 'a' property accessor. |
7096 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); | 7059 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); |
7097 named->SetAccessor(v8::String::New("a"), | 7060 named->SetAccessor(v8::String::New("a"), |
7098 NamedGetterWithCallingContextCheck); | 7061 NamedGetterWithCallingContextCheck); |
7099 env->Global()->Set(v8::String::New("obj"), | 7062 env->Global()->Set(v8::String::New("obj"), |
7100 named->NewInstance()); | 7063 named->NewInstance()); |
7101 | 7064 |
7102 // Register the debug event listener | 7065 // Register the debug event listener |
7103 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue); | 7066 v8::Debug::SetDebugEventListener2(DebugEventGetAtgumentPropertyValue); |
7104 | 7067 |
7105 // Create a function that invokes debugger. | 7068 // Create a function that invokes debugger. |
7106 v8::Local<v8::Function> foo = CompileFunction( | 7069 v8::Local<v8::Function> foo = CompileFunction( |
7107 &env, | 7070 &env, |
7108 "function bar(x) { debugger; }" | 7071 "function bar(x) { debugger; }" |
7109 "function foo(){ bar(obj); }", | 7072 "function foo(){ bar(obj); }", |
7110 "foo"); | 7073 "foo"); |
7111 | 7074 |
7112 break_point_hit_count = 0; | 7075 break_point_hit_count = 0; |
7113 foo->Call(env->Global(), 0, NULL); | 7076 foo->Call(env->Global(), 0, NULL); |
7114 CHECK_EQ(1, break_point_hit_count); | 7077 CHECK_EQ(1, break_point_hit_count); |
7115 | 7078 |
7116 v8::Debug::SetDebugEventListener(NULL); | 7079 v8::Debug::SetDebugEventListener2(NULL); |
7117 debugee_context = v8::Handle<v8::Context>(); | 7080 debugee_context = v8::Handle<v8::Context>(); |
7118 debugger_context = v8::Handle<v8::Context>(); | 7081 debugger_context = v8::Handle<v8::Context>(); |
7119 CheckDebuggerUnloaded(); | 7082 CheckDebuggerUnloaded(); |
7120 } | 7083 } |
7121 | 7084 |
7122 | 7085 |
7123 TEST(DebugContextIsPreservedBetweenAccesses) { | 7086 TEST(DebugContextIsPreservedBetweenAccesses) { |
7124 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 7087 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
7125 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); | 7088 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); |
7126 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); | 7089 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); |
(...skipping 12 matching lines...) Expand all Loading... |
7139 TEST(DebugEventContext) { | 7102 TEST(DebugEventContext) { |
7140 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 7103 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
7141 v8::HandleScope scope(isolate); | 7104 v8::HandleScope scope(isolate); |
7142 expected_callback_data = v8::Int32::New(2010); | 7105 expected_callback_data = v8::Int32::New(2010); |
7143 expected_context = v8::Context::New(isolate); | 7106 expected_context = v8::Context::New(isolate); |
7144 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7107 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, |
7145 expected_callback_data); | 7108 expected_callback_data); |
7146 v8::Context::Scope context_scope(expected_context); | 7109 v8::Context::Scope context_scope(expected_context); |
7147 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); | 7110 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); |
7148 expected_context.Clear(); | 7111 expected_context.Clear(); |
7149 v8::Debug::SetDebugEventListener(NULL); | 7112 v8::Debug::SetDebugEventListener2(NULL); |
7150 expected_context_data = v8::Handle<v8::Value>(); | 7113 expected_context_data = v8::Handle<v8::Value>(); |
7151 CheckDebuggerUnloaded(); | 7114 CheckDebuggerUnloaded(); |
7152 } | 7115 } |
7153 | 7116 |
7154 | 7117 |
7155 static void* expected_break_data; | 7118 static void* expected_break_data; |
7156 static bool was_debug_break_called; | 7119 static bool was_debug_break_called; |
7157 static bool was_debug_event_called; | 7120 static bool was_debug_event_called; |
7158 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) { | 7121 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) { |
7159 if (details.GetEvent() == v8::BreakForCommand) { | 7122 if (details.GetEvent() == v8::BreakForCommand) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7206 v8::Debug::DebugBreak(); | 7169 v8::Debug::DebugBreak(); |
7207 v8::Debug::DebugBreakForCommand(data2); | 7170 v8::Debug::DebugBreakForCommand(data2); |
7208 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run(); | 7171 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run(); |
7209 CHECK(was_debug_event_called); | 7172 CHECK(was_debug_event_called); |
7210 CHECK(was_debug_break_called); | 7173 CHECK(was_debug_break_called); |
7211 | 7174 |
7212 CHECK_EQ(2, TestClientData::constructor_call_counter); | 7175 CHECK_EQ(2, TestClientData::constructor_call_counter); |
7213 CHECK_EQ(TestClientData::constructor_call_counter, | 7176 CHECK_EQ(TestClientData::constructor_call_counter, |
7214 TestClientData::destructor_call_counter); | 7177 TestClientData::destructor_call_counter); |
7215 | 7178 |
7216 v8::Debug::SetDebugEventListener(NULL); | 7179 v8::Debug::SetDebugEventListener2(NULL); |
7217 CheckDebuggerUnloaded(); | 7180 CheckDebuggerUnloaded(); |
7218 } | 7181 } |
7219 | 7182 |
7220 static bool debug_event_break_deoptimize_done = false; | 7183 static bool debug_event_break_deoptimize_done = false; |
7221 | 7184 |
7222 static void DebugEventBreakDeoptimize(v8::DebugEvent event, | 7185 static void DebugEventBreakDeoptimize( |
7223 v8::Handle<v8::Object> exec_state, | 7186 const v8::Debug::EventDetails& event_details) { |
7224 v8::Handle<v8::Object> event_data, | 7187 v8::DebugEvent event = event_details.GetEvent(); |
7225 v8::Handle<v8::Value> data) { | 7188 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
7226 if (event == v8::Break) { | 7189 if (event == v8::Break) { |
7227 if (!frame_function_name.IsEmpty()) { | 7190 if (!frame_function_name.IsEmpty()) { |
7228 // Get the name of the function. | 7191 // Get the name of the function. |
7229 const int argc = 2; | 7192 const int argc = 2; |
7230 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; | 7193 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(0) }; |
7231 v8::Handle<v8::Value> result = | 7194 v8::Handle<v8::Value> result = |
7232 frame_function_name->Call(exec_state, argc, argv); | 7195 frame_function_name->Call(exec_state, argc, argv); |
7233 if (!result->IsUndefined()) { | 7196 if (!result->IsUndefined()) { |
7234 char fn[80]; | 7197 char fn[80]; |
7235 CHECK(result->IsString()); | 7198 CHECK(result->IsString()); |
(...skipping 22 matching lines...) Expand all Loading... |
7258 frame_function_name = CompileFunction(&env, | 7221 frame_function_name = CompileFunction(&env, |
7259 frame_function_name_source, | 7222 frame_function_name_source, |
7260 "frame_function_name"); | 7223 "frame_function_name"); |
7261 | 7224 |
7262 | 7225 |
7263 // Set a debug event listener which will keep interrupting execution until | 7226 // Set a debug event listener which will keep interrupting execution until |
7264 // debug break. When inside function bar it will deoptimize all functions. | 7227 // debug break. When inside function bar it will deoptimize all functions. |
7265 // This tests lazy deoptimization bailout for the stack check, as the first | 7228 // This tests lazy deoptimization bailout for the stack check, as the first |
7266 // time in function bar when using debug break and no break points will be at | 7229 // time in function bar when using debug break and no break points will be at |
7267 // the initial stack check. | 7230 // the initial stack check. |
7268 v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize, | 7231 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize); |
7269 v8::Undefined()); | |
7270 | 7232 |
7271 // Compile and run function bar which will optimize it for some flag settings. | 7233 // Compile and run function bar which will optimize it for some flag settings. |
7272 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run(); | 7234 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run(); |
7273 | 7235 |
7274 // Set debug break and call bar again. | 7236 // Set debug break and call bar again. |
7275 v8::Debug::DebugBreak(); | 7237 v8::Debug::DebugBreak(); |
7276 v8::Script::Compile(v8::String::New("bar()"))->Run(); | 7238 v8::Script::Compile(v8::String::New("bar()"))->Run(); |
7277 | 7239 |
7278 CHECK(debug_event_break_deoptimize_done); | 7240 CHECK(debug_event_break_deoptimize_done); |
7279 | 7241 |
7280 v8::Debug::SetDebugEventListener(NULL); | 7242 v8::Debug::SetDebugEventListener2(NULL); |
7281 } | 7243 } |
7282 | 7244 |
7283 | 7245 |
7284 static void DebugEventBreakWithOptimizedStack(v8::DebugEvent event, | 7246 static void DebugEventBreakWithOptimizedStack( |
7285 v8::Handle<v8::Object> exec_state, | 7247 const v8::Debug::EventDetails& event_details) { |
7286 v8::Handle<v8::Object> event_data, | 7248 v8::DebugEvent event = event_details.GetEvent(); |
7287 v8::Handle<v8::Value> data) { | 7249 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
7288 if (event == v8::Break) { | 7250 if (event == v8::Break) { |
7289 if (!frame_function_name.IsEmpty()) { | 7251 if (!frame_function_name.IsEmpty()) { |
7290 for (int i = 0; i < 2; i++) { | 7252 for (int i = 0; i < 2; i++) { |
7291 const int argc = 2; | 7253 const int argc = 2; |
7292 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(i) }; | 7254 v8::Handle<v8::Value> argv[argc] = { exec_state, v8::Integer::New(i) }; |
7293 // Get the name of the function in frame i. | 7255 // Get the name of the function in frame i. |
7294 v8::Handle<v8::Value> result = | 7256 v8::Handle<v8::Value> result = |
7295 frame_function_name->Call(exec_state, argc, argv); | 7257 frame_function_name->Call(exec_state, argc, argv); |
7296 CHECK(result->IsString()); | 7258 CHECK(result->IsString()); |
7297 v8::Handle<v8::String> function_name(result->ToString()); | 7259 v8::Handle<v8::String> function_name(result->ToString()); |
(...skipping 24 matching lines...) Expand all Loading... |
7322 // optimized frames. | 7284 // optimized frames. |
7323 result = frame_local_value->Call(exec_state, argc, argv); | 7285 result = frame_local_value->Call(exec_state, argc, argv); |
7324 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); | 7286 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); |
7325 } | 7287 } |
7326 } | 7288 } |
7327 } | 7289 } |
7328 } | 7290 } |
7329 | 7291 |
7330 | 7292 |
7331 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7293 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7332 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack, | 7294 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack); |
7333 v8::Undefined()); | |
7334 v8::Debug::DebugBreak(); | 7295 v8::Debug::DebugBreak(); |
7335 } | 7296 } |
7336 | 7297 |
7337 | 7298 |
7338 TEST(DebugBreakStackInspection) { | 7299 TEST(DebugBreakStackInspection) { |
7339 DebugLocalContext env; | 7300 DebugLocalContext env; |
7340 v8::HandleScope scope(env->GetIsolate()); | 7301 v8::HandleScope scope(env->GetIsolate()); |
7341 | 7302 |
7342 frame_function_name = | 7303 frame_function_name = |
7343 CompileFunction(&env, frame_function_name_source, "frame_function_name"); | 7304 CompileFunction(&env, frame_function_name_source, "frame_function_name"); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7406 } | 7367 } |
7407 } | 7368 } |
7408 } | 7369 } |
7409 | 7370 |
7410 | 7371 |
7411 TEST(DebugBreakLoop) { | 7372 TEST(DebugBreakLoop) { |
7412 DebugLocalContext env; | 7373 DebugLocalContext env; |
7413 v8::HandleScope scope(env->GetIsolate()); | 7374 v8::HandleScope scope(env->GetIsolate()); |
7414 | 7375 |
7415 // Register a debug event listener which sets the break flag and counts. | 7376 // Register a debug event listener which sets the break flag and counts. |
7416 v8::Debug::SetDebugEventListener(DebugEventBreakMax); | 7377 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); |
7417 | 7378 |
7418 // Create a function for getting the frame count when hitting the break. | 7379 // Create a function for getting the frame count when hitting the break. |
7419 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); | 7380 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); |
7420 | 7381 |
7421 CompileRun("var a = 1;"); | 7382 CompileRun("var a = 1;"); |
7422 CompileRun("function g() { }"); | 7383 CompileRun("function g() { }"); |
7423 CompileRun("function h() { }"); | 7384 CompileRun("function h() { }"); |
7424 | 7385 |
7425 const char* loop_bodies[] = { | 7386 const char* loop_bodies[] = { |
7426 "", | 7387 "", |
(...skipping 13 matching lines...) Expand all Loading... |
7440 TestDebugBreakInLoop("while (true) {", loop_bodies, "}"); | 7401 TestDebugBreakInLoop("while (true) {", loop_bodies, "}"); |
7441 TestDebugBreakInLoop("while (a == 1) {", loop_bodies, "}"); | 7402 TestDebugBreakInLoop("while (a == 1) {", loop_bodies, "}"); |
7442 | 7403 |
7443 TestDebugBreakInLoop("do {", loop_bodies, "} while (true)"); | 7404 TestDebugBreakInLoop("do {", loop_bodies, "} while (true)"); |
7444 TestDebugBreakInLoop("do {", loop_bodies, "} while (a == 1)"); | 7405 TestDebugBreakInLoop("do {", loop_bodies, "} while (a == 1)"); |
7445 | 7406 |
7446 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); | 7407 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); |
7447 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); | 7408 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); |
7448 | 7409 |
7449 // Get rid of the debug event listener. | 7410 // Get rid of the debug event listener. |
7450 v8::Debug::SetDebugEventListener(NULL); | 7411 v8::Debug::SetDebugEventListener2(NULL); |
7451 CheckDebuggerUnloaded(); | 7412 CheckDebuggerUnloaded(); |
7452 } | 7413 } |
7453 | 7414 |
7454 | 7415 |
7455 v8::Local<v8::Script> inline_script; | 7416 v8::Local<v8::Script> inline_script; |
7456 | 7417 |
7457 static void DebugBreakInlineListener(v8::DebugEvent event, | 7418 static void DebugBreakInlineListener( |
7458 v8::Handle<v8::Object> exec_state, | 7419 const v8::Debug::EventDetails& event_details) { |
7459 v8::Handle<v8::Object> event_data, | 7420 v8::DebugEvent event = event_details.GetEvent(); |
7460 v8::Handle<v8::Value> data) { | |
7461 if (event != v8::Break) return; | 7421 if (event != v8::Break) return; |
7462 | 7422 |
7463 int expected_frame_count = 4; | 7423 int expected_frame_count = 4; |
7464 int expected_line_number[] = {1, 4, 7, 12}; | 7424 int expected_line_number[] = {1, 4, 7, 12}; |
7465 | 7425 |
7466 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script); | 7426 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script); |
7467 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast( | 7427 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast( |
7468 i::JSFunction::cast(*compiled_script)->shared()->script())); | 7428 i::JSFunction::cast(*compiled_script)->shared()->script())); |
7469 | 7429 |
7470 int break_id = v8::internal::Isolate::Current()->debug()->break_id(); | 7430 int break_id = v8::internal::Isolate::Current()->debug()->break_id(); |
7471 char script[128]; | 7431 char script[128]; |
7472 i::Vector<char> script_vector(script, sizeof(script)); | 7432 i::Vector<char> script_vector(script, sizeof(script)); |
7473 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id); | 7433 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id); |
7474 v8::Local<v8::Value> result = CompileRun(script); | 7434 v8::Local<v8::Value> result = CompileRun(script); |
7475 | 7435 |
7476 int frame_count = result->Int32Value(); | 7436 int frame_count = result->Int32Value(); |
7477 CHECK_EQ(expected_frame_count, frame_count); | 7437 CHECK_EQ(expected_frame_count, frame_count); |
7478 | 7438 |
7479 for (int i = 0; i < frame_count; i++) { | 7439 for (int i = 0; i < frame_count; i++) { |
7480 // The 5. element in the returned array of GetFrameDetails contains the | 7440 // The 5. element in the returned array of GetFrameDetails contains the |
7481 // source position of that frame. | 7441 // source position of that frame. |
7482 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); | 7442 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); |
7483 v8::Local<v8::Value> result = CompileRun(script); | 7443 v8::Local<v8::Value> result = CompileRun(script); |
7484 CHECK_EQ(expected_line_number[i], | 7444 CHECK_EQ(expected_line_number[i], |
7485 i::GetScriptLineNumber(source_script, result->Int32Value())); | 7445 i::GetScriptLineNumber(source_script, result->Int32Value())); |
7486 } | 7446 } |
7487 v8::Debug::SetDebugEventListener(NULL); | 7447 v8::Debug::SetDebugEventListener2(NULL); |
7488 v8::V8::TerminateExecution(); | 7448 v8::V8::TerminateExecution(); |
7489 } | 7449 } |
7490 | 7450 |
7491 | 7451 |
7492 TEST(DebugBreakInline) { | 7452 TEST(DebugBreakInline) { |
7493 i::FLAG_allow_natives_syntax = true; | 7453 i::FLAG_allow_natives_syntax = true; |
7494 DebugLocalContext env; | 7454 DebugLocalContext env; |
7495 v8::HandleScope scope(env->GetIsolate()); | 7455 v8::HandleScope scope(env->GetIsolate()); |
7496 const char* source = | 7456 const char* source = |
7497 "function debug(b) { \n" | 7457 "function debug(b) { \n" |
7498 " if (b) debugger; \n" | 7458 " if (b) debugger; \n" |
7499 "} \n" | 7459 "} \n" |
7500 "function f(b) { \n" | 7460 "function f(b) { \n" |
7501 " debug(b) \n" | 7461 " debug(b) \n" |
7502 "}; \n" | 7462 "}; \n" |
7503 "function g(b) { \n" | 7463 "function g(b) { \n" |
7504 " f(b); \n" | 7464 " f(b); \n" |
7505 "}; \n" | 7465 "}; \n" |
7506 "g(false); \n" | 7466 "g(false); \n" |
7507 "g(false); \n" | 7467 "g(false); \n" |
7508 "%OptimizeFunctionOnNextCall(g); \n" | 7468 "%OptimizeFunctionOnNextCall(g); \n" |
7509 "g(true);"; | 7469 "g(true);"; |
7510 v8::Debug::SetDebugEventListener(DebugBreakInlineListener); | 7470 v8::Debug::SetDebugEventListener2(DebugBreakInlineListener); |
7511 inline_script = v8::Script::Compile(v8::String::New(source)); | 7471 inline_script = v8::Script::Compile(v8::String::New(source)); |
7512 inline_script->Run(); | 7472 inline_script->Run(); |
7513 } | 7473 } |
7514 | 7474 |
7515 | 7475 |
7516 static void DebugEventStepNext(v8::DebugEvent event, | 7476 static void DebugEventStepNext( |
7517 v8::Handle<v8::Object> exec_state, | 7477 const v8::Debug::EventDetails& event_details) { |
7518 v8::Handle<v8::Object> event_data, | 7478 v8::DebugEvent event = event_details.GetEvent(); |
7519 v8::Handle<v8::Value> data) { | |
7520 if (event == v8::Break) { | 7479 if (event == v8::Break) { |
7521 PrepareStep(StepNext); | 7480 PrepareStep(StepNext); |
7522 } | 7481 } |
7523 } | 7482 } |
7524 | 7483 |
7525 | 7484 |
7526 static void RunScriptInANewCFrame(const char* source) { | 7485 static void RunScriptInANewCFrame(const char* source) { |
7527 v8::TryCatch try_catch; | 7486 v8::TryCatch try_catch; |
7528 CompileRun(source); | 7487 CompileRun(source); |
7529 CHECK(try_catch.HasCaught()); | 7488 CHECK(try_catch.HasCaught()); |
7530 } | 7489 } |
7531 | 7490 |
7532 | 7491 |
7533 TEST(Regress131642) { | 7492 TEST(Regress131642) { |
7534 // Bug description: | 7493 // Bug description: |
7535 // When doing StepNext through the first script, the debugger is not reset | 7494 // When doing StepNext through the first script, the debugger is not reset |
7536 // after exiting through exception. A flawed implementation enabling the | 7495 // after exiting through exception. A flawed implementation enabling the |
7537 // debugger to step into Array.prototype.forEach breaks inside the callback | 7496 // debugger to step into Array.prototype.forEach breaks inside the callback |
7538 // for forEach in the second script under the assumption that we are in a | 7497 // for forEach in the second script under the assumption that we are in a |
7539 // recursive call. In an attempt to step out, we crawl the stack using the | 7498 // recursive call. In an attempt to step out, we crawl the stack using the |
7540 // recorded frame pointer from the first script and fail when not finding it | 7499 // recorded frame pointer from the first script and fail when not finding it |
7541 // on the stack. | 7500 // on the stack. |
7542 DebugLocalContext env; | 7501 DebugLocalContext env; |
7543 v8::HandleScope scope(env->GetIsolate()); | 7502 v8::HandleScope scope(env->GetIsolate()); |
7544 v8::Debug::SetDebugEventListener(DebugEventStepNext); | 7503 v8::Debug::SetDebugEventListener2(DebugEventStepNext); |
7545 | 7504 |
7546 // We step through the first script. It exits through an exception. We run | 7505 // We step through the first script. It exits through an exception. We run |
7547 // this inside a new frame to record a different FP than the second script | 7506 // this inside a new frame to record a different FP than the second script |
7548 // would expect. | 7507 // would expect. |
7549 const char* script_1 = "debugger; throw new Error();"; | 7508 const char* script_1 = "debugger; throw new Error();"; |
7550 RunScriptInANewCFrame(script_1); | 7509 RunScriptInANewCFrame(script_1); |
7551 | 7510 |
7552 // The second script uses forEach. | 7511 // The second script uses forEach. |
7553 const char* script_2 = "[0].forEach(function() { });"; | 7512 const char* script_2 = "[0].forEach(function() { });"; |
7554 CompileRun(script_2); | 7513 CompileRun(script_2); |
7555 | 7514 |
7556 v8::Debug::SetDebugEventListener(NULL); | 7515 v8::Debug::SetDebugEventListener2(NULL); |
7557 } | 7516 } |
7558 | 7517 |
7559 | 7518 |
7560 // Import from test-heap.cc | 7519 // Import from test-heap.cc |
7561 int CountNativeContexts(); | 7520 int CountNativeContexts(); |
7562 | 7521 |
7563 | 7522 |
7564 static void NopListener(v8::DebugEvent event, | 7523 static void NopListener(const v8::Debug::EventDetails& event_details) { |
7565 v8::Handle<v8::Object> exec_state, | |
7566 v8::Handle<v8::Object> event_data, | |
7567 v8::Handle<v8::Value> data) { | |
7568 } | 7524 } |
7569 | 7525 |
7570 | 7526 |
7571 TEST(DebuggerCreatesContextIffActive) { | 7527 TEST(DebuggerCreatesContextIffActive) { |
7572 DebugLocalContext env; | 7528 DebugLocalContext env; |
7573 v8::HandleScope scope(env->GetIsolate()); | 7529 v8::HandleScope scope(env->GetIsolate()); |
7574 CHECK_EQ(1, CountNativeContexts()); | 7530 CHECK_EQ(1, CountNativeContexts()); |
7575 | 7531 |
7576 v8::Debug::SetDebugEventListener(NULL); | 7532 v8::Debug::SetDebugEventListener2(NULL); |
7577 CompileRun("debugger;"); | 7533 CompileRun("debugger;"); |
7578 CHECK_EQ(1, CountNativeContexts()); | 7534 CHECK_EQ(1, CountNativeContexts()); |
7579 | 7535 |
7580 v8::Debug::SetDebugEventListener(NopListener); | 7536 v8::Debug::SetDebugEventListener2(NopListener); |
7581 CompileRun("debugger;"); | 7537 CompileRun("debugger;"); |
7582 CHECK_EQ(2, CountNativeContexts()); | 7538 CHECK_EQ(2, CountNativeContexts()); |
7583 | 7539 |
7584 v8::Debug::SetDebugEventListener(NULL); | 7540 v8::Debug::SetDebugEventListener2(NULL); |
7585 } | 7541 } |
7586 | 7542 |
7587 | 7543 |
7588 TEST(LiveEditEnabled) { | 7544 TEST(LiveEditEnabled) { |
7589 v8::internal::FLAG_allow_natives_syntax = true; | 7545 v8::internal::FLAG_allow_natives_syntax = true; |
7590 LocalContext env; | 7546 LocalContext env; |
7591 v8::HandleScope scope(env->GetIsolate()); | 7547 v8::HandleScope scope(env->GetIsolate()); |
7592 v8::Debug::SetLiveEditEnabled(true); | 7548 v8::Debug::SetLiveEditEnabled(true); |
7593 CompileRun("%LiveEditCompareStrings('', '')"); | 7549 CompileRun("%LiveEditCompareStrings('', '')"); |
7594 } | 7550 } |
7595 | 7551 |
7596 | 7552 |
7597 TEST(LiveEditDisabled) { | 7553 TEST(LiveEditDisabled) { |
7598 v8::internal::FLAG_allow_natives_syntax = true; | 7554 v8::internal::FLAG_allow_natives_syntax = true; |
7599 LocalContext env; | 7555 LocalContext env; |
7600 v8::HandleScope scope(env->GetIsolate()); | 7556 v8::HandleScope scope(env->GetIsolate()); |
7601 v8::Debug::SetLiveEditEnabled(false); | 7557 v8::Debug::SetLiveEditEnabled(false); |
7602 CompileRun("%LiveEditCompareStrings('', '')"); | 7558 CompileRun("%LiveEditCompareStrings('', '')"); |
7603 } | 7559 } |
7604 | 7560 |
7605 | 7561 |
7606 #endif // ENABLE_DEBUGGER_SUPPORT | 7562 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |