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

Side by Side Diff: test/cctest/test-debug.cc

Issue 1496493002: Pass explicit Isolate parameter to v8::Debug methods that need it (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 } 415 }
416 } 416 }
417 417
418 418
419 } // namespace internal 419 } // namespace internal
420 } // namespace v8 420 } // namespace v8
421 421
422 422
423 // Check that the debugger has been fully unloaded. 423 // Check that the debugger has been fully unloaded.
424 static void CheckDebuggerUnloaded(bool check_functions = false) { 424 static void CheckDebuggerUnloaded(v8::Isolate* isolate,
425 bool check_functions = false) {
425 // Let debugger to unload itself synchronously 426 // Let debugger to unload itself synchronously
426 v8::Debug::ProcessDebugMessages(); 427 v8::Debug::ProcessDebugMessages(isolate);
427 428
428 v8::internal::CheckDebuggerUnloaded(check_functions); 429 v8::internal::CheckDebuggerUnloaded(check_functions);
429 } 430 }
430 431
431 432
432 // --- D e b u g E v e n t H a n d l e r s 433 // --- D e b u g E v e n t H a n d l e r s
433 // --- 434 // ---
434 // --- The different tests uses a number of debug event handlers. 435 // --- The different tests uses a number of debug event handlers.
435 // --- 436 // ---
436 437
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 v8::HandleScope scope(env->GetIsolate()); 912 v8::HandleScope scope(env->GetIsolate());
912 // Create a couple of functions for the test. 913 // Create a couple of functions for the test.
913 v8::Local<v8::Function> foo = 914 v8::Local<v8::Function> foo =
914 CompileFunction(&env, "function foo(){}", "foo"); 915 CompileFunction(&env, "function foo(){}", "foo");
915 v8::Local<v8::Function> bar = 916 v8::Local<v8::Function> bar =
916 CompileFunction(&env, "function bar(){}", "bar"); 917 CompileFunction(&env, "function bar(){}", "bar");
917 // Initially no functions are debugged. 918 // Initially no functions are debugged.
918 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); 919 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
919 CHECK(!HasDebugInfo(foo)); 920 CHECK(!HasDebugInfo(foo));
920 CHECK(!HasDebugInfo(bar)); 921 CHECK(!HasDebugInfo(bar));
921 EnableDebugger(); 922 EnableDebugger(env->GetIsolate());
922 // One function (foo) is debugged. 923 // One function (foo) is debugged.
923 int bp1 = SetBreakPoint(foo, 0); 924 int bp1 = SetBreakPoint(foo, 0);
924 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length()); 925 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
925 CHECK(HasDebugInfo(foo)); 926 CHECK(HasDebugInfo(foo));
926 CHECK(!HasDebugInfo(bar)); 927 CHECK(!HasDebugInfo(bar));
927 // Two functions are debugged. 928 // Two functions are debugged.
928 int bp2 = SetBreakPoint(bar, 0); 929 int bp2 = SetBreakPoint(bar, 0);
929 CHECK_EQ(2, v8::internal::GetDebuggedFunctions()->length()); 930 CHECK_EQ(2, v8::internal::GetDebuggedFunctions()->length());
930 CHECK(HasDebugInfo(foo)); 931 CHECK(HasDebugInfo(foo));
931 CHECK(HasDebugInfo(bar)); 932 CHECK(HasDebugInfo(bar));
932 // One function (bar) is debugged. 933 // One function (bar) is debugged.
933 ClearBreakPoint(bp1); 934 ClearBreakPoint(bp1);
934 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length()); 935 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
935 CHECK(!HasDebugInfo(foo)); 936 CHECK(!HasDebugInfo(foo));
936 CHECK(HasDebugInfo(bar)); 937 CHECK(HasDebugInfo(bar));
937 // No functions are debugged. 938 // No functions are debugged.
938 ClearBreakPoint(bp2); 939 ClearBreakPoint(bp2);
939 DisableDebugger(); 940 DisableDebugger(env->GetIsolate());
940 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); 941 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
941 CHECK(!HasDebugInfo(foo)); 942 CHECK(!HasDebugInfo(foo));
942 CHECK(!HasDebugInfo(bar)); 943 CHECK(!HasDebugInfo(bar));
943 } 944 }
944 945
945 946
946 // Test that a break point can be set at an IC store location. 947 // Test that a break point can be set at an IC store location.
947 TEST(BreakPointICStore) { 948 TEST(BreakPointICStore) {
948 break_point_hit_count = 0; 949 break_point_hit_count = 0;
949 DebugLocalContext env; 950 DebugLocalContext env;
950 v8::HandleScope scope(env->GetIsolate()); 951 v8::HandleScope scope(env->GetIsolate());
951 952
952 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 953 v8::Debug::SetDebugEventListener(env->GetIsolate(),
954 DebugEventBreakPointHitCount);
953 v8::Local<v8::Function> foo = 955 v8::Local<v8::Function> foo =
954 CompileFunction(&env, "function foo(){bar=0;}", "foo"); 956 CompileFunction(&env, "function foo(){bar=0;}", "foo");
955 957
956 // Run without breakpoints. 958 // Run without breakpoints.
957 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 959 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
958 CHECK_EQ(0, break_point_hit_count); 960 CHECK_EQ(0, break_point_hit_count);
959 961
960 // Run with breakpoint 962 // Run with breakpoint
961 int bp = SetBreakPoint(foo, 0); 963 int bp = SetBreakPoint(foo, 0);
962 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 964 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
963 CHECK_EQ(1, break_point_hit_count); 965 CHECK_EQ(1, break_point_hit_count);
964 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 966 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
965 CHECK_EQ(2, break_point_hit_count); 967 CHECK_EQ(2, break_point_hit_count);
966 968
967 // Run without breakpoints. 969 // Run without breakpoints.
968 ClearBreakPoint(bp); 970 ClearBreakPoint(bp);
969 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 971 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
970 CHECK_EQ(2, break_point_hit_count); 972 CHECK_EQ(2, break_point_hit_count);
971 973
972 v8::Debug::SetDebugEventListener(NULL); 974 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
973 CheckDebuggerUnloaded(); 975 CheckDebuggerUnloaded(env->GetIsolate());
974 } 976 }
975 977
976 978
977 // Test that a break point can be set at an IC load location. 979 // Test that a break point can be set at an IC load location.
978 TEST(BreakPointICLoad) { 980 TEST(BreakPointICLoad) {
979 break_point_hit_count = 0; 981 break_point_hit_count = 0;
980 DebugLocalContext env; 982 DebugLocalContext env;
981 v8::HandleScope scope(env->GetIsolate()); 983 v8::HandleScope scope(env->GetIsolate());
982 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 984 v8::Debug::SetDebugEventListener(env->GetIsolate(),
985 DebugEventBreakPointHitCount);
983 986
984 CompileRunChecked(env->GetIsolate(), "bar=1"); 987 CompileRunChecked(env->GetIsolate(), "bar=1");
985 v8::Local<v8::Function> foo = 988 v8::Local<v8::Function> foo =
986 CompileFunction(&env, "function foo(){var x=bar;}", "foo"); 989 CompileFunction(&env, "function foo(){var x=bar;}", "foo");
987 990
988 // Run without breakpoints. 991 // Run without breakpoints.
989 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 992 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
990 CHECK_EQ(0, break_point_hit_count); 993 CHECK_EQ(0, break_point_hit_count);
991 994
992 // Run with breakpoint. 995 // Run with breakpoint.
993 int bp = SetBreakPoint(foo, 0); 996 int bp = SetBreakPoint(foo, 0);
994 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 997 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
995 CHECK_EQ(1, break_point_hit_count); 998 CHECK_EQ(1, break_point_hit_count);
996 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 999 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
997 CHECK_EQ(2, break_point_hit_count); 1000 CHECK_EQ(2, break_point_hit_count);
998 1001
999 // Run without breakpoints. 1002 // Run without breakpoints.
1000 ClearBreakPoint(bp); 1003 ClearBreakPoint(bp);
1001 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1004 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1002 CHECK_EQ(2, break_point_hit_count); 1005 CHECK_EQ(2, break_point_hit_count);
1003 1006
1004 v8::Debug::SetDebugEventListener(NULL); 1007 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1005 CheckDebuggerUnloaded(); 1008 CheckDebuggerUnloaded(env->GetIsolate());
1006 } 1009 }
1007 1010
1008 1011
1009 // Test that a break point can be set at an IC call location. 1012 // Test that a break point can be set at an IC call location.
1010 TEST(BreakPointICCall) { 1013 TEST(BreakPointICCall) {
1011 break_point_hit_count = 0; 1014 break_point_hit_count = 0;
1012 DebugLocalContext env; 1015 DebugLocalContext env;
1013 v8::HandleScope scope(env->GetIsolate()); 1016 v8::HandleScope scope(env->GetIsolate());
1014 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1017 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1018 DebugEventBreakPointHitCount);
1015 CompileRunChecked(env->GetIsolate(), "function bar(){}"); 1019 CompileRunChecked(env->GetIsolate(), "function bar(){}");
1016 v8::Local<v8::Function> foo = 1020 v8::Local<v8::Function> foo =
1017 CompileFunction(&env, "function foo(){bar();}", "foo"); 1021 CompileFunction(&env, "function foo(){bar();}", "foo");
1018 1022
1019 // Run without breakpoints. 1023 // Run without breakpoints.
1020 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1024 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1021 CHECK_EQ(0, break_point_hit_count); 1025 CHECK_EQ(0, break_point_hit_count);
1022 1026
1023 // Run with breakpoint 1027 // Run with breakpoint
1024 int bp = SetBreakPoint(foo, 0); 1028 int bp = SetBreakPoint(foo, 0);
1025 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1029 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1026 CHECK_EQ(1, break_point_hit_count); 1030 CHECK_EQ(1, break_point_hit_count);
1027 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1031 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1028 CHECK_EQ(2, break_point_hit_count); 1032 CHECK_EQ(2, break_point_hit_count);
1029 1033
1030 // Run without breakpoints. 1034 // Run without breakpoints.
1031 ClearBreakPoint(bp); 1035 ClearBreakPoint(bp);
1032 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1036 foo->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1033 CHECK_EQ(2, break_point_hit_count); 1037 CHECK_EQ(2, break_point_hit_count);
1034 1038
1035 v8::Debug::SetDebugEventListener(NULL); 1039 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1036 CheckDebuggerUnloaded(); 1040 CheckDebuggerUnloaded(env->GetIsolate());
1037 } 1041 }
1038 1042
1039 1043
1040 // Test that a break point can be set at an IC call location and survive a GC. 1044 // Test that a break point can be set at an IC call location and survive a GC.
1041 TEST(BreakPointICCallWithGC) { 1045 TEST(BreakPointICCallWithGC) {
1042 break_point_hit_count = 0; 1046 break_point_hit_count = 0;
1043 DebugLocalContext env; 1047 DebugLocalContext env;
1044 v8::HandleScope scope(env->GetIsolate()); 1048 v8::HandleScope scope(env->GetIsolate());
1045 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); 1049 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1050 DebugEventBreakPointCollectGarbage);
1046 CompileRunChecked(env->GetIsolate(), "function bar(){return 1;}"); 1051 CompileRunChecked(env->GetIsolate(), "function bar(){return 1;}");
1047 v8::Local<v8::Function> foo = 1052 v8::Local<v8::Function> foo =
1048 CompileFunction(&env, "function foo(){return bar();}", "foo"); 1053 CompileFunction(&env, "function foo(){return bar();}", "foo");
1049 v8::Local<v8::Context> context = env.context(); 1054 v8::Local<v8::Context> context = env.context();
1050 1055
1051 // Run without breakpoints. 1056 // Run without breakpoints.
1052 CHECK_EQ(1, foo->Call(context, env->Global(), 0, NULL) 1057 CHECK_EQ(1, foo->Call(context, env->Global(), 0, NULL)
1053 .ToLocalChecked() 1058 .ToLocalChecked()
1054 ->Int32Value(context) 1059 ->Int32Value(context)
1055 .FromJust()); 1060 .FromJust());
(...skipping 10 matching lines...) Expand all
1066 .ToLocalChecked() 1071 .ToLocalChecked()
1067 ->Int32Value(context) 1072 ->Int32Value(context)
1068 .FromJust()); 1073 .FromJust());
1069 CHECK_EQ(2, break_point_hit_count); 1074 CHECK_EQ(2, break_point_hit_count);
1070 1075
1071 // Run without breakpoints. 1076 // Run without breakpoints.
1072 ClearBreakPoint(bp); 1077 ClearBreakPoint(bp);
1073 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1078 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1074 CHECK_EQ(2, break_point_hit_count); 1079 CHECK_EQ(2, break_point_hit_count);
1075 1080
1076 v8::Debug::SetDebugEventListener(NULL); 1081 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1077 CheckDebuggerUnloaded(); 1082 CheckDebuggerUnloaded(env->GetIsolate());
1078 } 1083 }
1079 1084
1080 1085
1081 // Test that a break point can be set at an IC call location and survive a GC. 1086 // Test that a break point can be set at an IC call location and survive a GC.
1082 TEST(BreakPointConstructCallWithGC) { 1087 TEST(BreakPointConstructCallWithGC) {
1083 break_point_hit_count = 0; 1088 break_point_hit_count = 0;
1084 DebugLocalContext env; 1089 DebugLocalContext env;
1085 v8::HandleScope scope(env->GetIsolate()); 1090 v8::HandleScope scope(env->GetIsolate());
1086 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); 1091 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1092 DebugEventBreakPointCollectGarbage);
1087 CompileRunChecked(env->GetIsolate(), "function bar(){ this.x = 1;}"); 1093 CompileRunChecked(env->GetIsolate(), "function bar(){ this.x = 1;}");
1088 v8::Local<v8::Function> foo = 1094 v8::Local<v8::Function> foo =
1089 CompileFunction(&env, "function foo(){return new bar(1).x;}", "foo"); 1095 CompileFunction(&env, "function foo(){return new bar(1).x;}", "foo");
1090 v8::Local<v8::Context> context = env.context(); 1096 v8::Local<v8::Context> context = env.context();
1091 1097
1092 // Run without breakpoints. 1098 // Run without breakpoints.
1093 CHECK_EQ(1, foo->Call(context, env->Global(), 0, NULL) 1099 CHECK_EQ(1, foo->Call(context, env->Global(), 0, NULL)
1094 .ToLocalChecked() 1100 .ToLocalChecked()
1095 ->Int32Value(context) 1101 ->Int32Value(context)
1096 .FromJust()); 1102 .FromJust());
(...skipping 10 matching lines...) Expand all
1107 .ToLocalChecked() 1113 .ToLocalChecked()
1108 ->Int32Value(context) 1114 ->Int32Value(context)
1109 .FromJust()); 1115 .FromJust());
1110 CHECK_EQ(2, break_point_hit_count); 1116 CHECK_EQ(2, break_point_hit_count);
1111 1117
1112 // Run without breakpoints. 1118 // Run without breakpoints.
1113 ClearBreakPoint(bp); 1119 ClearBreakPoint(bp);
1114 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1120 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1115 CHECK_EQ(2, break_point_hit_count); 1121 CHECK_EQ(2, break_point_hit_count);
1116 1122
1117 v8::Debug::SetDebugEventListener(NULL); 1123 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1118 CheckDebuggerUnloaded(); 1124 CheckDebuggerUnloaded(env->GetIsolate());
1119 } 1125 }
1120 1126
1121 1127
1122 // Test that a break point can be set at a return store location. 1128 // Test that a break point can be set at a return store location.
1123 TEST(BreakPointReturn) { 1129 TEST(BreakPointReturn) {
1124 break_point_hit_count = 0; 1130 break_point_hit_count = 0;
1125 DebugLocalContext env; 1131 DebugLocalContext env;
1126 v8::HandleScope scope(env->GetIsolate()); 1132 v8::HandleScope scope(env->GetIsolate());
1127 1133
1128 // Create a functions for checking the source line and column when hitting 1134 // Create a functions for checking the source line and column when hitting
1129 // a break point. 1135 // a break point.
1130 frame_source_line = CompileFunction(&env, 1136 frame_source_line = CompileFunction(&env,
1131 frame_source_line_source, 1137 frame_source_line_source,
1132 "frame_source_line"); 1138 "frame_source_line");
1133 frame_source_column = CompileFunction(&env, 1139 frame_source_column = CompileFunction(&env,
1134 frame_source_column_source, 1140 frame_source_column_source,
1135 "frame_source_column"); 1141 "frame_source_column");
1136 1142
1137 1143
1138 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1144 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1145 DebugEventBreakPointHitCount);
1139 v8::Local<v8::Function> foo = 1146 v8::Local<v8::Function> foo =
1140 CompileFunction(&env, "function foo(){}", "foo"); 1147 CompileFunction(&env, "function foo(){}", "foo");
1141 v8::Local<v8::Context> context = env.context(); 1148 v8::Local<v8::Context> context = env.context();
1142 1149
1143 // Run without breakpoints. 1150 // Run without breakpoints.
1144 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1151 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1145 CHECK_EQ(0, break_point_hit_count); 1152 CHECK_EQ(0, break_point_hit_count);
1146 1153
1147 // Run with breakpoint 1154 // Run with breakpoint
1148 int bp = SetBreakPoint(foo, 0); 1155 int bp = SetBreakPoint(foo, 0);
1149 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1156 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1150 CHECK_EQ(1, break_point_hit_count); 1157 CHECK_EQ(1, break_point_hit_count);
1151 CHECK_EQ(0, last_source_line); 1158 CHECK_EQ(0, last_source_line);
1152 CHECK_EQ(15, last_source_column); 1159 CHECK_EQ(15, last_source_column);
1153 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1160 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1154 CHECK_EQ(2, break_point_hit_count); 1161 CHECK_EQ(2, break_point_hit_count);
1155 CHECK_EQ(0, last_source_line); 1162 CHECK_EQ(0, last_source_line);
1156 CHECK_EQ(15, last_source_column); 1163 CHECK_EQ(15, last_source_column);
1157 1164
1158 // Run without breakpoints. 1165 // Run without breakpoints.
1159 ClearBreakPoint(bp); 1166 ClearBreakPoint(bp);
1160 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1167 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1161 CHECK_EQ(2, break_point_hit_count); 1168 CHECK_EQ(2, break_point_hit_count);
1162 1169
1163 v8::Debug::SetDebugEventListener(NULL); 1170 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1164 CheckDebuggerUnloaded(); 1171 CheckDebuggerUnloaded(env->GetIsolate());
1165 } 1172 }
1166 1173
1167 1174
1168 static void CallWithBreakPoints(v8::Local<v8::Context> context, 1175 static void CallWithBreakPoints(v8::Local<v8::Context> context,
1169 v8::Local<v8::Object> recv, 1176 v8::Local<v8::Object> recv,
1170 v8::Local<v8::Function> f, 1177 v8::Local<v8::Function> f,
1171 int break_point_count, int call_count) { 1178 int break_point_count, int call_count) {
1172 break_point_hit_count = 0; 1179 break_point_hit_count = 0;
1173 for (int i = 0; i < call_count; i++) { 1180 for (int i = 0; i < call_count; i++) {
1174 f->Call(context, recv, 0, NULL).ToLocalChecked(); 1181 f->Call(context, recv, 0, NULL).ToLocalChecked();
1175 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); 1182 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count);
1176 } 1183 }
1177 } 1184 }
1178 1185
1179 1186
1180 // Test GC during break point processing. 1187 // Test GC during break point processing.
1181 TEST(GCDuringBreakPointProcessing) { 1188 TEST(GCDuringBreakPointProcessing) {
1182 break_point_hit_count = 0; 1189 break_point_hit_count = 0;
1183 DebugLocalContext env; 1190 DebugLocalContext env;
1184 v8::HandleScope scope(env->GetIsolate()); 1191 v8::HandleScope scope(env->GetIsolate());
1185 v8::Local<v8::Context> context = env.context(); 1192 v8::Local<v8::Context> context = env.context();
1186 1193
1187 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); 1194 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1195 DebugEventBreakPointCollectGarbage);
1188 v8::Local<v8::Function> foo; 1196 v8::Local<v8::Function> foo;
1189 1197
1190 // Test IC store break point with garbage collection. 1198 // Test IC store break point with garbage collection.
1191 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); 1199 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
1192 SetBreakPoint(foo, 0); 1200 SetBreakPoint(foo, 0);
1193 CallWithBreakPoints(context, env->Global(), foo, 1, 10); 1201 CallWithBreakPoints(context, env->Global(), foo, 1, 10);
1194 1202
1195 // Test IC load break point with garbage collection. 1203 // Test IC load break point with garbage collection.
1196 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); 1204 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo");
1197 SetBreakPoint(foo, 0); 1205 SetBreakPoint(foo, 0);
1198 CallWithBreakPoints(context, env->Global(), foo, 1, 10); 1206 CallWithBreakPoints(context, env->Global(), foo, 1, 10);
1199 1207
1200 // Test IC call break point with garbage collection. 1208 // Test IC call break point with garbage collection.
1201 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); 1209 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo");
1202 SetBreakPoint(foo, 0); 1210 SetBreakPoint(foo, 0);
1203 CallWithBreakPoints(context, env->Global(), foo, 1, 10); 1211 CallWithBreakPoints(context, env->Global(), foo, 1, 10);
1204 1212
1205 // Test return break point with garbage collection. 1213 // Test return break point with garbage collection.
1206 foo = CompileFunction(&env, "function foo(){}", "foo"); 1214 foo = CompileFunction(&env, "function foo(){}", "foo");
1207 SetBreakPoint(foo, 0); 1215 SetBreakPoint(foo, 0);
1208 CallWithBreakPoints(context, env->Global(), foo, 1, 25); 1216 CallWithBreakPoints(context, env->Global(), foo, 1, 25);
1209 1217
1210 // Test debug break slot break point with garbage collection. 1218 // Test debug break slot break point with garbage collection.
1211 foo = CompileFunction(&env, "function foo(){var a;}", "foo"); 1219 foo = CompileFunction(&env, "function foo(){var a;}", "foo");
1212 SetBreakPoint(foo, 0); 1220 SetBreakPoint(foo, 0);
1213 CallWithBreakPoints(context, env->Global(), foo, 1, 25); 1221 CallWithBreakPoints(context, env->Global(), foo, 1, 25);
1214 1222
1215 v8::Debug::SetDebugEventListener(NULL); 1223 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1216 CheckDebuggerUnloaded(); 1224 CheckDebuggerUnloaded(env->GetIsolate());
1217 } 1225 }
1218 1226
1219 1227
1220 // Call the function three times with different garbage collections in between 1228 // Call the function three times with different garbage collections in between
1221 // and make sure that the break point survives. 1229 // and make sure that the break point survives.
1222 static void CallAndGC(v8::Local<v8::Context> context, 1230 static void CallAndGC(v8::Local<v8::Context> context,
1223 v8::Local<v8::Object> recv, v8::Local<v8::Function> f) { 1231 v8::Local<v8::Object> recv, v8::Local<v8::Function> f) {
1224 break_point_hit_count = 0; 1232 break_point_hit_count = 0;
1225 1233
1226 for (int i = 0; i < 3; i++) { 1234 for (int i = 0; i < 3; i++) {
(...skipping 14 matching lines...) Expand all
1241 } 1249 }
1242 1250
1243 1251
1244 // Test that a break point can be set at a return store location. 1252 // Test that a break point can be set at a return store location.
1245 TEST(BreakPointSurviveGC) { 1253 TEST(BreakPointSurviveGC) {
1246 break_point_hit_count = 0; 1254 break_point_hit_count = 0;
1247 DebugLocalContext env; 1255 DebugLocalContext env;
1248 v8::HandleScope scope(env->GetIsolate()); 1256 v8::HandleScope scope(env->GetIsolate());
1249 v8::Local<v8::Context> context = env.context(); 1257 v8::Local<v8::Context> context = env.context();
1250 1258
1251 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1259 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1260 DebugEventBreakPointHitCount);
1252 v8::Local<v8::Function> foo; 1261 v8::Local<v8::Function> foo;
1253 1262
1254 // Test IC store break point with garbage collection. 1263 // Test IC store break point with garbage collection.
1255 { 1264 {
1256 CompileFunction(&env, "function foo(){}", "foo"); 1265 CompileFunction(&env, "function foo(){}", "foo");
1257 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); 1266 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
1258 SetBreakPoint(foo, 0); 1267 SetBreakPoint(foo, 0);
1259 } 1268 }
1260 CallAndGC(context, env->Global(), foo); 1269 CallAndGC(context, env->Global(), foo);
1261 1270
(...skipping 25 matching lines...) Expand all
1287 1296
1288 // Test non IC break point with garbage collection. 1297 // Test non IC break point with garbage collection.
1289 { 1298 {
1290 CompileFunction(&env, "function foo(){}", "foo"); 1299 CompileFunction(&env, "function foo(){}", "foo");
1291 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); 1300 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo");
1292 SetBreakPoint(foo, 0); 1301 SetBreakPoint(foo, 0);
1293 } 1302 }
1294 CallAndGC(context, env->Global(), foo); 1303 CallAndGC(context, env->Global(), foo);
1295 1304
1296 1305
1297 v8::Debug::SetDebugEventListener(NULL); 1306 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1298 CheckDebuggerUnloaded(); 1307 CheckDebuggerUnloaded(env->GetIsolate());
1299 } 1308 }
1300 1309
1301 1310
1302 // Test that break points can be set using the global Debug object. 1311 // Test that break points can be set using the global Debug object.
1303 TEST(BreakPointThroughJavaScript) { 1312 TEST(BreakPointThroughJavaScript) {
1304 break_point_hit_count = 0; 1313 break_point_hit_count = 0;
1305 DebugLocalContext env; 1314 DebugLocalContext env;
1306 v8::Isolate* isolate = env->GetIsolate(); 1315 v8::Isolate* isolate = env->GetIsolate();
1307 v8::HandleScope scope(isolate); 1316 v8::HandleScope scope(isolate);
1308 v8::Local<v8::Context> context = env.context(); 1317 v8::Local<v8::Context> context = env.context();
1309 env.ExposeDebug(); 1318 env.ExposeDebug();
1310 1319
1311 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1320 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
1312 CompileRunChecked(isolate, "function bar(){}"); 1321 CompileRunChecked(isolate, "function bar(){}");
1313 CompileFunction(isolate, "function foo(){bar();bar();}", "foo"); 1322 CompileFunction(isolate, "function foo(){bar();bar();}", "foo");
1314 // 012345678901234567890 1323 // 012345678901234567890
1315 // 1 2 1324 // 1 2
1316 // Break points are set at position 3 and 9 1325 // Break points are set at position 3 and 9
1317 v8::Local<v8::String> source = v8_str(env->GetIsolate(), "foo()"); 1326 v8::Local<v8::String> source = v8_str(env->GetIsolate(), "foo()");
1318 v8::Local<v8::Script> foo = 1327 v8::Local<v8::Script> foo =
1319 v8::Script::Compile(context, source).ToLocalChecked(); 1328 v8::Script::Compile(context, source).ToLocalChecked();
1320 1329
1321 CHECK_EQ(0, break_point_hit_count); 1330 CHECK_EQ(0, break_point_hit_count);
(...skipping 17 matching lines...) Expand all
1339 foo->Run(context).ToLocalChecked(); 1348 foo->Run(context).ToLocalChecked();
1340 CHECK_EQ(7, break_point_hit_count); 1349 CHECK_EQ(7, break_point_hit_count);
1341 foo->Run(context).ToLocalChecked(); 1350 foo->Run(context).ToLocalChecked();
1342 CHECK_EQ(8, break_point_hit_count); 1351 CHECK_EQ(8, break_point_hit_count);
1343 1352
1344 // Run without breakpoints. 1353 // Run without breakpoints.
1345 ClearBreakPointFromJS(env->GetIsolate(), bp1); 1354 ClearBreakPointFromJS(env->GetIsolate(), bp1);
1346 foo->Run(context).ToLocalChecked(); 1355 foo->Run(context).ToLocalChecked();
1347 CHECK_EQ(8, break_point_hit_count); 1356 CHECK_EQ(8, break_point_hit_count);
1348 1357
1349 v8::Debug::SetDebugEventListener(NULL); 1358 v8::Debug::SetDebugEventListener(isolate, nullptr);
1350 CheckDebuggerUnloaded(); 1359 CheckDebuggerUnloaded(isolate);
1351 1360
1352 // Make sure that the break point numbers are consecutive. 1361 // Make sure that the break point numbers are consecutive.
1353 CHECK_EQ(1, bp1); 1362 CHECK_EQ(1, bp1);
1354 CHECK_EQ(2, bp2); 1363 CHECK_EQ(2, bp2);
1355 } 1364 }
1356 1365
1357 1366
1358 // Test that break points on scripts identified by name can be set using the 1367 // Test that break points on scripts identified by name can be set using the
1359 // global Debug object. 1368 // global Debug object.
1360 TEST(ScriptBreakPointByNameThroughJavaScript) { 1369 TEST(ScriptBreakPointByNameThroughJavaScript) {
1361 break_point_hit_count = 0; 1370 break_point_hit_count = 0;
1362 DebugLocalContext env; 1371 DebugLocalContext env;
1363 v8::Isolate* isolate = env->GetIsolate(); 1372 v8::Isolate* isolate = env->GetIsolate();
1364 v8::HandleScope scope(isolate); 1373 v8::HandleScope scope(isolate);
1365 v8::Local<v8::Context> context = env.context(); 1374 v8::Local<v8::Context> context = env.context();
1366 env.ExposeDebug(); 1375 env.ExposeDebug();
1367 1376
1368 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1377 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
1369 1378
1370 v8::Local<v8::String> script = v8_str(isolate, 1379 v8::Local<v8::String> script = v8_str(isolate,
1371 "function f() {\n" 1380 "function f() {\n"
1372 " function h() {\n" 1381 " function h() {\n"
1373 " a = 0; // line 2\n" 1382 " a = 0; // line 2\n"
1374 " }\n" 1383 " }\n"
1375 " b = 1; // line 4\n" 1384 " b = 1; // line 4\n"
1376 " return h();\n" 1385 " return h();\n"
1377 "}\n" 1386 "}\n"
1378 "\n" 1387 "\n"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 ClearBreakPointFromJS(isolate, sbp2); 1453 ClearBreakPointFromJS(isolate, sbp2);
1445 ClearBreakPointFromJS(isolate, sbp3); 1454 ClearBreakPointFromJS(isolate, sbp3);
1446 ClearBreakPointFromJS(isolate, sbp4); 1455 ClearBreakPointFromJS(isolate, sbp4);
1447 ClearBreakPointFromJS(isolate, sbp5); 1456 ClearBreakPointFromJS(isolate, sbp5);
1448 ClearBreakPointFromJS(isolate, sbp6); 1457 ClearBreakPointFromJS(isolate, sbp6);
1449 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1458 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1450 CHECK_EQ(0, break_point_hit_count); 1459 CHECK_EQ(0, break_point_hit_count);
1451 g->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1460 g->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1452 CHECK_EQ(0, break_point_hit_count); 1461 CHECK_EQ(0, break_point_hit_count);
1453 1462
1454 v8::Debug::SetDebugEventListener(NULL); 1463 v8::Debug::SetDebugEventListener(isolate, nullptr);
1455 CheckDebuggerUnloaded(); 1464 CheckDebuggerUnloaded(isolate);
1456 1465
1457 // Make sure that the break point numbers are consecutive. 1466 // Make sure that the break point numbers are consecutive.
1458 CHECK_EQ(1, sbp1); 1467 CHECK_EQ(1, sbp1);
1459 CHECK_EQ(2, sbp2); 1468 CHECK_EQ(2, sbp2);
1460 CHECK_EQ(3, sbp3); 1469 CHECK_EQ(3, sbp3);
1461 CHECK_EQ(4, sbp4); 1470 CHECK_EQ(4, sbp4);
1462 CHECK_EQ(5, sbp5); 1471 CHECK_EQ(5, sbp5);
1463 CHECK_EQ(6, sbp6); 1472 CHECK_EQ(6, sbp6);
1464 } 1473 }
1465 1474
1466 1475
1467 TEST(ScriptBreakPointByIdThroughJavaScript) { 1476 TEST(ScriptBreakPointByIdThroughJavaScript) {
1468 break_point_hit_count = 0; 1477 break_point_hit_count = 0;
1469 DebugLocalContext env; 1478 DebugLocalContext env;
1470 v8::Isolate* isolate = env->GetIsolate(); 1479 v8::Isolate* isolate = env->GetIsolate();
1471 v8::HandleScope scope(isolate); 1480 v8::HandleScope scope(isolate);
1472 v8::Local<v8::Context> context = env.context(); 1481 v8::Local<v8::Context> context = env.context();
1473 env.ExposeDebug(); 1482 env.ExposeDebug();
1474 1483
1475 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1484 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
1476 1485
1477 v8::Local<v8::String> source = v8_str(isolate, 1486 v8::Local<v8::String> source = v8_str(isolate,
1478 "function f() {\n" 1487 "function f() {\n"
1479 " function h() {\n" 1488 " function h() {\n"
1480 " a = 0; // line 2\n" 1489 " a = 0; // line 2\n"
1481 " }\n" 1490 " }\n"
1482 " b = 1; // line 4\n" 1491 " b = 1; // line 4\n"
1483 " return h();\n" 1492 " return h();\n"
1484 "}\n" 1493 "}\n"
1485 "\n" 1494 "\n"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 ClearBreakPointFromJS(env->GetIsolate(), sbp2); 1562 ClearBreakPointFromJS(env->GetIsolate(), sbp2);
1554 ClearBreakPointFromJS(env->GetIsolate(), sbp3); 1563 ClearBreakPointFromJS(env->GetIsolate(), sbp3);
1555 ClearBreakPointFromJS(env->GetIsolate(), sbp4); 1564 ClearBreakPointFromJS(env->GetIsolate(), sbp4);
1556 ClearBreakPointFromJS(env->GetIsolate(), sbp5); 1565 ClearBreakPointFromJS(env->GetIsolate(), sbp5);
1557 ClearBreakPointFromJS(env->GetIsolate(), sbp6); 1566 ClearBreakPointFromJS(env->GetIsolate(), sbp6);
1558 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1567 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1559 CHECK_EQ(0, break_point_hit_count); 1568 CHECK_EQ(0, break_point_hit_count);
1560 g->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1569 g->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1561 CHECK_EQ(0, break_point_hit_count); 1570 CHECK_EQ(0, break_point_hit_count);
1562 1571
1563 v8::Debug::SetDebugEventListener(NULL); 1572 v8::Debug::SetDebugEventListener(isolate, nullptr);
1564 CheckDebuggerUnloaded(); 1573 CheckDebuggerUnloaded(isolate);
1565 1574
1566 // Make sure that the break point numbers are consecutive. 1575 // Make sure that the break point numbers are consecutive.
1567 CHECK_EQ(1, sbp1); 1576 CHECK_EQ(1, sbp1);
1568 CHECK_EQ(2, sbp2); 1577 CHECK_EQ(2, sbp2);
1569 CHECK_EQ(3, sbp3); 1578 CHECK_EQ(3, sbp3);
1570 CHECK_EQ(4, sbp4); 1579 CHECK_EQ(4, sbp4);
1571 CHECK_EQ(5, sbp5); 1580 CHECK_EQ(5, sbp5);
1572 CHECK_EQ(6, sbp6); 1581 CHECK_EQ(6, sbp6);
1573 } 1582 }
1574 1583
1575 1584
1576 // Test conditional script break points. 1585 // Test conditional script break points.
1577 TEST(EnableDisableScriptBreakPoint) { 1586 TEST(EnableDisableScriptBreakPoint) {
1578 break_point_hit_count = 0; 1587 break_point_hit_count = 0;
1579 DebugLocalContext env; 1588 DebugLocalContext env;
1580 v8::Isolate* isolate = env->GetIsolate(); 1589 v8::Isolate* isolate = env->GetIsolate();
1581 v8::HandleScope scope(isolate); 1590 v8::HandleScope scope(isolate);
1582 v8::Local<v8::Context> context = env.context(); 1591 v8::Local<v8::Context> context = env.context();
1583 env.ExposeDebug(); 1592 env.ExposeDebug();
1584 1593
1585 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1594 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
1586 1595
1587 v8::Local<v8::String> script = v8_str(isolate, 1596 v8::Local<v8::String> script = v8_str(isolate,
1588 "function f() {\n" 1597 "function f() {\n"
1589 " a = 0; // line 1\n" 1598 " a = 0; // line 1\n"
1590 "};"); 1599 "};");
1591 1600
1592 // Compile the script and get function f. 1601 // Compile the script and get function f.
1593 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(isolate, "test")); 1602 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(isolate, "test"));
1594 v8::Script::Compile(context, script, &origin) 1603 v8::Script::Compile(context, script, &origin)
1595 .ToLocalChecked() 1604 .ToLocalChecked()
(...skipping 29 matching lines...) Expand all
1625 .ToLocalChecked(); 1634 .ToLocalChecked();
1626 f = v8::Local<v8::Function>::Cast( 1635 f = v8::Local<v8::Function>::Cast(
1627 env->Global()->Get(context, v8_str(isolate, "f")).ToLocalChecked()); 1636 env->Global()->Get(context, v8_str(isolate, "f")).ToLocalChecked());
1628 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1637 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1629 CHECK_EQ(2, break_point_hit_count); 1638 CHECK_EQ(2, break_point_hit_count);
1630 1639
1631 EnableScriptBreakPointFromJS(isolate, sbp); 1640 EnableScriptBreakPointFromJS(isolate, sbp);
1632 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1641 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1633 CHECK_EQ(3, break_point_hit_count); 1642 CHECK_EQ(3, break_point_hit_count);
1634 1643
1635 v8::Debug::SetDebugEventListener(NULL); 1644 v8::Debug::SetDebugEventListener(isolate, nullptr);
1636 CheckDebuggerUnloaded(); 1645 CheckDebuggerUnloaded(isolate);
1637 } 1646 }
1638 1647
1639 1648
1640 // Test conditional script break points. 1649 // Test conditional script break points.
1641 TEST(ConditionalScriptBreakPoint) { 1650 TEST(ConditionalScriptBreakPoint) {
1642 break_point_hit_count = 0; 1651 break_point_hit_count = 0;
1643 DebugLocalContext env; 1652 DebugLocalContext env;
1644 v8::HandleScope scope(env->GetIsolate()); 1653 v8::HandleScope scope(env->GetIsolate());
1645 env.ExposeDebug(); 1654 env.ExposeDebug();
1646 1655
1647 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1656 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1657 DebugEventBreakPointHitCount);
1648 1658
1649 v8::Local<v8::String> script = v8_str(env->GetIsolate(), 1659 v8::Local<v8::String> script = v8_str(env->GetIsolate(),
1650 "count = 0;\n" 1660 "count = 0;\n"
1651 "function f() {\n" 1661 "function f() {\n"
1652 " g(count++); // line 2\n" 1662 " g(count++); // line 2\n"
1653 "};\n" 1663 "};\n"
1654 "function g(x) {\n" 1664 "function g(x) {\n"
1655 " var a=x; // line 5\n" 1665 " var a=x; // line 5\n"
1656 "};"); 1666 "};");
1657 1667
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 env->Global() 1707 env->Global()
1698 ->Get(context, v8_str(env->GetIsolate(), "f")) 1708 ->Get(context, v8_str(env->GetIsolate(), "f"))
1699 .ToLocalChecked()); 1709 .ToLocalChecked());
1700 1710
1701 break_point_hit_count = 0; 1711 break_point_hit_count = 0;
1702 for (int i = 0; i < 10; i++) { 1712 for (int i = 0; i < 10; i++) {
1703 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1713 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1704 } 1714 }
1705 CHECK_EQ(5, break_point_hit_count); 1715 CHECK_EQ(5, break_point_hit_count);
1706 1716
1707 v8::Debug::SetDebugEventListener(NULL); 1717 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1708 CheckDebuggerUnloaded(); 1718 CheckDebuggerUnloaded(env->GetIsolate());
1709 } 1719 }
1710 1720
1711 1721
1712 // Test ignore count on script break points. 1722 // Test ignore count on script break points.
1713 TEST(ScriptBreakPointIgnoreCount) { 1723 TEST(ScriptBreakPointIgnoreCount) {
1714 break_point_hit_count = 0; 1724 break_point_hit_count = 0;
1715 DebugLocalContext env; 1725 DebugLocalContext env;
1716 v8::HandleScope scope(env->GetIsolate()); 1726 v8::HandleScope scope(env->GetIsolate());
1717 env.ExposeDebug(); 1727 env.ExposeDebug();
1718 1728
1719 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1729 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1730 DebugEventBreakPointHitCount);
1720 1731
1721 v8::Local<v8::String> script = v8_str(env->GetIsolate(), 1732 v8::Local<v8::String> script = v8_str(env->GetIsolate(),
1722 "function f() {\n" 1733 "function f() {\n"
1723 " a = 0; // line 1\n" 1734 " a = 0; // line 1\n"
1724 "};"); 1735 "};");
1725 1736
1726 // Compile the script and get function f. 1737 // Compile the script and get function f.
1727 v8::Local<v8::Context> context = env.context(); 1738 v8::Local<v8::Context> context = env.context();
1728 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(env->GetIsolate(), "test")); 1739 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(env->GetIsolate(), "test"));
1729 v8::Script::Compile(context, script, &origin) 1740 v8::Script::Compile(context, script, &origin)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 env->Global() 1773 env->Global()
1763 ->Get(context, v8_str(env->GetIsolate(), "f")) 1774 ->Get(context, v8_str(env->GetIsolate(), "f"))
1764 .ToLocalChecked()); 1775 .ToLocalChecked());
1765 1776
1766 break_point_hit_count = 0; 1777 break_point_hit_count = 0;
1767 for (int i = 0; i < 10; i++) { 1778 for (int i = 0; i < 10; i++) {
1768 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1779 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1769 } 1780 }
1770 CHECK_EQ(5, break_point_hit_count); 1781 CHECK_EQ(5, break_point_hit_count);
1771 1782
1772 v8::Debug::SetDebugEventListener(NULL); 1783 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1773 CheckDebuggerUnloaded(); 1784 CheckDebuggerUnloaded(env->GetIsolate());
1774 } 1785 }
1775 1786
1776 1787
1777 // Test that script break points survive when a script is reloaded. 1788 // Test that script break points survive when a script is reloaded.
1778 TEST(ScriptBreakPointReload) { 1789 TEST(ScriptBreakPointReload) {
1779 break_point_hit_count = 0; 1790 break_point_hit_count = 0;
1780 DebugLocalContext env; 1791 DebugLocalContext env;
1781 v8::HandleScope scope(env->GetIsolate()); 1792 v8::HandleScope scope(env->GetIsolate());
1782 env.ExposeDebug(); 1793 env.ExposeDebug();
1783 1794
1784 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1795 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1796 DebugEventBreakPointHitCount);
1785 1797
1786 v8::Local<v8::Context> context = env.context(); 1798 v8::Local<v8::Context> context = env.context();
1787 v8::Local<v8::Function> f; 1799 v8::Local<v8::Function> f;
1788 v8::Local<v8::String> script = v8_str(env->GetIsolate(), 1800 v8::Local<v8::String> script = v8_str(env->GetIsolate(),
1789 "function f() {\n" 1801 "function f() {\n"
1790 " function h() {\n" 1802 " function h() {\n"
1791 " a = 0; // line 2\n" 1803 " a = 0; // line 2\n"
1792 " }\n" 1804 " }\n"
1793 " b = 1; // line 4\n" 1805 " b = 1; // line 4\n"
1794 " return h();\n" 1806 " return h();\n"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 f = v8::Local<v8::Function>::Cast( 1851 f = v8::Local<v8::Function>::Cast(
1840 env->Global() 1852 env->Global()
1841 ->Get(context, v8_str(env->GetIsolate(), "f")) 1853 ->Get(context, v8_str(env->GetIsolate(), "f"))
1842 .ToLocalChecked()); 1854 .ToLocalChecked());
1843 1855
1844 // Call f and check that the script break point is active. 1856 // Call f and check that the script break point is active.
1845 break_point_hit_count = 0; 1857 break_point_hit_count = 0;
1846 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1858 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1847 CHECK_EQ(1, break_point_hit_count); 1859 CHECK_EQ(1, break_point_hit_count);
1848 1860
1849 v8::Debug::SetDebugEventListener(NULL); 1861 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1850 CheckDebuggerUnloaded(); 1862 CheckDebuggerUnloaded(env->GetIsolate());
1851 } 1863 }
1852 1864
1853 1865
1854 // Test when several scripts has the same script data 1866 // Test when several scripts has the same script data
1855 TEST(ScriptBreakPointMultiple) { 1867 TEST(ScriptBreakPointMultiple) {
1856 break_point_hit_count = 0; 1868 break_point_hit_count = 0;
1857 DebugLocalContext env; 1869 DebugLocalContext env;
1858 v8::HandleScope scope(env->GetIsolate()); 1870 v8::HandleScope scope(env->GetIsolate());
1859 env.ExposeDebug(); 1871 env.ExposeDebug();
1860 1872
1861 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1873 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1874 DebugEventBreakPointHitCount);
1862 1875
1863 v8::Local<v8::Context> context = env.context(); 1876 v8::Local<v8::Context> context = env.context();
1864 v8::Local<v8::Function> f; 1877 v8::Local<v8::Function> f;
1865 v8::Local<v8::String> script_f = v8_str(env->GetIsolate(), 1878 v8::Local<v8::String> script_f = v8_str(env->GetIsolate(),
1866 "function f() {\n" 1879 "function f() {\n"
1867 " a = 0; // line 1\n" 1880 " a = 0; // line 1\n"
1868 "}"); 1881 "}");
1869 1882
1870 v8::Local<v8::Function> g; 1883 v8::Local<v8::Function> g;
1871 v8::Local<v8::String> script_g = v8_str(env->GetIsolate(), 1884 v8::Local<v8::String> script_g = v8_str(env->GetIsolate(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 // Set script break point with the scripts loaded. 1929 // Set script break point with the scripts loaded.
1917 sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0); 1930 sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
1918 1931
1919 // Call f and g and check that the script break point is active. 1932 // Call f and g and check that the script break point is active.
1920 break_point_hit_count = 0; 1933 break_point_hit_count = 0;
1921 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1934 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1922 CHECK_EQ(1, break_point_hit_count); 1935 CHECK_EQ(1, break_point_hit_count);
1923 g->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1936 g->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1924 CHECK_EQ(2, break_point_hit_count); 1937 CHECK_EQ(2, break_point_hit_count);
1925 1938
1926 v8::Debug::SetDebugEventListener(NULL); 1939 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1927 CheckDebuggerUnloaded(); 1940 CheckDebuggerUnloaded(env->GetIsolate());
1928 } 1941 }
1929 1942
1930 1943
1931 // Test the script origin which has both name and line offset. 1944 // Test the script origin which has both name and line offset.
1932 TEST(ScriptBreakPointLineOffset) { 1945 TEST(ScriptBreakPointLineOffset) {
1933 break_point_hit_count = 0; 1946 break_point_hit_count = 0;
1934 DebugLocalContext env; 1947 DebugLocalContext env;
1935 v8::HandleScope scope(env->GetIsolate()); 1948 v8::HandleScope scope(env->GetIsolate());
1936 env.ExposeDebug(); 1949 env.ExposeDebug();
1937 1950
1938 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 1951 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1952 DebugEventBreakPointHitCount);
1939 1953
1940 v8::Local<v8::Context> context = env.context(); 1954 v8::Local<v8::Context> context = env.context();
1941 v8::Local<v8::Function> f; 1955 v8::Local<v8::Function> f;
1942 v8::Local<v8::String> script = 1956 v8::Local<v8::String> script =
1943 v8_str(env->GetIsolate(), 1957 v8_str(env->GetIsolate(),
1944 "function f() {\n" 1958 "function f() {\n"
1945 " a = 0; // line 8 as this script has line offset 7\n" 1959 " a = 0; // line 8 as this script has line offset 7\n"
1946 " b = 0; // line 9 as this script has line offset 7\n" 1960 " b = 0; // line 9 as this script has line offset 7\n"
1947 "}"); 1961 "}");
1948 1962
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 CHECK_EQ(0, break_point_hit_count); 1995 CHECK_EQ(0, break_point_hit_count);
1982 1996
1983 // Set a script break point with the script loaded. 1997 // Set a script break point with the script loaded.
1984 sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0); 1998 sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0);
1985 1999
1986 // Call f and check that the script break point is active. 2000 // Call f and check that the script break point is active.
1987 break_point_hit_count = 0; 2001 break_point_hit_count = 0;
1988 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2002 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1989 CHECK_EQ(1, break_point_hit_count); 2003 CHECK_EQ(1, break_point_hit_count);
1990 2004
1991 v8::Debug::SetDebugEventListener(NULL); 2005 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1992 CheckDebuggerUnloaded(); 2006 CheckDebuggerUnloaded(env->GetIsolate());
1993 } 2007 }
1994 2008
1995 2009
1996 // Test script break points set on lines. 2010 // Test script break points set on lines.
1997 TEST(ScriptBreakPointLine) { 2011 TEST(ScriptBreakPointLine) {
1998 DebugLocalContext env; 2012 DebugLocalContext env;
1999 v8::HandleScope scope(env->GetIsolate()); 2013 v8::HandleScope scope(env->GetIsolate());
2000 env.ExposeDebug(); 2014 env.ExposeDebug();
2001 2015
2002 // Create a function for checking the function when hitting a break point. 2016 // Create a function for checking the function when hitting a break point.
2003 frame_function_name = CompileFunction(&env, 2017 frame_function_name = CompileFunction(&env,
2004 frame_function_name_source, 2018 frame_function_name_source,
2005 "frame_function_name"); 2019 "frame_function_name");
2006 2020
2007 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2021 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2022 DebugEventBreakPointHitCount);
2008 2023
2009 v8::Local<v8::Context> context = env.context(); 2024 v8::Local<v8::Context> context = env.context();
2010 v8::Local<v8::Function> f; 2025 v8::Local<v8::Function> f;
2011 v8::Local<v8::Function> g; 2026 v8::Local<v8::Function> g;
2012 v8::Local<v8::String> script = 2027 v8::Local<v8::String> script =
2013 v8_str(env->GetIsolate(), 2028 v8_str(env->GetIsolate(),
2014 "a = 0 // line 0\n" 2029 "a = 0 // line 0\n"
2015 "function f() {\n" 2030 "function f() {\n"
2016 " a = 1; // line 2\n" 2031 " a = 1; // line 2\n"
2017 "}\n" 2032 "}\n"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 ClearBreakPointFromJS(env->GetIsolate(), sbp1); 2128 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
2114 ClearBreakPointFromJS(env->GetIsolate(), sbp5); 2129 ClearBreakPointFromJS(env->GetIsolate(), sbp5);
2115 ClearBreakPointFromJS(env->GetIsolate(), sbp6); 2130 ClearBreakPointFromJS(env->GetIsolate(), sbp6);
2116 break_point_hit_count = 0; 2131 break_point_hit_count = 0;
2117 v8::Script::Compile(context, script, &origin) 2132 v8::Script::Compile(context, script, &origin)
2118 .ToLocalChecked() 2133 .ToLocalChecked()
2119 ->Run(context) 2134 ->Run(context)
2120 .ToLocalChecked(); 2135 .ToLocalChecked();
2121 CHECK_EQ(0, break_point_hit_count); 2136 CHECK_EQ(0, break_point_hit_count);
2122 2137
2123 v8::Debug::SetDebugEventListener(NULL); 2138 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2124 CheckDebuggerUnloaded(); 2139 CheckDebuggerUnloaded(env->GetIsolate());
2125 } 2140 }
2126 2141
2127 2142
2128 // Test top level script break points set on lines. 2143 // Test top level script break points set on lines.
2129 TEST(ScriptBreakPointLineTopLevel) { 2144 TEST(ScriptBreakPointLineTopLevel) {
2130 DebugLocalContext env; 2145 DebugLocalContext env;
2131 v8::HandleScope scope(env->GetIsolate()); 2146 v8::HandleScope scope(env->GetIsolate());
2132 env.ExposeDebug(); 2147 env.ExposeDebug();
2133 2148
2134 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2149 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2150 DebugEventBreakPointHitCount);
2135 2151
2136 v8::Local<v8::Context> context = env.context(); 2152 v8::Local<v8::Context> context = env.context();
2137 v8::Local<v8::String> script = 2153 v8::Local<v8::String> script =
2138 v8_str(env->GetIsolate(), 2154 v8_str(env->GetIsolate(),
2139 "function f() {\n" 2155 "function f() {\n"
2140 " a = 1; // line 1\n" 2156 " a = 1; // line 1\n"
2141 "}\n" 2157 "}\n"
2142 "a = 2; // line 3\n"); 2158 "a = 2; // line 3\n");
2143 v8::Local<v8::Function> f; 2159 v8::Local<v8::Function> f;
2144 { 2160 {
(...skipping 20 matching lines...) Expand all
2165 CHECK_EQ(1, break_point_hit_count); 2181 CHECK_EQ(1, break_point_hit_count);
2166 2182
2167 // Call f and check that there are still no break points. 2183 // Call f and check that there are still no break points.
2168 break_point_hit_count = 0; 2184 break_point_hit_count = 0;
2169 f = v8::Local<v8::Function>::Cast( 2185 f = v8::Local<v8::Function>::Cast(
2170 env->Global() 2186 env->Global()
2171 ->Get(context, v8_str(env->GetIsolate(), "f")) 2187 ->Get(context, v8_str(env->GetIsolate(), "f"))
2172 .ToLocalChecked()); 2188 .ToLocalChecked());
2173 CHECK_EQ(0, break_point_hit_count); 2189 CHECK_EQ(0, break_point_hit_count);
2174 2190
2175 v8::Debug::SetDebugEventListener(NULL); 2191 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2176 CheckDebuggerUnloaded(); 2192 CheckDebuggerUnloaded(env->GetIsolate());
2177 } 2193 }
2178 2194
2179 2195
2180 // Test that it is possible to add and remove break points in a top level 2196 // Test that it is possible to add and remove break points in a top level
2181 // function which has no references but has not been collected yet. 2197 // function which has no references but has not been collected yet.
2182 TEST(ScriptBreakPointTopLevelCrash) { 2198 TEST(ScriptBreakPointTopLevelCrash) {
2183 DebugLocalContext env; 2199 DebugLocalContext env;
2184 v8::HandleScope scope(env->GetIsolate()); 2200 v8::HandleScope scope(env->GetIsolate());
2185 env.ExposeDebug(); 2201 env.ExposeDebug();
2186 2202
2187 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2203 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2204 DebugEventBreakPointHitCount);
2188 2205
2189 v8::Local<v8::String> script_source = v8_str(env->GetIsolate(), 2206 v8::Local<v8::String> script_source = v8_str(env->GetIsolate(),
2190 "function f() {\n" 2207 "function f() {\n"
2191 " return 0;\n" 2208 " return 0;\n"
2192 "}\n" 2209 "}\n"
2193 "f()"); 2210 "f()");
2194 2211
2195 int sbp1 = 2212 int sbp1 =
2196 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); 2213 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
2197 { 2214 {
2198 v8::HandleScope scope(env->GetIsolate()); 2215 v8::HandleScope scope(env->GetIsolate());
2199 break_point_hit_count = 0; 2216 break_point_hit_count = 0;
2200 CompileRunWithOrigin(script_source, "test.html"); 2217 CompileRunWithOrigin(script_source, "test.html");
2201 CHECK_EQ(1, break_point_hit_count); 2218 CHECK_EQ(1, break_point_hit_count);
2202 } 2219 }
2203 2220
2204 int sbp2 = 2221 int sbp2 =
2205 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); 2222 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
2206 ClearBreakPointFromJS(env->GetIsolate(), sbp1); 2223 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
2207 ClearBreakPointFromJS(env->GetIsolate(), sbp2); 2224 ClearBreakPointFromJS(env->GetIsolate(), sbp2);
2208 2225
2209 v8::Debug::SetDebugEventListener(NULL); 2226 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2210 CheckDebuggerUnloaded(); 2227 CheckDebuggerUnloaded(env->GetIsolate());
2211 } 2228 }
2212 2229
2213 2230
2214 // Test that it is possible to remove the last break point for a function 2231 // Test that it is possible to remove the last break point for a function
2215 // inside the break handling of that break point. 2232 // inside the break handling of that break point.
2216 TEST(RemoveBreakPointInBreak) { 2233 TEST(RemoveBreakPointInBreak) {
2217 DebugLocalContext env; 2234 DebugLocalContext env;
2218 v8::HandleScope scope(env->GetIsolate()); 2235 v8::HandleScope scope(env->GetIsolate());
2219 2236
2220 v8::Local<v8::Context> context = env.context(); 2237 v8::Local<v8::Context> context = env.context();
2221 v8::Local<v8::Function> foo = 2238 v8::Local<v8::Function> foo =
2222 CompileFunction(&env, "function foo(){a=1;}", "foo"); 2239 CompileFunction(&env, "function foo(){a=1;}", "foo");
2223 2240
2224 // Register the debug event listener pasing the function 2241 // Register the debug event listener pasing the function
2225 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); 2242 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2243 DebugEventRemoveBreakPoint, foo);
2226 2244
2227 debug_event_remove_break_point = SetBreakPoint(foo, 0); 2245 debug_event_remove_break_point = SetBreakPoint(foo, 0);
2228 2246
2229 break_point_hit_count = 0; 2247 break_point_hit_count = 0;
2230 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2248 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2231 CHECK_EQ(1, break_point_hit_count); 2249 CHECK_EQ(1, break_point_hit_count);
2232 2250
2233 break_point_hit_count = 0; 2251 break_point_hit_count = 0;
2234 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2252 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2235 CHECK_EQ(0, break_point_hit_count); 2253 CHECK_EQ(0, break_point_hit_count);
2236 2254
2237 v8::Debug::SetDebugEventListener(NULL); 2255 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2238 CheckDebuggerUnloaded(); 2256 CheckDebuggerUnloaded(env->GetIsolate());
2239 } 2257 }
2240 2258
2241 2259
2242 // Test that the debugger statement causes a break. 2260 // Test that the debugger statement causes a break.
2243 TEST(DebuggerStatement) { 2261 TEST(DebuggerStatement) {
2244 break_point_hit_count = 0; 2262 break_point_hit_count = 0;
2245 DebugLocalContext env; 2263 DebugLocalContext env;
2246 v8::HandleScope scope(env->GetIsolate()); 2264 v8::HandleScope scope(env->GetIsolate());
2247 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2265 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2266 DebugEventBreakPointHitCount);
2248 v8::Local<v8::Context> context = env.context(); 2267 v8::Local<v8::Context> context = env.context();
2249 v8::Script::Compile(context, 2268 v8::Script::Compile(context,
2250 v8_str(env->GetIsolate(), "function bar(){debugger}")) 2269 v8_str(env->GetIsolate(), "function bar(){debugger}"))
2251 .ToLocalChecked() 2270 .ToLocalChecked()
2252 ->Run(context) 2271 ->Run(context)
2253 .ToLocalChecked(); 2272 .ToLocalChecked();
2254 v8::Script::Compile( 2273 v8::Script::Compile(
2255 context, v8_str(env->GetIsolate(), "function foo(){debugger;debugger;}")) 2274 context, v8_str(env->GetIsolate(), "function foo(){debugger;debugger;}"))
2256 .ToLocalChecked() 2275 .ToLocalChecked()
2257 ->Run(context) 2276 ->Run(context)
2258 .ToLocalChecked(); 2277 .ToLocalChecked();
2259 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 2278 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
2260 env->Global() 2279 env->Global()
2261 ->Get(context, v8_str(env->GetIsolate(), "foo")) 2280 ->Get(context, v8_str(env->GetIsolate(), "foo"))
2262 .ToLocalChecked()); 2281 .ToLocalChecked());
2263 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 2282 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
2264 env->Global() 2283 env->Global()
2265 ->Get(context, v8_str(env->GetIsolate(), "bar")) 2284 ->Get(context, v8_str(env->GetIsolate(), "bar"))
2266 .ToLocalChecked()); 2285 .ToLocalChecked());
2267 2286
2268 // Run function with debugger statement 2287 // Run function with debugger statement
2269 bar->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2288 bar->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2270 CHECK_EQ(1, break_point_hit_count); 2289 CHECK_EQ(1, break_point_hit_count);
2271 2290
2272 // Run function with two debugger statement 2291 // Run function with two debugger statement
2273 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2292 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2274 CHECK_EQ(3, break_point_hit_count); 2293 CHECK_EQ(3, break_point_hit_count);
2275 2294
2276 v8::Debug::SetDebugEventListener(NULL); 2295 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2277 CheckDebuggerUnloaded(); 2296 CheckDebuggerUnloaded(env->GetIsolate());
2278 } 2297 }
2279 2298
2280 2299
2281 // Test setting a breakpoint on the debugger statement. 2300 // Test setting a breakpoint on the debugger statement.
2282 TEST(DebuggerStatementBreakpoint) { 2301 TEST(DebuggerStatementBreakpoint) {
2283 break_point_hit_count = 0; 2302 break_point_hit_count = 0;
2284 DebugLocalContext env; 2303 DebugLocalContext env;
2285 v8::HandleScope scope(env->GetIsolate()); 2304 v8::HandleScope scope(env->GetIsolate());
2286 v8::Local<v8::Context> context = env.context(); 2305 v8::Local<v8::Context> context = env.context();
2287 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2306 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2307 DebugEventBreakPointHitCount);
2288 v8::Script::Compile(context, 2308 v8::Script::Compile(context,
2289 v8_str(env->GetIsolate(), "function foo(){debugger;}")) 2309 v8_str(env->GetIsolate(), "function foo(){debugger;}"))
2290 .ToLocalChecked() 2310 .ToLocalChecked()
2291 ->Run(context) 2311 ->Run(context)
2292 .ToLocalChecked(); 2312 .ToLocalChecked();
2293 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 2313 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
2294 env->Global() 2314 env->Global()
2295 ->Get(context, v8_str(env->GetIsolate(), "foo")) 2315 ->Get(context, v8_str(env->GetIsolate(), "foo"))
2296 .ToLocalChecked()); 2316 .ToLocalChecked());
2297 2317
2298 // The debugger statement triggers breakpoint hit 2318 // The debugger statement triggers breakpoint hit
2299 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2319 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2300 CHECK_EQ(1, break_point_hit_count); 2320 CHECK_EQ(1, break_point_hit_count);
2301 2321
2302 int bp = SetBreakPoint(foo, 0); 2322 int bp = SetBreakPoint(foo, 0);
2303 2323
2304 // Set breakpoint does not duplicate hits 2324 // Set breakpoint does not duplicate hits
2305 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2325 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2306 CHECK_EQ(2, break_point_hit_count); 2326 CHECK_EQ(2, break_point_hit_count);
2307 2327
2308 ClearBreakPoint(bp); 2328 ClearBreakPoint(bp);
2309 v8::Debug::SetDebugEventListener(NULL); 2329 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2310 CheckDebuggerUnloaded(); 2330 CheckDebuggerUnloaded(env->GetIsolate());
2311 } 2331 }
2312 2332
2313 2333
2314 // Test that the evaluation of expressions when a break point is hit generates 2334 // Test that the evaluation of expressions when a break point is hit generates
2315 // the correct results. 2335 // the correct results.
2316 TEST(DebugEvaluate) { 2336 TEST(DebugEvaluate) {
2317 DebugLocalContext env; 2337 DebugLocalContext env;
2318 v8::Isolate* isolate = env->GetIsolate(); 2338 v8::Isolate* isolate = env->GetIsolate();
2319 v8::HandleScope scope(isolate); 2339 v8::HandleScope scope(isolate);
2320 env.ExposeDebug(); 2340 env.ExposeDebug();
2321 2341
2322 // Create a function for checking the evaluation when hitting a break point. 2342 // Create a function for checking the evaluation when hitting a break point.
2323 evaluate_check_function = CompileFunction(&env, 2343 evaluate_check_function = CompileFunction(&env,
2324 evaluate_check_source, 2344 evaluate_check_source,
2325 "evaluate_check"); 2345 "evaluate_check");
2326 // Register the debug event listener 2346 // Register the debug event listener
2327 v8::Debug::SetDebugEventListener(DebugEventEvaluate); 2347 v8::Debug::SetDebugEventListener(isolate, DebugEventEvaluate);
2328 2348
2329 // Different expected vaules of x and a when in a break point (u = undefined, 2349 // Different expected vaules of x and a when in a break point (u = undefined,
2330 // d = Hello, world!). 2350 // d = Hello, world!).
2331 struct EvaluateCheck checks_uu[] = {{"x", v8::Undefined(isolate)}, 2351 struct EvaluateCheck checks_uu[] = {{"x", v8::Undefined(isolate)},
2332 {"a", v8::Undefined(isolate)}, 2352 {"a", v8::Undefined(isolate)},
2333 {NULL, v8::Local<v8::Value>()}}; 2353 {NULL, v8::Local<v8::Value>()}};
2334 struct EvaluateCheck checks_hu[] = { 2354 struct EvaluateCheck checks_hu[] = {
2335 {"x", v8_str(env->GetIsolate(), "Hello, world!")}, 2355 {"x", v8_str(env->GetIsolate(), "Hello, world!")},
2336 {"a", v8::Undefined(isolate)}, 2356 {"a", v8::Undefined(isolate)},
2337 {NULL, v8::Local<v8::Value>()}}; 2357 {NULL, v8::Local<v8::Value>()}};
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 bar->Call(context, env->Global(), 2, argv_bar_2).ToLocalChecked(); 2459 bar->Call(context, env->Global(), 2, argv_bar_2).ToLocalChecked();
2440 2460
2441 // Call bar setting breakpoint after a=x in barbar and parameter 2461 // Call bar setting breakpoint after a=x in barbar and parameter
2442 // "Hello, world!". 2462 // "Hello, world!".
2443 checks = checks_hh; 2463 checks = checks_hh;
2444 v8::Local<v8::Value> argv_bar_3[2] = { 2464 v8::Local<v8::Value> argv_bar_3[2] = {
2445 v8_str(env->GetIsolate(), "Hello, world!"), 2465 v8_str(env->GetIsolate(), "Hello, world!"),
2446 v8::Number::New(env->GetIsolate(), barbar_break_position + 1)}; 2466 v8::Number::New(env->GetIsolate(), barbar_break_position + 1)};
2447 bar->Call(context, env->Global(), 2, argv_bar_3).ToLocalChecked(); 2467 bar->Call(context, env->Global(), 2, argv_bar_3).ToLocalChecked();
2448 2468
2449 v8::Debug::SetDebugEventListener(NULL); 2469 v8::Debug::SetDebugEventListener(isolate, nullptr);
2450 CheckDebuggerUnloaded(); 2470 CheckDebuggerUnloaded(isolate);
2451 } 2471 }
2452 2472
2453 2473
2454 int debugEventCount = 0; 2474 int debugEventCount = 0;
2455 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { 2475 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) {
2456 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; 2476 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount;
2457 } 2477 }
2458 2478
2459 2479
2460 // Test that the conditional breakpoints work event if code generation from 2480 // Test that the conditional breakpoints work event if code generation from
2461 // strings is prohibited in the debugee context. 2481 // strings is prohibited in the debugee context.
2462 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) { 2482 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) {
2463 DebugLocalContext env; 2483 DebugLocalContext env;
2464 v8::HandleScope scope(env->GetIsolate()); 2484 v8::HandleScope scope(env->GetIsolate());
2465 env.ExposeDebug(); 2485 env.ExposeDebug();
2466 2486
2467 v8::Debug::SetDebugEventListener(CheckDebugEvent); 2487 v8::Debug::SetDebugEventListener(env->GetIsolate(), CheckDebugEvent);
2468 2488
2469 v8::Local<v8::Context> context = env.context(); 2489 v8::Local<v8::Context> context = env.context();
2470 v8::Local<v8::Function> foo = CompileFunction(&env, 2490 v8::Local<v8::Function> foo = CompileFunction(&env,
2471 "function foo(x) {\n" 2491 "function foo(x) {\n"
2472 " var s = 'String value2';\n" 2492 " var s = 'String value2';\n"
2473 " return s + x;\n" 2493 " return s + x;\n"
2474 "}", 2494 "}",
2475 "foo"); 2495 "foo");
2476 2496
2477 // Set conditional breakpoint with condition 'true'. 2497 // Set conditional breakpoint with condition 'true'.
2478 CompileRun("debug.Debug.setBreakPoint(foo, 2, 0, 'true')"); 2498 CompileRun("debug.Debug.setBreakPoint(foo, 2, 0, 'true')");
2479 2499
2480 debugEventCount = 0; 2500 debugEventCount = 0;
2481 env->AllowCodeGenerationFromStrings(false); 2501 env->AllowCodeGenerationFromStrings(false);
2482 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2502 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2483 CHECK_EQ(1, debugEventCount); 2503 CHECK_EQ(1, debugEventCount);
2484 2504
2485 v8::Debug::SetDebugEventListener(NULL); 2505 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2486 CheckDebuggerUnloaded(); 2506 CheckDebuggerUnloaded(env->GetIsolate());
2487 } 2507 }
2488 2508
2489 2509
2490 bool checkedDebugEvals = true; 2510 bool checkedDebugEvals = true;
2491 v8::Local<v8::Function> checkGlobalEvalFunction; 2511 v8::Local<v8::Function> checkGlobalEvalFunction;
2492 v8::Local<v8::Function> checkFrameEvalFunction; 2512 v8::Local<v8::Function> checkFrameEvalFunction;
2493 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) { 2513 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) {
2494 if (eventDetails.GetEvent() == v8::Break) { 2514 if (eventDetails.GetEvent() == v8::Break) {
2495 ++debugEventCount; 2515 ++debugEventCount;
2496 v8::HandleScope handleScope(CcTest::isolate()); 2516 v8::HandleScope handleScope(CcTest::isolate());
(...skipping 15 matching lines...) Expand all
2512 2532
2513 2533
2514 // Test that the evaluation of expressions when a break point is hit generates 2534 // Test that the evaluation of expressions when a break point is hit generates
2515 // the correct results in case code generation from strings is disallowed in the 2535 // the correct results in case code generation from strings is disallowed in the
2516 // debugee context. 2536 // debugee context.
2517 TEST(DebugEvaluateWithCodeGenerationDisallowed) { 2537 TEST(DebugEvaluateWithCodeGenerationDisallowed) {
2518 DebugLocalContext env; 2538 DebugLocalContext env;
2519 v8::HandleScope scope(env->GetIsolate()); 2539 v8::HandleScope scope(env->GetIsolate());
2520 env.ExposeDebug(); 2540 env.ExposeDebug();
2521 2541
2522 v8::Debug::SetDebugEventListener(CheckDebugEval); 2542 v8::Debug::SetDebugEventListener(env->GetIsolate(), CheckDebugEval);
2523 2543
2524 v8::Local<v8::Context> context = env.context(); 2544 v8::Local<v8::Context> context = env.context();
2525 v8::Local<v8::Function> foo = CompileFunction(&env, 2545 v8::Local<v8::Function> foo = CompileFunction(&env,
2526 "var global = 'Global';\n" 2546 "var global = 'Global';\n"
2527 "function foo(x) {\n" 2547 "function foo(x) {\n"
2528 " var local = 'Local';\n" 2548 " var local = 'Local';\n"
2529 " debugger;\n" 2549 " debugger;\n"
2530 " return local + x;\n" 2550 " return local + x;\n"
2531 "}", 2551 "}",
2532 "foo"); 2552 "foo");
2533 checkGlobalEvalFunction = CompileFunction(&env, 2553 checkGlobalEvalFunction = CompileFunction(&env,
2534 "function checkGlobalEval(exec_state) {\n" 2554 "function checkGlobalEval(exec_state) {\n"
2535 " return exec_state.evaluateGlobal('global').value() === 'Global';\n" 2555 " return exec_state.evaluateGlobal('global').value() === 'Global';\n"
2536 "}", 2556 "}",
2537 "checkGlobalEval"); 2557 "checkGlobalEval");
2538 2558
2539 checkFrameEvalFunction = CompileFunction(&env, 2559 checkFrameEvalFunction = CompileFunction(&env,
2540 "function checkFrameEval(exec_state) {\n" 2560 "function checkFrameEval(exec_state) {\n"
2541 " return exec_state.frame(0).evaluate('local').value() === 'Local';\n" 2561 " return exec_state.frame(0).evaluate('local').value() === 'Local';\n"
2542 "}", 2562 "}",
2543 "checkFrameEval"); 2563 "checkFrameEval");
2544 debugEventCount = 0; 2564 debugEventCount = 0;
2545 env->AllowCodeGenerationFromStrings(false); 2565 env->AllowCodeGenerationFromStrings(false);
2546 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2566 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2547 CHECK_EQ(1, debugEventCount); 2567 CHECK_EQ(1, debugEventCount);
2548 2568
2549 checkGlobalEvalFunction.Clear(); 2569 checkGlobalEvalFunction.Clear();
2550 checkFrameEvalFunction.Clear(); 2570 checkFrameEvalFunction.Clear();
2551 v8::Debug::SetDebugEventListener(NULL); 2571 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2552 CheckDebuggerUnloaded(); 2572 CheckDebuggerUnloaded(env->GetIsolate());
2553 } 2573 }
2554 2574
2555 2575
2556 // Copies a C string to a 16-bit string. Does not check for buffer overflow. 2576 // Copies a C string to a 16-bit string. Does not check for buffer overflow.
2557 // Does not use the V8 engine to convert strings, so it can be used 2577 // Does not use the V8 engine to convert strings, so it can be used
2558 // in any thread. Returns the length of the string. 2578 // in any thread. Returns the length of the string.
2559 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { 2579 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) {
2560 int i; 2580 int i;
2561 for (i = 0; input_buffer[i] != '\0'; ++i) { 2581 for (i = 0; input_buffer[i] != '\0'; ++i) {
2562 // ASCII does not use chars > 127, but be careful anyway. 2582 // ASCII does not use chars > 127, but be careful anyway.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 EvaluateResult::kBufferSize); 2666 EvaluateResult::kBufferSize);
2647 if (res) { 2667 if (res) {
2648 process_debug_messages_data.next(); 2668 process_debug_messages_data.next();
2649 } 2669 }
2650 } 2670 }
2651 2671
2652 2672
2653 // Test that the evaluation of expressions works even from ProcessDebugMessages 2673 // Test that the evaluation of expressions works even from ProcessDebugMessages
2654 // i.e. with empty stack. 2674 // i.e. with empty stack.
2655 TEST(DebugEvaluateWithoutStack) { 2675 TEST(DebugEvaluateWithoutStack) {
2656 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler);
2657
2658 DebugLocalContext env; 2676 DebugLocalContext env;
2677 v8::Debug::SetMessageHandler(env->GetIsolate(),
2678 DebugProcessDebugMessagesHandler);
2659 v8::HandleScope scope(env->GetIsolate()); 2679 v8::HandleScope scope(env->GetIsolate());
2660 2680
2661 const char* source = 2681 const char* source =
2662 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; 2682 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }";
2663 2683
2664 v8::Local<v8::Context> context = env.context(); 2684 v8::Local<v8::Context> context = env.context();
2665 v8::Script::Compile(context, v8_str(env->GetIsolate(), source)) 2685 v8::Script::Compile(context, v8_str(env->GetIsolate(), source))
2666 .ToLocalChecked() 2686 .ToLocalChecked()
2667 ->Run(context) 2687 ->Run(context)
2668 .ToLocalChecked(); 2688 .ToLocalChecked();
2669 2689
2670 v8::Debug::ProcessDebugMessages(); 2690 v8::Debug::ProcessDebugMessages(env->GetIsolate());
2671 2691
2672 const int kBufferSize = 1000; 2692 const int kBufferSize = 1000;
2673 uint16_t buffer[kBufferSize]; 2693 uint16_t buffer[kBufferSize];
2674 2694
2675 const char* command_111 = "{\"seq\":111," 2695 const char* command_111 = "{\"seq\":111,"
2676 "\"type\":\"request\"," 2696 "\"type\":\"request\","
2677 "\"command\":\"evaluate\"," 2697 "\"command\":\"evaluate\","
2678 "\"arguments\":{" 2698 "\"arguments\":{"
2679 " \"global\":true," 2699 " \"global\":true,"
2680 " \"expression\":\"v1\",\"disable_break\":true" 2700 " \"expression\":\"v1\",\"disable_break\":true"
(...skipping 15 matching lines...) Expand all
2696 const char* command_113 = "{\"seq\":113," 2716 const char* command_113 = "{\"seq\":113,"
2697 "\"type\":\"request\"," 2717 "\"type\":\"request\","
2698 "\"command\":\"evaluate\"," 2718 "\"command\":\"evaluate\","
2699 "\"arguments\":{" 2719 "\"arguments\":{"
2700 " \"global\":true," 2720 " \"global\":true,"
2701 " \"expression\":\"239 + 566\",\"disable_break\":true" 2721 " \"expression\":\"239 + 566\",\"disable_break\":true"
2702 "}}"; 2722 "}}";
2703 2723
2704 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_113, buffer)); 2724 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_113, buffer));
2705 2725
2706 v8::Debug::ProcessDebugMessages(); 2726 v8::Debug::ProcessDebugMessages(isolate);
2707 2727
2708 CHECK_EQ(3, process_debug_messages_data.counter); 2728 CHECK_EQ(3, process_debug_messages_data.counter);
2709 2729
2710 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); 2730 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0);
2711 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), 2731 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer),
2712 0); 2732 0);
2713 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); 2733 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0);
2714 2734
2715 v8::Debug::SetMessageHandler(NULL); 2735 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
2716 v8::Debug::SetDebugEventListener(NULL); 2736 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2717 CheckDebuggerUnloaded(); 2737 CheckDebuggerUnloaded(env->GetIsolate());
2718 } 2738 }
2719 2739
2720 2740
2721 // Simple test of the stepping mechanism using only store ICs. 2741 // Simple test of the stepping mechanism using only store ICs.
2722 TEST(DebugStepLinear) { 2742 TEST(DebugStepLinear) {
2723 DebugLocalContext env; 2743 DebugLocalContext env;
2724 v8::HandleScope scope(env->GetIsolate()); 2744 v8::HandleScope scope(env->GetIsolate());
2725 2745
2726 // Create a function for testing stepping. 2746 // Create a function for testing stepping.
2727 v8::Local<v8::Function> foo = CompileFunction(&env, 2747 v8::Local<v8::Function> foo = CompileFunction(&env,
2728 "function foo(){a=1;b=1;c=1;}", 2748 "function foo(){a=1;b=1;c=1;}",
2729 "foo"); 2749 "foo");
2730 2750
2731 // Run foo to allow it to get optimized. 2751 // Run foo to allow it to get optimized.
2732 CompileRun("a=0; b=0; c=0; foo();"); 2752 CompileRun("a=0; b=0; c=0; foo();");
2733 2753
2734 // Register a debug event listener which steps and counts. 2754 // Register a debug event listener which steps and counts.
2735 v8::Debug::SetDebugEventListener(DebugEventStep); 2755 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2736 2756
2737 SetBreakPoint(foo, 3); 2757 SetBreakPoint(foo, 3);
2738 2758
2739 step_action = StepIn; 2759 step_action = StepIn;
2740 break_point_hit_count = 0; 2760 break_point_hit_count = 0;
2741 v8::Local<v8::Context> context = env.context(); 2761 v8::Local<v8::Context> context = env.context();
2742 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2762 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2743 2763
2744 // With stepping all break locations are hit. 2764 // With stepping all break locations are hit.
2745 CHECK_EQ(4, break_point_hit_count); 2765 CHECK_EQ(4, break_point_hit_count);
2746 2766
2747 v8::Debug::SetDebugEventListener(NULL); 2767 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2748 CheckDebuggerUnloaded(); 2768 CheckDebuggerUnloaded(env->GetIsolate());
2749 2769
2750 // Register a debug event listener which just counts. 2770 // Register a debug event listener which just counts.
2751 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 2771 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2772 DebugEventBreakPointHitCount);
2752 2773
2753 SetBreakPoint(foo, 3); 2774 SetBreakPoint(foo, 3);
2754 break_point_hit_count = 0; 2775 break_point_hit_count = 0;
2755 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2776 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2756 2777
2757 // Without stepping only active break points are hit. 2778 // Without stepping only active break points are hit.
2758 CHECK_EQ(1, break_point_hit_count); 2779 CHECK_EQ(1, break_point_hit_count);
2759 2780
2760 v8::Debug::SetDebugEventListener(NULL); 2781 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2761 CheckDebuggerUnloaded(); 2782 CheckDebuggerUnloaded(env->GetIsolate());
2762 } 2783 }
2763 2784
2764 2785
2765 // Test of the stepping mechanism for keyed load in a loop. 2786 // Test of the stepping mechanism for keyed load in a loop.
2766 TEST(DebugStepKeyedLoadLoop) { 2787 TEST(DebugStepKeyedLoadLoop) {
2767 DebugLocalContext env; 2788 DebugLocalContext env;
2768 v8::HandleScope scope(env->GetIsolate()); 2789 v8::HandleScope scope(env->GetIsolate());
2769 2790
2770 // Register a debug event listener which steps and counts. 2791 // Register a debug event listener which steps and counts.
2771 v8::Debug::SetDebugEventListener(DebugEventStep); 2792 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2772 2793
2773 // Create a function for testing stepping of keyed load. The statement 'y=1' 2794 // Create a function for testing stepping of keyed load. The statement 'y=1'
2774 // is there to have more than one breakable statement in the loop, TODO(315). 2795 // is there to have more than one breakable statement in the loop, TODO(315).
2775 v8::Local<v8::Function> foo = CompileFunction( 2796 v8::Local<v8::Function> foo = CompileFunction(
2776 &env, 2797 &env,
2777 "function foo(a) {\n" 2798 "function foo(a) {\n"
2778 " var x;\n" 2799 " var x;\n"
2779 " var len = a.length;\n" 2800 " var len = a.length;\n"
2780 " for (var i = 0; i < len; i++) {\n" 2801 " for (var i = 0; i < len; i++) {\n"
2781 " y = 1;\n" 2802 " y = 1;\n"
(...skipping 19 matching lines...) Expand all
2801 2822
2802 // Set up break point and step through the function. 2823 // Set up break point and step through the function.
2803 SetBreakPoint(foo, 3); 2824 SetBreakPoint(foo, 3);
2804 step_action = StepNext; 2825 step_action = StepNext;
2805 break_point_hit_count = 0; 2826 break_point_hit_count = 0;
2806 foo->Call(context, env->Global(), kArgc, args).ToLocalChecked(); 2827 foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
2807 2828
2808 // With stepping all break locations are hit. 2829 // With stepping all break locations are hit.
2809 CHECK_EQ(45, break_point_hit_count); 2830 CHECK_EQ(45, break_point_hit_count);
2810 2831
2811 v8::Debug::SetDebugEventListener(NULL); 2832 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2812 CheckDebuggerUnloaded(); 2833 CheckDebuggerUnloaded(env->GetIsolate());
2813 } 2834 }
2814 2835
2815 2836
2816 // Test of the stepping mechanism for keyed store in a loop. 2837 // Test of the stepping mechanism for keyed store in a loop.
2817 TEST(DebugStepKeyedStoreLoop) { 2838 TEST(DebugStepKeyedStoreLoop) {
2818 DebugLocalContext env; 2839 DebugLocalContext env;
2819 v8::HandleScope scope(env->GetIsolate()); 2840 v8::HandleScope scope(env->GetIsolate());
2820 2841
2821 // Register a debug event listener which steps and counts. 2842 // Register a debug event listener which steps and counts.
2822 v8::Debug::SetDebugEventListener(DebugEventStep); 2843 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2823 2844
2824 // Create a function for testing stepping of keyed store. The statement 'y=1' 2845 // Create a function for testing stepping of keyed store. The statement 'y=1'
2825 // is there to have more than one breakable statement in the loop, TODO(315). 2846 // is there to have more than one breakable statement in the loop, TODO(315).
2826 v8::Local<v8::Function> foo = CompileFunction( 2847 v8::Local<v8::Function> foo = CompileFunction(
2827 &env, 2848 &env,
2828 "function foo(a) {\n" 2849 "function foo(a) {\n"
2829 " var len = a.length;\n" 2850 " var len = a.length;\n"
2830 " for (var i = 0; i < len; i++) {\n" 2851 " for (var i = 0; i < len; i++) {\n"
2831 " y = 1;\n" 2852 " y = 1;\n"
2832 " a[i] = 42;\n" 2853 " a[i] = 42;\n"
(...skipping 18 matching lines...) Expand all
2851 2872
2852 // Set up break point and step through the function. 2873 // Set up break point and step through the function.
2853 SetBreakPoint(foo, 3); 2874 SetBreakPoint(foo, 3);
2854 step_action = StepNext; 2875 step_action = StepNext;
2855 break_point_hit_count = 0; 2876 break_point_hit_count = 0;
2856 foo->Call(context, env->Global(), kArgc, args).ToLocalChecked(); 2877 foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
2857 2878
2858 // With stepping all break locations are hit. 2879 // With stepping all break locations are hit.
2859 CHECK_EQ(44, break_point_hit_count); 2880 CHECK_EQ(44, break_point_hit_count);
2860 2881
2861 v8::Debug::SetDebugEventListener(NULL); 2882 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2862 CheckDebuggerUnloaded(); 2883 CheckDebuggerUnloaded(env->GetIsolate());
2863 } 2884 }
2864 2885
2865 2886
2866 // Test of the stepping mechanism for named load in a loop. 2887 // Test of the stepping mechanism for named load in a loop.
2867 TEST(DebugStepNamedLoadLoop) { 2888 TEST(DebugStepNamedLoadLoop) {
2868 DebugLocalContext env; 2889 DebugLocalContext env;
2869 v8::HandleScope scope(env->GetIsolate()); 2890 v8::HandleScope scope(env->GetIsolate());
2870 2891
2871 // Register a debug event listener which steps and counts. 2892 // Register a debug event listener which steps and counts.
2872 v8::Debug::SetDebugEventListener(DebugEventStep); 2893 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2873 2894
2874 v8::Local<v8::Context> context = env.context(); 2895 v8::Local<v8::Context> context = env.context();
2875 // Create a function for testing stepping of named load. 2896 // Create a function for testing stepping of named load.
2876 v8::Local<v8::Function> foo = CompileFunction( 2897 v8::Local<v8::Function> foo = CompileFunction(
2877 &env, 2898 &env,
2878 "function foo() {\n" 2899 "function foo() {\n"
2879 " var a = [];\n" 2900 " var a = [];\n"
2880 " var s = \"\";\n" 2901 " var s = \"\";\n"
2881 " for (var i = 0; i < 10; i++) {\n" 2902 " for (var i = 0; i < 10; i++) {\n"
2882 " var v = new V(i, i + 1);\n" 2903 " var v = new V(i, i + 1);\n"
(...skipping 13 matching lines...) Expand all
2896 2917
2897 // Set up break point and step through the function. 2918 // Set up break point and step through the function.
2898 SetBreakPoint(foo, 4); 2919 SetBreakPoint(foo, 4);
2899 step_action = StepNext; 2920 step_action = StepNext;
2900 break_point_hit_count = 0; 2921 break_point_hit_count = 0;
2901 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2922 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2902 2923
2903 // With stepping all break locations are hit. 2924 // With stepping all break locations are hit.
2904 CHECK_EQ(65, break_point_hit_count); 2925 CHECK_EQ(65, break_point_hit_count);
2905 2926
2906 v8::Debug::SetDebugEventListener(NULL); 2927 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2907 CheckDebuggerUnloaded(); 2928 CheckDebuggerUnloaded(env->GetIsolate());
2908 } 2929 }
2909 2930
2910 2931
2911 static void DoDebugStepNamedStoreLoop(int expected) { 2932 static void DoDebugStepNamedStoreLoop(int expected) {
2912 DebugLocalContext env; 2933 DebugLocalContext env;
2913 v8::HandleScope scope(env->GetIsolate()); 2934 v8::HandleScope scope(env->GetIsolate());
2914 2935
2915 // Register a debug event listener which steps and counts. 2936 // Register a debug event listener which steps and counts.
2916 v8::Debug::SetDebugEventListener(DebugEventStep); 2937 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2917 2938
2918 // Create a function for testing stepping of named store. 2939 // Create a function for testing stepping of named store.
2919 v8::Local<v8::Context> context = env.context(); 2940 v8::Local<v8::Context> context = env.context();
2920 v8::Local<v8::Function> foo = CompileFunction( 2941 v8::Local<v8::Function> foo = CompileFunction(
2921 &env, 2942 &env,
2922 "function foo() {\n" 2943 "function foo() {\n"
2923 " var a = {a:1};\n" 2944 " var a = {a:1};\n"
2924 " for (var i = 0; i < 10; i++) {\n" 2945 " for (var i = 0; i < 10; i++) {\n"
2925 " a.a = 2\n" 2946 " a.a = 2\n"
2926 " }\n" 2947 " }\n"
2927 "}\n", 2948 "}\n",
2928 "foo"); 2949 "foo");
2929 2950
2930 // Call function without any break points to ensure inlining is in place. 2951 // Call function without any break points to ensure inlining is in place.
2931 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2952 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2932 2953
2933 // Set up break point and step through the function. 2954 // Set up break point and step through the function.
2934 SetBreakPoint(foo, 3); 2955 SetBreakPoint(foo, 3);
2935 step_action = StepNext; 2956 step_action = StepNext;
2936 break_point_hit_count = 0; 2957 break_point_hit_count = 0;
2937 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2958 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2938 2959
2939 // With stepping all expected break locations are hit. 2960 // With stepping all expected break locations are hit.
2940 CHECK_EQ(expected, break_point_hit_count); 2961 CHECK_EQ(expected, break_point_hit_count);
2941 2962
2942 v8::Debug::SetDebugEventListener(NULL); 2963 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2943 CheckDebuggerUnloaded(); 2964 CheckDebuggerUnloaded(env->GetIsolate());
2944 } 2965 }
2945 2966
2946 2967
2947 // Test of the stepping mechanism for named load in a loop. 2968 // Test of the stepping mechanism for named load in a loop.
2948 TEST(DebugStepNamedStoreLoop) { DoDebugStepNamedStoreLoop(34); } 2969 TEST(DebugStepNamedStoreLoop) { DoDebugStepNamedStoreLoop(34); }
2949 2970
2950 2971
2951 // Test the stepping mechanism with different ICs. 2972 // Test the stepping mechanism with different ICs.
2952 TEST(DebugStepLinearMixedICs) { 2973 TEST(DebugStepLinearMixedICs) {
2953 DebugLocalContext env; 2974 DebugLocalContext env;
2954 v8::HandleScope scope(env->GetIsolate()); 2975 v8::HandleScope scope(env->GetIsolate());
2955 2976
2956 // Register a debug event listener which steps and counts. 2977 // Register a debug event listener which steps and counts.
2957 v8::Debug::SetDebugEventListener(DebugEventStep); 2978 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
2958 2979
2959 v8::Local<v8::Context> context = env.context(); 2980 v8::Local<v8::Context> context = env.context();
2960 // Create a function for testing stepping. 2981 // Create a function for testing stepping.
2961 v8::Local<v8::Function> foo = CompileFunction(&env, 2982 v8::Local<v8::Function> foo = CompileFunction(&env,
2962 "function bar() {};" 2983 "function bar() {};"
2963 "function foo() {" 2984 "function foo() {"
2964 " var x;" 2985 " var x;"
2965 " var index='name';" 2986 " var index='name';"
2966 " var y = {};" 2987 " var y = {};"
2967 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo"); 2988 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo");
2968 2989
2969 // Run functions to allow them to get optimized. 2990 // Run functions to allow them to get optimized.
2970 CompileRun("a=0; b=0; bar(); foo();"); 2991 CompileRun("a=0; b=0; bar(); foo();");
2971 2992
2972 SetBreakPoint(foo, 0); 2993 SetBreakPoint(foo, 0);
2973 2994
2974 step_action = StepIn; 2995 step_action = StepIn;
2975 break_point_hit_count = 0; 2996 break_point_hit_count = 0;
2976 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 2997 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2977 2998
2978 // With stepping all break locations are hit. 2999 // With stepping all break locations are hit.
2979 CHECK_EQ(11, break_point_hit_count); 3000 CHECK_EQ(11, break_point_hit_count);
2980 3001
2981 v8::Debug::SetDebugEventListener(NULL); 3002 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2982 CheckDebuggerUnloaded(); 3003 CheckDebuggerUnloaded(env->GetIsolate());
2983 3004
2984 // Register a debug event listener which just counts. 3005 // Register a debug event listener which just counts.
2985 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 3006 v8::Debug::SetDebugEventListener(env->GetIsolate(),
3007 DebugEventBreakPointHitCount);
2986 3008
2987 SetBreakPoint(foo, 0); 3009 SetBreakPoint(foo, 0);
2988 break_point_hit_count = 0; 3010 break_point_hit_count = 0;
2989 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3011 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2990 3012
2991 // Without stepping only active break points are hit. 3013 // Without stepping only active break points are hit.
2992 CHECK_EQ(1, break_point_hit_count); 3014 CHECK_EQ(1, break_point_hit_count);
2993 3015
2994 v8::Debug::SetDebugEventListener(NULL); 3016 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2995 CheckDebuggerUnloaded(); 3017 CheckDebuggerUnloaded(env->GetIsolate());
2996 } 3018 }
2997 3019
2998 3020
2999 TEST(DebugStepDeclarations) { 3021 TEST(DebugStepDeclarations) {
3000 DebugLocalContext env; 3022 DebugLocalContext env;
3001 v8::HandleScope scope(env->GetIsolate()); 3023 v8::HandleScope scope(env->GetIsolate());
3002 3024
3003 // Register a debug event listener which steps and counts. 3025 // Register a debug event listener which steps and counts.
3004 v8::Debug::SetDebugEventListener(DebugEventStep); 3026 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3005 3027
3006 v8::Local<v8::Context> context = env.context(); 3028 v8::Local<v8::Context> context = env.context();
3007 // Create a function for testing stepping. Run it to allow it to get 3029 // Create a function for testing stepping. Run it to allow it to get
3008 // optimized. 3030 // optimized.
3009 const char* src = "function foo() { " 3031 const char* src = "function foo() { "
3010 " var a;" 3032 " var a;"
3011 " var b = 1;" 3033 " var b = 1;"
3012 " var c = foo;" 3034 " var c = foo;"
3013 " var d = Math.floor;" 3035 " var d = Math.floor;"
3014 " var e = b + d(1.2);" 3036 " var e = b + d(1.2);"
3015 "}" 3037 "}"
3016 "foo()"; 3038 "foo()";
3017 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); 3039 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3018 3040
3019 SetBreakPoint(foo, 0); 3041 SetBreakPoint(foo, 0);
3020 3042
3021 // Stepping through the declarations. 3043 // Stepping through the declarations.
3022 step_action = StepIn; 3044 step_action = StepIn;
3023 break_point_hit_count = 0; 3045 break_point_hit_count = 0;
3024 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3046 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3025 CHECK_EQ(6, break_point_hit_count); 3047 CHECK_EQ(6, break_point_hit_count);
3026 3048
3027 // Get rid of the debug event listener. 3049 // Get rid of the debug event listener.
3028 v8::Debug::SetDebugEventListener(NULL); 3050 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3029 CheckDebuggerUnloaded(); 3051 CheckDebuggerUnloaded(env->GetIsolate());
3030 } 3052 }
3031 3053
3032 3054
3033 TEST(DebugStepLocals) { 3055 TEST(DebugStepLocals) {
3034 DebugLocalContext env; 3056 DebugLocalContext env;
3035 v8::HandleScope scope(env->GetIsolate()); 3057 v8::HandleScope scope(env->GetIsolate());
3036 3058
3037 // Register a debug event listener which steps and counts. 3059 // Register a debug event listener which steps and counts.
3038 v8::Debug::SetDebugEventListener(DebugEventStep); 3060 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3039 3061
3040 v8::Local<v8::Context> context = env.context(); 3062 v8::Local<v8::Context> context = env.context();
3041 // Create a function for testing stepping. Run it to allow it to get 3063 // Create a function for testing stepping. Run it to allow it to get
3042 // optimized. 3064 // optimized.
3043 const char* src = "function foo() { " 3065 const char* src = "function foo() { "
3044 " var a,b;" 3066 " var a,b;"
3045 " a = 1;" 3067 " a = 1;"
3046 " b = a + 2;" 3068 " b = a + 2;"
3047 " b = 1 + 2 + 3;" 3069 " b = 1 + 2 + 3;"
3048 " a = Math.floor(b);" 3070 " a = Math.floor(b);"
3049 "}" 3071 "}"
3050 "foo()"; 3072 "foo()";
3051 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); 3073 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3052 3074
3053 SetBreakPoint(foo, 0); 3075 SetBreakPoint(foo, 0);
3054 3076
3055 // Stepping through the declarations. 3077 // Stepping through the declarations.
3056 step_action = StepIn; 3078 step_action = StepIn;
3057 break_point_hit_count = 0; 3079 break_point_hit_count = 0;
3058 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3080 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3059 CHECK_EQ(6, break_point_hit_count); 3081 CHECK_EQ(6, break_point_hit_count);
3060 3082
3061 // Get rid of the debug event listener. 3083 // Get rid of the debug event listener.
3062 v8::Debug::SetDebugEventListener(NULL); 3084 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3063 CheckDebuggerUnloaded(); 3085 CheckDebuggerUnloaded(env->GetIsolate());
3064 } 3086 }
3065 3087
3066 3088
3067 TEST(DebugStepIf) { 3089 TEST(DebugStepIf) {
3068 DebugLocalContext env; 3090 DebugLocalContext env;
3069 v8::Isolate* isolate = env->GetIsolate(); 3091 v8::Isolate* isolate = env->GetIsolate();
3070 v8::HandleScope scope(isolate); 3092 v8::HandleScope scope(isolate);
3071 3093
3072 // Register a debug event listener which steps and counts. 3094 // Register a debug event listener which steps and counts.
3073 v8::Debug::SetDebugEventListener(DebugEventStep); 3095 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3074 3096
3075 v8::Local<v8::Context> context = env.context(); 3097 v8::Local<v8::Context> context = env.context();
3076 // Create a function for testing stepping. Run it to allow it to get 3098 // Create a function for testing stepping. Run it to allow it to get
3077 // optimized. 3099 // optimized.
3078 const int argc = 1; 3100 const int argc = 1;
3079 const char* src = "function foo(x) { " 3101 const char* src = "function foo(x) { "
3080 " a = 1;" 3102 " a = 1;"
3081 " if (x) {" 3103 " if (x) {"
3082 " b = 1;" 3104 " b = 1;"
3083 " } else {" 3105 " } else {"
(...skipping 13 matching lines...) Expand all
3097 CHECK_EQ(4, break_point_hit_count); 3119 CHECK_EQ(4, break_point_hit_count);
3098 3120
3099 // Stepping through the false part. 3121 // Stepping through the false part.
3100 step_action = StepIn; 3122 step_action = StepIn;
3101 break_point_hit_count = 0; 3123 break_point_hit_count = 0;
3102 v8::Local<v8::Value> argv_false[argc] = {v8::False(isolate)}; 3124 v8::Local<v8::Value> argv_false[argc] = {v8::False(isolate)};
3103 foo->Call(context, env->Global(), argc, argv_false).ToLocalChecked(); 3125 foo->Call(context, env->Global(), argc, argv_false).ToLocalChecked();
3104 CHECK_EQ(5, break_point_hit_count); 3126 CHECK_EQ(5, break_point_hit_count);
3105 3127
3106 // Get rid of the debug event listener. 3128 // Get rid of the debug event listener.
3107 v8::Debug::SetDebugEventListener(NULL); 3129 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3108 CheckDebuggerUnloaded(); 3130 CheckDebuggerUnloaded(isolate);
3109 } 3131 }
3110 3132
3111 3133
3112 TEST(DebugStepSwitch) { 3134 TEST(DebugStepSwitch) {
3113 DebugLocalContext env; 3135 DebugLocalContext env;
3114 v8::Isolate* isolate = env->GetIsolate(); 3136 v8::Isolate* isolate = env->GetIsolate();
3115 v8::HandleScope scope(isolate); 3137 v8::HandleScope scope(isolate);
3116 3138
3117 // Register a debug event listener which steps and counts. 3139 // Register a debug event listener which steps and counts.
3118 v8::Debug::SetDebugEventListener(DebugEventStep); 3140 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3119 3141
3120 v8::Local<v8::Context> context = env.context(); 3142 v8::Local<v8::Context> context = env.context();
3121 // Create a function for testing stepping. Run it to allow it to get 3143 // Create a function for testing stepping. Run it to allow it to get
3122 // optimized. 3144 // optimized.
3123 const int argc = 1; 3145 const int argc = 1;
3124 const char* src = "function foo(x) { " 3146 const char* src = "function foo(x) { "
3125 " a = 1;" 3147 " a = 1;"
3126 " switch (x) {" 3148 " switch (x) {"
3127 " case 1:" 3149 " case 1:"
3128 " b = 1;" 3150 " b = 1;"
(...skipping 26 matching lines...) Expand all
3155 CHECK_EQ(5, break_point_hit_count); 3177 CHECK_EQ(5, break_point_hit_count);
3156 3178
3157 // Last case. 3179 // Last case.
3158 step_action = StepIn; 3180 step_action = StepIn;
3159 break_point_hit_count = 0; 3181 break_point_hit_count = 0;
3160 v8::Local<v8::Value> argv_3[argc] = {v8::Number::New(isolate, 3)}; 3182 v8::Local<v8::Value> argv_3[argc] = {v8::Number::New(isolate, 3)};
3161 foo->Call(context, env->Global(), argc, argv_3).ToLocalChecked(); 3183 foo->Call(context, env->Global(), argc, argv_3).ToLocalChecked();
3162 CHECK_EQ(7, break_point_hit_count); 3184 CHECK_EQ(7, break_point_hit_count);
3163 3185
3164 // Get rid of the debug event listener. 3186 // Get rid of the debug event listener.
3165 v8::Debug::SetDebugEventListener(NULL); 3187 v8::Debug::SetDebugEventListener(isolate, nullptr);
3166 CheckDebuggerUnloaded(); 3188 CheckDebuggerUnloaded(isolate);
3167 } 3189 }
3168 3190
3169 3191
3170 TEST(DebugStepWhile) { 3192 TEST(DebugStepWhile) {
3171 DebugLocalContext env; 3193 DebugLocalContext env;
3172 v8::Isolate* isolate = env->GetIsolate(); 3194 v8::Isolate* isolate = env->GetIsolate();
3173 v8::HandleScope scope(isolate); 3195 v8::HandleScope scope(isolate);
3174 3196
3175 // Register a debug event listener which steps and counts. 3197 // Register a debug event listener which steps and counts.
3176 v8::Debug::SetDebugEventListener(DebugEventStep); 3198 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3177 3199
3178 v8::Local<v8::Context> context = env.context(); 3200 v8::Local<v8::Context> context = env.context();
3179 // Create a function for testing stepping. Run it to allow it to get 3201 // Create a function for testing stepping. Run it to allow it to get
3180 // optimized. 3202 // optimized.
3181 const int argc = 1; 3203 const int argc = 1;
3182 const char* src = "function foo(x) { " 3204 const char* src = "function foo(x) { "
3183 " var a = 0;" 3205 " var a = 0;"
3184 " while (a < x) {" 3206 " while (a < x) {"
3185 " a++;" 3207 " a++;"
3186 " }" 3208 " }"
(...skipping 17 matching lines...) Expand all
3204 CHECK_EQ(23, break_point_hit_count); 3226 CHECK_EQ(23, break_point_hit_count);
3205 3227
3206 // Looping 100 times. 3228 // Looping 100 times.
3207 step_action = StepIn; 3229 step_action = StepIn;
3208 break_point_hit_count = 0; 3230 break_point_hit_count = 0;
3209 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)}; 3231 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
3210 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked(); 3232 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
3211 CHECK_EQ(203, break_point_hit_count); 3233 CHECK_EQ(203, break_point_hit_count);
3212 3234
3213 // Get rid of the debug event listener. 3235 // Get rid of the debug event listener.
3214 v8::Debug::SetDebugEventListener(NULL); 3236 v8::Debug::SetDebugEventListener(isolate, nullptr);
3215 CheckDebuggerUnloaded(); 3237 CheckDebuggerUnloaded(isolate);
3216 } 3238 }
3217 3239
3218 3240
3219 TEST(DebugStepDoWhile) { 3241 TEST(DebugStepDoWhile) {
3220 DebugLocalContext env; 3242 DebugLocalContext env;
3221 v8::Isolate* isolate = env->GetIsolate(); 3243 v8::Isolate* isolate = env->GetIsolate();
3222 v8::HandleScope scope(isolate); 3244 v8::HandleScope scope(isolate);
3223 3245
3224 // Register a debug event listener which steps and counts. 3246 // Register a debug event listener which steps and counts.
3225 v8::Debug::SetDebugEventListener(DebugEventStep); 3247 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3226 3248
3227 v8::Local<v8::Context> context = env.context(); 3249 v8::Local<v8::Context> context = env.context();
3228 // Create a function for testing stepping. Run it to allow it to get 3250 // Create a function for testing stepping. Run it to allow it to get
3229 // optimized. 3251 // optimized.
3230 const int argc = 1; 3252 const int argc = 1;
3231 const char* src = "function foo(x) { " 3253 const char* src = "function foo(x) { "
3232 " var a = 0;" 3254 " var a = 0;"
3233 " do {" 3255 " do {"
3234 " a++;" 3256 " a++;"
3235 " } while (a < x)" 3257 " } while (a < x)"
(...skipping 17 matching lines...) Expand all
3253 CHECK_EQ(22, break_point_hit_count); 3275 CHECK_EQ(22, break_point_hit_count);
3254 3276
3255 // Looping 100 times. 3277 // Looping 100 times.
3256 step_action = StepIn; 3278 step_action = StepIn;
3257 break_point_hit_count = 0; 3279 break_point_hit_count = 0;
3258 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)}; 3280 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
3259 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked(); 3281 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
3260 CHECK_EQ(202, break_point_hit_count); 3282 CHECK_EQ(202, break_point_hit_count);
3261 3283
3262 // Get rid of the debug event listener. 3284 // Get rid of the debug event listener.
3263 v8::Debug::SetDebugEventListener(NULL); 3285 v8::Debug::SetDebugEventListener(isolate, nullptr);
3264 CheckDebuggerUnloaded(); 3286 CheckDebuggerUnloaded(isolate);
3265 } 3287 }
3266 3288
3267 3289
3268 TEST(DebugStepFor) { 3290 TEST(DebugStepFor) {
3269 DebugLocalContext env; 3291 DebugLocalContext env;
3270 v8::Isolate* isolate = env->GetIsolate(); 3292 v8::Isolate* isolate = env->GetIsolate();
3271 v8::HandleScope scope(isolate); 3293 v8::HandleScope scope(isolate);
3272 3294
3273 // Register a debug event listener which steps and counts. 3295 // Register a debug event listener which steps and counts.
3274 v8::Debug::SetDebugEventListener(DebugEventStep); 3296 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3275 3297
3276 v8::Local<v8::Context> context = env.context(); 3298 v8::Local<v8::Context> context = env.context();
3277 // Create a function for testing stepping. Run it to allow it to get 3299 // Create a function for testing stepping. Run it to allow it to get
3278 // optimized. 3300 // optimized.
3279 const int argc = 1; 3301 const int argc = 1;
3280 const char* src = "function foo(x) { " 3302 const char* src = "function foo(x) { "
3281 " a = 1;" 3303 " a = 1;"
3282 " for (i = 0; i < x; i++) {" 3304 " for (i = 0; i < x; i++) {"
3283 " b = 1;" 3305 " b = 1;"
3284 " }" 3306 " }"
(...skipping 18 matching lines...) Expand all
3303 CHECK_EQ(34, break_point_hit_count); 3325 CHECK_EQ(34, break_point_hit_count);
3304 3326
3305 // Looping 100 times. 3327 // Looping 100 times.
3306 step_action = StepIn; 3328 step_action = StepIn;
3307 break_point_hit_count = 0; 3329 break_point_hit_count = 0;
3308 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)}; 3330 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
3309 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked(); 3331 foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
3310 CHECK_EQ(304, break_point_hit_count); 3332 CHECK_EQ(304, break_point_hit_count);
3311 3333
3312 // Get rid of the debug event listener. 3334 // Get rid of the debug event listener.
3313 v8::Debug::SetDebugEventListener(NULL); 3335 v8::Debug::SetDebugEventListener(isolate, nullptr);
3314 CheckDebuggerUnloaded(); 3336 CheckDebuggerUnloaded(isolate);
3315 } 3337 }
3316 3338
3317 3339
3318 TEST(DebugStepForContinue) { 3340 TEST(DebugStepForContinue) {
3319 DebugLocalContext env; 3341 DebugLocalContext env;
3320 v8::Isolate* isolate = env->GetIsolate(); 3342 v8::Isolate* isolate = env->GetIsolate();
3321 v8::HandleScope scope(isolate); 3343 v8::HandleScope scope(isolate);
3322 3344
3323 // Register a debug event listener which steps and counts. 3345 // Register a debug event listener which steps and counts.
3324 v8::Debug::SetDebugEventListener(DebugEventStep); 3346 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3325 3347
3326 v8::Local<v8::Context> context = env.context(); 3348 v8::Local<v8::Context> context = env.context();
3327 // Create a function for testing stepping. Run it to allow it to get 3349 // Create a function for testing stepping. Run it to allow it to get
3328 // optimized. 3350 // optimized.
3329 const int argc = 1; 3351 const int argc = 1;
3330 const char* src = "function foo(x) { " 3352 const char* src = "function foo(x) { "
3331 " var a = 0;" 3353 " var a = 0;"
3332 " var b = 0;" 3354 " var b = 0;"
3333 " var c = 0;" 3355 " var c = 0;"
3334 " for (var i = 0; i < x; i++) {" 3356 " for (var i = 0; i < x; i++) {"
(...skipping 21 matching lines...) Expand all
3356 3378
3357 // Looping 100 times. 3379 // Looping 100 times.
3358 step_action = StepIn; 3380 step_action = StepIn;
3359 break_point_hit_count = 0; 3381 break_point_hit_count = 0;
3360 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)}; 3382 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
3361 result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked(); 3383 result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
3362 CHECK_EQ(50, result->Int32Value(context).FromJust()); 3384 CHECK_EQ(50, result->Int32Value(context).FromJust());
3363 CHECK_EQ(557, break_point_hit_count); 3385 CHECK_EQ(557, break_point_hit_count);
3364 3386
3365 // Get rid of the debug event listener. 3387 // Get rid of the debug event listener.
3366 v8::Debug::SetDebugEventListener(NULL); 3388 v8::Debug::SetDebugEventListener(isolate, nullptr);
3367 CheckDebuggerUnloaded(); 3389 CheckDebuggerUnloaded(isolate);
3368 } 3390 }
3369 3391
3370 3392
3371 TEST(DebugStepForBreak) { 3393 TEST(DebugStepForBreak) {
3372 DebugLocalContext env; 3394 DebugLocalContext env;
3373 v8::Isolate* isolate = env->GetIsolate(); 3395 v8::Isolate* isolate = env->GetIsolate();
3374 v8::HandleScope scope(isolate); 3396 v8::HandleScope scope(isolate);
3375 3397
3376 // Register a debug event listener which steps and counts. 3398 // Register a debug event listener which steps and counts.
3377 v8::Debug::SetDebugEventListener(DebugEventStep); 3399 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3378 3400
3379 v8::Local<v8::Context> context = env.context(); 3401 v8::Local<v8::Context> context = env.context();
3380 // Create a function for testing stepping. Run it to allow it to get 3402 // Create a function for testing stepping. Run it to allow it to get
3381 // optimized. 3403 // optimized.
3382 const int argc = 1; 3404 const int argc = 1;
3383 const char* src = "function foo(x) { " 3405 const char* src = "function foo(x) { "
3384 " var a = 0;" 3406 " var a = 0;"
3385 " var b = 0;" 3407 " var b = 0;"
3386 " var c = 0;" 3408 " var c = 0;"
3387 " for (var i = 0; i < 1000; i++) {" 3409 " for (var i = 0; i < 1000; i++) {"
(...skipping 22 matching lines...) Expand all
3410 3432
3411 // Looping 100 times. 3433 // Looping 100 times.
3412 step_action = StepIn; 3434 step_action = StepIn;
3413 break_point_hit_count = 0; 3435 break_point_hit_count = 0;
3414 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)}; 3436 v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
3415 result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked(); 3437 result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
3416 CHECK_EQ(99, result->Int32Value(context).FromJust()); 3438 CHECK_EQ(99, result->Int32Value(context).FromJust());
3417 CHECK_EQ(604, break_point_hit_count); 3439 CHECK_EQ(604, break_point_hit_count);
3418 3440
3419 // Get rid of the debug event listener. 3441 // Get rid of the debug event listener.
3420 v8::Debug::SetDebugEventListener(NULL); 3442 v8::Debug::SetDebugEventListener(isolate, nullptr);
3421 CheckDebuggerUnloaded(); 3443 CheckDebuggerUnloaded(isolate);
3422 } 3444 }
3423 3445
3424 3446
3425 TEST(DebugStepForIn) { 3447 TEST(DebugStepForIn) {
3426 DebugLocalContext env; 3448 DebugLocalContext env;
3427 v8::HandleScope scope(env->GetIsolate()); 3449 v8::HandleScope scope(env->GetIsolate());
3428 3450
3429 // Register a debug event listener which steps and counts. 3451 // Register a debug event listener which steps and counts.
3430 v8::Debug::SetDebugEventListener(DebugEventStep); 3452 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3431 3453
3432 v8::Local<v8::Context> context = env.context(); 3454 v8::Local<v8::Context> context = env.context();
3433 // Create a function for testing stepping. Run it to allow it to get 3455 // Create a function for testing stepping. Run it to allow it to get
3434 // optimized. 3456 // optimized.
3435 v8::Local<v8::Function> foo; 3457 v8::Local<v8::Function> foo;
3436 const char* src_1 = "function foo() { " 3458 const char* src_1 = "function foo() { "
3437 " var a = [1, 2];" 3459 " var a = [1, 2];"
3438 " for (x in a) {" 3460 " for (x in a) {"
3439 " b = 0;" 3461 " b = 0;"
3440 " }" 3462 " }"
(...skipping 18 matching lines...) Expand all
3459 "foo()"; 3481 "foo()";
3460 foo = CompileFunction(&env, src_2, "foo"); 3482 foo = CompileFunction(&env, src_2, "foo");
3461 SetBreakPoint(foo, 0); // "var a = ..." 3483 SetBreakPoint(foo, 0); // "var a = ..."
3462 3484
3463 step_action = StepIn; 3485 step_action = StepIn;
3464 break_point_hit_count = 0; 3486 break_point_hit_count = 0;
3465 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3487 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3466 CHECK_EQ(10, break_point_hit_count); 3488 CHECK_EQ(10, break_point_hit_count);
3467 3489
3468 // Get rid of the debug event listener. 3490 // Get rid of the debug event listener.
3469 v8::Debug::SetDebugEventListener(NULL); 3491 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3470 CheckDebuggerUnloaded(); 3492 CheckDebuggerUnloaded(env->GetIsolate());
3471 } 3493 }
3472 3494
3473 3495
3474 TEST(DebugStepWith) { 3496 TEST(DebugStepWith) {
3475 DebugLocalContext env; 3497 DebugLocalContext env;
3476 v8::HandleScope scope(env->GetIsolate()); 3498 v8::HandleScope scope(env->GetIsolate());
3477 3499
3478 // Register a debug event listener which steps and counts. 3500 // Register a debug event listener which steps and counts.
3479 v8::Debug::SetDebugEventListener(DebugEventStep); 3501 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3480 3502
3481 v8::Local<v8::Context> context = env.context(); 3503 v8::Local<v8::Context> context = env.context();
3482 // Create a function for testing stepping. Run it to allow it to get 3504 // Create a function for testing stepping. Run it to allow it to get
3483 // optimized. 3505 // optimized.
3484 const char* src = "function foo(x) { " 3506 const char* src = "function foo(x) { "
3485 " var a = {};" 3507 " var a = {};"
3486 " with (a) {}" 3508 " with (a) {}"
3487 " with (b) {}" 3509 " with (b) {}"
3488 "}" 3510 "}"
3489 "foo()"; 3511 "foo()";
3490 CHECK(env->Global() 3512 CHECK(env->Global()
3491 ->Set(context, v8_str(env->GetIsolate(), "b"), 3513 ->Set(context, v8_str(env->GetIsolate(), "b"),
3492 v8::Object::New(env->GetIsolate())) 3514 v8::Object::New(env->GetIsolate()))
3493 .FromJust()); 3515 .FromJust());
3494 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); 3516 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3495 v8::Local<v8::Value> result; 3517 v8::Local<v8::Value> result;
3496 SetBreakPoint(foo, 8); // "var a = {};" 3518 SetBreakPoint(foo, 8); // "var a = {};"
3497 3519
3498 step_action = StepIn; 3520 step_action = StepIn;
3499 break_point_hit_count = 0; 3521 break_point_hit_count = 0;
3500 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3522 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3501 CHECK_EQ(4, break_point_hit_count); 3523 CHECK_EQ(4, break_point_hit_count);
3502 3524
3503 // Get rid of the debug event listener. 3525 // Get rid of the debug event listener.
3504 v8::Debug::SetDebugEventListener(NULL); 3526 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3505 CheckDebuggerUnloaded(); 3527 CheckDebuggerUnloaded(env->GetIsolate());
3506 } 3528 }
3507 3529
3508 3530
3509 TEST(DebugConditional) { 3531 TEST(DebugConditional) {
3510 DebugLocalContext env; 3532 DebugLocalContext env;
3511 v8::Isolate* isolate = env->GetIsolate(); 3533 v8::Isolate* isolate = env->GetIsolate();
3512 v8::HandleScope scope(isolate); 3534 v8::HandleScope scope(isolate);
3513 3535
3514 // Register a debug event listener which steps and counts. 3536 // Register a debug event listener which steps and counts.
3515 v8::Debug::SetDebugEventListener(DebugEventStep); 3537 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3516 3538
3517 v8::Local<v8::Context> context = env.context(); 3539 v8::Local<v8::Context> context = env.context();
3518 // Create a function for testing stepping. Run it to allow it to get 3540 // Create a function for testing stepping. Run it to allow it to get
3519 // optimized. 3541 // optimized.
3520 const char* src = "function foo(x) { " 3542 const char* src = "function foo(x) { "
3521 " var a;" 3543 " var a;"
3522 " a = x ? 1 : 2;" 3544 " a = x ? 1 : 2;"
3523 " return a;" 3545 " return a;"
3524 "}" 3546 "}"
3525 "foo()"; 3547 "foo()";
3526 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); 3548 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3527 SetBreakPoint(foo, 0); // "var a;" 3549 SetBreakPoint(foo, 0); // "var a;"
3528 3550
3529 step_action = StepIn; 3551 step_action = StepIn;
3530 break_point_hit_count = 0; 3552 break_point_hit_count = 0;
3531 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3553 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3532 CHECK_EQ(4, break_point_hit_count); 3554 CHECK_EQ(4, break_point_hit_count);
3533 3555
3534 step_action = StepIn; 3556 step_action = StepIn;
3535 break_point_hit_count = 0; 3557 break_point_hit_count = 0;
3536 const int argc = 1; 3558 const int argc = 1;
3537 v8::Local<v8::Value> argv_true[argc] = {v8::True(isolate)}; 3559 v8::Local<v8::Value> argv_true[argc] = {v8::True(isolate)};
3538 foo->Call(context, env->Global(), argc, argv_true).ToLocalChecked(); 3560 foo->Call(context, env->Global(), argc, argv_true).ToLocalChecked();
3539 CHECK_EQ(4, break_point_hit_count); 3561 CHECK_EQ(4, break_point_hit_count);
3540 3562
3541 // Get rid of the debug event listener. 3563 // Get rid of the debug event listener.
3542 v8::Debug::SetDebugEventListener(NULL); 3564 v8::Debug::SetDebugEventListener(isolate, nullptr);
3543 CheckDebuggerUnloaded(); 3565 CheckDebuggerUnloaded(isolate);
3544 } 3566 }
3545 3567
3546 3568
3547 TEST(StepInOutSimple) { 3569 TEST(StepInOutSimple) {
3548 DebugLocalContext env; 3570 DebugLocalContext env;
3549 v8::HandleScope scope(env->GetIsolate()); 3571 v8::HandleScope scope(env->GetIsolate());
3550 3572
3551 // Create a function for checking the function when hitting a break point. 3573 // Create a function for checking the function when hitting a break point.
3552 frame_function_name = CompileFunction(&env, 3574 frame_function_name = CompileFunction(&env,
3553 frame_function_name_source, 3575 frame_function_name_source,
3554 "frame_function_name"); 3576 "frame_function_name");
3555 3577
3556 // Register a debug event listener which steps and counts. 3578 // Register a debug event listener which steps and counts.
3557 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3579 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStepSequence);
3558 3580
3559 v8::Local<v8::Context> context = env.context(); 3581 v8::Local<v8::Context> context = env.context();
3560 // Create a function for testing stepping. Run it to allow it to get 3582 // Create a function for testing stepping. Run it to allow it to get
3561 // optimized. 3583 // optimized.
3562 const char* src = "function a() {b();c();}; " 3584 const char* src = "function a() {b();c();}; "
3563 "function b() {c();}; " 3585 "function b() {c();}; "
3564 "function c() {}; " 3586 "function c() {}; "
3565 "a(); b(); c()"; 3587 "a(); b(); c()";
3566 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); 3588 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3567 SetBreakPoint(a, 0); 3589 SetBreakPoint(a, 0);
(...skipping 16 matching lines...) Expand all
3584 3606
3585 // Step through invocation of a with step out. 3607 // Step through invocation of a with step out.
3586 step_action = StepOut; 3608 step_action = StepOut;
3587 break_point_hit_count = 0; 3609 break_point_hit_count = 0;
3588 expected_step_sequence = "a"; 3610 expected_step_sequence = "a";
3589 a->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3611 a->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3590 CHECK_EQ(StrLength(expected_step_sequence), 3612 CHECK_EQ(StrLength(expected_step_sequence),
3591 break_point_hit_count); 3613 break_point_hit_count);
3592 3614
3593 // Get rid of the debug event listener. 3615 // Get rid of the debug event listener.
3594 v8::Debug::SetDebugEventListener(NULL); 3616 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3595 CheckDebuggerUnloaded(); 3617 CheckDebuggerUnloaded(env->GetIsolate());
3596 } 3618 }
3597 3619
3598 3620
3599 TEST(StepInOutTree) { 3621 TEST(StepInOutTree) {
3600 DebugLocalContext env; 3622 DebugLocalContext env;
3601 v8::HandleScope scope(env->GetIsolate()); 3623 v8::HandleScope scope(env->GetIsolate());
3602 3624
3603 // Create a function for checking the function when hitting a break point. 3625 // Create a function for checking the function when hitting a break point.
3604 frame_function_name = CompileFunction(&env, 3626 frame_function_name = CompileFunction(&env,
3605 frame_function_name_source, 3627 frame_function_name_source,
3606 "frame_function_name"); 3628 "frame_function_name");
3607 3629
3608 // Register a debug event listener which steps and counts. 3630 // Register a debug event listener which steps and counts.
3609 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3631 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStepSequence);
3610 3632
3611 v8::Local<v8::Context> context = env.context(); 3633 v8::Local<v8::Context> context = env.context();
3612 // Create a function for testing stepping. Run it to allow it to get 3634 // Create a function for testing stepping. Run it to allow it to get
3613 // optimized. 3635 // optimized.
3614 const char* src = "function a() {b(c(d()),d());c(d());d()}; " 3636 const char* src = "function a() {b(c(d()),d());c(d());d()}; "
3615 "function b(x,y) {c();}; " 3637 "function b(x,y) {c();}; "
3616 "function c(x) {}; " 3638 "function c(x) {}; "
3617 "function d() {}; " 3639 "function d() {}; "
3618 "a(); b(); c(); d()"; 3640 "a(); b(); c(); d()";
3619 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); 3641 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
(...skipping 17 matching lines...) Expand all
3637 3659
3638 // Step through invocation of a with step out. 3660 // Step through invocation of a with step out.
3639 step_action = StepOut; 3661 step_action = StepOut;
3640 break_point_hit_count = 0; 3662 break_point_hit_count = 0;
3641 expected_step_sequence = "a"; 3663 expected_step_sequence = "a";
3642 a->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3664 a->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3643 CHECK_EQ(StrLength(expected_step_sequence), 3665 CHECK_EQ(StrLength(expected_step_sequence),
3644 break_point_hit_count); 3666 break_point_hit_count);
3645 3667
3646 // Get rid of the debug event listener. 3668 // Get rid of the debug event listener.
3647 v8::Debug::SetDebugEventListener(NULL); 3669 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3648 CheckDebuggerUnloaded(true); 3670 CheckDebuggerUnloaded(env->GetIsolate(), true);
3649 } 3671 }
3650 3672
3651 3673
3652 TEST(StepInOutBranch) { 3674 TEST(StepInOutBranch) {
3653 DebugLocalContext env; 3675 DebugLocalContext env;
3654 v8::HandleScope scope(env->GetIsolate()); 3676 v8::HandleScope scope(env->GetIsolate());
3655 3677
3656 // Create a function for checking the function when hitting a break point. 3678 // Create a function for checking the function when hitting a break point.
3657 frame_function_name = CompileFunction(&env, 3679 frame_function_name = CompileFunction(&env,
3658 frame_function_name_source, 3680 frame_function_name_source,
3659 "frame_function_name"); 3681 "frame_function_name");
3660 3682
3661 // Register a debug event listener which steps and counts. 3683 // Register a debug event listener which steps and counts.
3662 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3684 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStepSequence);
3663 3685
3664 v8::Local<v8::Context> context = env.context(); 3686 v8::Local<v8::Context> context = env.context();
3665 // Create a function for testing stepping. Run it to allow it to get 3687 // Create a function for testing stepping. Run it to allow it to get
3666 // optimized. 3688 // optimized.
3667 const char* src = "function a() {b(false);c();}; " 3689 const char* src = "function a() {b(false);c();}; "
3668 "function b(x) {if(x){c();};}; " 3690 "function b(x) {if(x){c();};}; "
3669 "function c() {}; " 3691 "function c() {}; "
3670 "a(); b(); c()"; 3692 "a(); b(); c()";
3671 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); 3693 v8::Local<v8::Function> a = CompileFunction(&env, src, "a");
3672 SetBreakPoint(a, 0); 3694 SetBreakPoint(a, 0);
3673 3695
3674 // Step through invocation of a. 3696 // Step through invocation of a.
3675 step_action = StepIn; 3697 step_action = StepIn;
3676 break_point_hit_count = 0; 3698 break_point_hit_count = 0;
3677 expected_step_sequence = "abbaca"; 3699 expected_step_sequence = "abbaca";
3678 a->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3700 a->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3679 CHECK_EQ(StrLength(expected_step_sequence), 3701 CHECK_EQ(StrLength(expected_step_sequence),
3680 break_point_hit_count); 3702 break_point_hit_count);
3681 3703
3682 // Get rid of the debug event listener. 3704 // Get rid of the debug event listener.
3683 v8::Debug::SetDebugEventListener(NULL); 3705 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3684 CheckDebuggerUnloaded(); 3706 CheckDebuggerUnloaded(env->GetIsolate());
3685 } 3707 }
3686 3708
3687 3709
3688 // Test that step in does not step into native functions. 3710 // Test that step in does not step into native functions.
3689 TEST(DebugStepNatives) { 3711 TEST(DebugStepNatives) {
3690 DebugLocalContext env; 3712 DebugLocalContext env;
3691 v8::HandleScope scope(env->GetIsolate()); 3713 v8::HandleScope scope(env->GetIsolate());
3692 3714
3693 // Create a function for testing stepping. 3715 // Create a function for testing stepping.
3694 v8::Local<v8::Function> foo = CompileFunction( 3716 v8::Local<v8::Function> foo = CompileFunction(
3695 &env, 3717 &env,
3696 "function foo(){debugger;Math.sin(1);}", 3718 "function foo(){debugger;Math.sin(1);}",
3697 "foo"); 3719 "foo");
3698 3720
3699 // Register a debug event listener which steps and counts. 3721 // Register a debug event listener which steps and counts.
3700 v8::Debug::SetDebugEventListener(DebugEventStep); 3722 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3701 3723
3702 v8::Local<v8::Context> context = env.context(); 3724 v8::Local<v8::Context> context = env.context();
3703 step_action = StepIn; 3725 step_action = StepIn;
3704 break_point_hit_count = 0; 3726 break_point_hit_count = 0;
3705 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3727 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3706 3728
3707 // With stepping all break locations are hit. 3729 // With stepping all break locations are hit.
3708 CHECK_EQ(3, break_point_hit_count); 3730 CHECK_EQ(3, break_point_hit_count);
3709 3731
3710 v8::Debug::SetDebugEventListener(NULL); 3732 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3711 CheckDebuggerUnloaded(); 3733 CheckDebuggerUnloaded(env->GetIsolate());
3712 3734
3713 // Register a debug event listener which just counts. 3735 // Register a debug event listener which just counts.
3714 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 3736 v8::Debug::SetDebugEventListener(env->GetIsolate(),
3737 DebugEventBreakPointHitCount);
3715 3738
3716 break_point_hit_count = 0; 3739 break_point_hit_count = 0;
3717 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3740 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3718 3741
3719 // Without stepping only active break points are hit. 3742 // Without stepping only active break points are hit.
3720 CHECK_EQ(1, break_point_hit_count); 3743 CHECK_EQ(1, break_point_hit_count);
3721 3744
3722 v8::Debug::SetDebugEventListener(NULL); 3745 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3723 CheckDebuggerUnloaded(); 3746 CheckDebuggerUnloaded(env->GetIsolate());
3724 } 3747 }
3725 3748
3726 3749
3727 // Test that step in works with function.apply. 3750 // Test that step in works with function.apply.
3728 TEST(DebugStepFunctionApply) { 3751 TEST(DebugStepFunctionApply) {
3729 DebugLocalContext env; 3752 DebugLocalContext env;
3730 v8::HandleScope scope(env->GetIsolate()); 3753 v8::HandleScope scope(env->GetIsolate());
3731 3754
3732 // Create a function for testing stepping. 3755 // Create a function for testing stepping.
3733 v8::Local<v8::Function> foo = CompileFunction( 3756 v8::Local<v8::Function> foo = CompileFunction(
3734 &env, 3757 &env,
3735 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" 3758 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3736 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", 3759 "function foo(){ debugger; bar.apply(this, [1,2,3]); }",
3737 "foo"); 3760 "foo");
3738 3761
3739 // Register a debug event listener which steps and counts. 3762 // Register a debug event listener which steps and counts.
3740 v8::Debug::SetDebugEventListener(DebugEventStep); 3763 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStep);
3741 3764
3742 v8::Local<v8::Context> context = env.context(); 3765 v8::Local<v8::Context> context = env.context();
3743 step_action = StepIn; 3766 step_action = StepIn;
3744 break_point_hit_count = 0; 3767 break_point_hit_count = 0;
3745 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3768 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3746 3769
3747 // With stepping all break locations are hit. 3770 // With stepping all break locations are hit.
3748 CHECK_EQ(7, break_point_hit_count); 3771 CHECK_EQ(7, break_point_hit_count);
3749 3772
3750 v8::Debug::SetDebugEventListener(NULL); 3773 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3751 CheckDebuggerUnloaded(); 3774 CheckDebuggerUnloaded(env->GetIsolate());
3752 3775
3753 // Register a debug event listener which just counts. 3776 // Register a debug event listener which just counts.
3754 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 3777 v8::Debug::SetDebugEventListener(env->GetIsolate(),
3778 DebugEventBreakPointHitCount);
3755 3779
3756 break_point_hit_count = 0; 3780 break_point_hit_count = 0;
3757 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3781 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3758 3782
3759 // Without stepping only the debugger statement is hit. 3783 // Without stepping only the debugger statement is hit.
3760 CHECK_EQ(1, break_point_hit_count); 3784 CHECK_EQ(1, break_point_hit_count);
3761 3785
3762 v8::Debug::SetDebugEventListener(NULL); 3786 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3763 CheckDebuggerUnloaded(); 3787 CheckDebuggerUnloaded(env->GetIsolate());
3764 } 3788 }
3765 3789
3766 3790
3767 // Test that step in works with function.call. 3791 // Test that step in works with function.call.
3768 TEST(DebugStepFunctionCall) { 3792 TEST(DebugStepFunctionCall) {
3769 DebugLocalContext env; 3793 DebugLocalContext env;
3770 v8::Isolate* isolate = env->GetIsolate(); 3794 v8::Isolate* isolate = env->GetIsolate();
3771 v8::HandleScope scope(isolate); 3795 v8::HandleScope scope(isolate);
3772 3796
3773 v8::Local<v8::Context> context = env.context(); 3797 v8::Local<v8::Context> context = env.context();
3774 // Create a function for testing stepping. 3798 // Create a function for testing stepping.
3775 v8::Local<v8::Function> foo = CompileFunction( 3799 v8::Local<v8::Function> foo = CompileFunction(
3776 &env, 3800 &env,
3777 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" 3801 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3778 "function foo(a){ debugger;" 3802 "function foo(a){ debugger;"
3779 " if (a) {" 3803 " if (a) {"
3780 " bar.call(this, 1, 2, 3);" 3804 " bar.call(this, 1, 2, 3);"
3781 " } else {" 3805 " } else {"
3782 " bar.call(this, 0);" 3806 " bar.call(this, 0);"
3783 " }" 3807 " }"
3784 "}", 3808 "}",
3785 "foo"); 3809 "foo");
3786 3810
3787 // Register a debug event listener which steps and counts. 3811 // Register a debug event listener which steps and counts.
3788 v8::Debug::SetDebugEventListener(DebugEventStep); 3812 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3789 step_action = StepIn; 3813 step_action = StepIn;
3790 3814
3791 // Check stepping where the if condition in bar is false. 3815 // Check stepping where the if condition in bar is false.
3792 break_point_hit_count = 0; 3816 break_point_hit_count = 0;
3793 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3817 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3794 CHECK_EQ(6, break_point_hit_count); 3818 CHECK_EQ(6, break_point_hit_count);
3795 3819
3796 // Check stepping where the if condition in bar is true. 3820 // Check stepping where the if condition in bar is true.
3797 break_point_hit_count = 0; 3821 break_point_hit_count = 0;
3798 const int argc = 1; 3822 const int argc = 1;
3799 v8::Local<v8::Value> argv[argc] = {v8::True(isolate)}; 3823 v8::Local<v8::Value> argv[argc] = {v8::True(isolate)};
3800 foo->Call(context, env->Global(), argc, argv).ToLocalChecked(); 3824 foo->Call(context, env->Global(), argc, argv).ToLocalChecked();
3801 CHECK_EQ(8, break_point_hit_count); 3825 CHECK_EQ(8, break_point_hit_count);
3802 3826
3803 v8::Debug::SetDebugEventListener(NULL); 3827 v8::Debug::SetDebugEventListener(isolate, nullptr);
3804 CheckDebuggerUnloaded(); 3828 CheckDebuggerUnloaded(isolate);
3805 3829
3806 // Register a debug event listener which just counts. 3830 // Register a debug event listener which just counts.
3807 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 3831 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
3808 3832
3809 break_point_hit_count = 0; 3833 break_point_hit_count = 0;
3810 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3834 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3811 3835
3812 // Without stepping only the debugger statement is hit. 3836 // Without stepping only the debugger statement is hit.
3813 CHECK_EQ(1, break_point_hit_count); 3837 CHECK_EQ(1, break_point_hit_count);
3814 3838
3815 v8::Debug::SetDebugEventListener(NULL); 3839 v8::Debug::SetDebugEventListener(isolate, nullptr);
3816 CheckDebuggerUnloaded(); 3840 CheckDebuggerUnloaded(isolate);
3817 } 3841 }
3818 3842
3819 3843
3820 // Test that step in works with Function.call.apply. 3844 // Test that step in works with Function.call.apply.
3821 TEST(DebugStepFunctionCallApply) { 3845 TEST(DebugStepFunctionCallApply) {
3822 DebugLocalContext env; 3846 DebugLocalContext env;
3823 v8::Isolate* isolate = env->GetIsolate(); 3847 v8::Isolate* isolate = env->GetIsolate();
3824 v8::HandleScope scope(isolate); 3848 v8::HandleScope scope(isolate);
3825 3849
3826 v8::Local<v8::Context> context = env.context(); 3850 v8::Local<v8::Context> context = env.context();
3827 // Create a function for testing stepping. 3851 // Create a function for testing stepping.
3828 v8::Local<v8::Function> foo = 3852 v8::Local<v8::Function> foo =
3829 CompileFunction(&env, 3853 CompileFunction(&env,
3830 "function bar() { }" 3854 "function bar() { }"
3831 "function foo(){ debugger;" 3855 "function foo(){ debugger;"
3832 " Function.call.apply(bar);" 3856 " Function.call.apply(bar);"
3833 " Function.call.apply(Function.call, " 3857 " Function.call.apply(Function.call, "
3834 "[Function.call, bar]);" 3858 "[Function.call, bar]);"
3835 "}", 3859 "}",
3836 "foo"); 3860 "foo");
3837 3861
3838 // Register a debug event listener which steps and counts. 3862 // Register a debug event listener which steps and counts.
3839 v8::Debug::SetDebugEventListener(DebugEventStep); 3863 v8::Debug::SetDebugEventListener(isolate, DebugEventStep);
3840 step_action = StepIn; 3864 step_action = StepIn;
3841 3865
3842 break_point_hit_count = 0; 3866 break_point_hit_count = 0;
3843 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3867 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3844 CHECK_EQ(6, break_point_hit_count); 3868 CHECK_EQ(6, break_point_hit_count);
3845 3869
3846 v8::Debug::SetDebugEventListener(NULL); 3870 v8::Debug::SetDebugEventListener(isolate, nullptr);
3847 CheckDebuggerUnloaded(); 3871 CheckDebuggerUnloaded(isolate);
3848 3872
3849 // Register a debug event listener which just counts. 3873 // Register a debug event listener which just counts.
3850 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 3874 v8::Debug::SetDebugEventListener(isolate, DebugEventBreakPointHitCount);
3851 3875
3852 break_point_hit_count = 0; 3876 break_point_hit_count = 0;
3853 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3877 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3854 3878
3855 // Without stepping only the debugger statement is hit. 3879 // Without stepping only the debugger statement is hit.
3856 CHECK_EQ(1, break_point_hit_count); 3880 CHECK_EQ(1, break_point_hit_count);
3857 3881
3858 v8::Debug::SetDebugEventListener(NULL); 3882 v8::Debug::SetDebugEventListener(isolate, nullptr);
3859 CheckDebuggerUnloaded(); 3883 CheckDebuggerUnloaded(isolate);
3860 } 3884 }
3861 3885
3862 3886
3863 // Tests that breakpoint will be hit if it's set in script. 3887 // Tests that breakpoint will be hit if it's set in script.
3864 TEST(PauseInScript) { 3888 TEST(PauseInScript) {
3865 DebugLocalContext env; 3889 DebugLocalContext env;
3866 v8::HandleScope scope(env->GetIsolate()); 3890 v8::HandleScope scope(env->GetIsolate());
3867 env.ExposeDebug(); 3891 env.ExposeDebug();
3868 3892
3869 // Register a debug event listener which counts. 3893 // Register a debug event listener which counts.
3870 v8::Debug::SetDebugEventListener(DebugEventCounter); 3894 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
3871 3895
3872 v8::Local<v8::Context> context = env.context(); 3896 v8::Local<v8::Context> context = env.context();
3873 // Create a script that returns a function. 3897 // Create a script that returns a function.
3874 const char* src = "(function (evt) {})"; 3898 const char* src = "(function (evt) {})";
3875 const char* script_name = "StepInHandlerTest"; 3899 const char* script_name = "StepInHandlerTest";
3876 3900
3877 // Set breakpoint in the script. 3901 // Set breakpoint in the script.
3878 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1); 3902 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1);
3879 break_point_hit_count = 0; 3903 break_point_hit_count = 0;
3880 3904
3881 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), script_name), 3905 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), script_name),
3882 v8::Integer::New(env->GetIsolate(), 0)); 3906 v8::Integer::New(env->GetIsolate(), 0));
3883 v8::Local<v8::Script> script = 3907 v8::Local<v8::Script> script =
3884 v8::Script::Compile(context, v8_str(env->GetIsolate(), src), &origin) 3908 v8::Script::Compile(context, v8_str(env->GetIsolate(), src), &origin)
3885 .ToLocalChecked(); 3909 .ToLocalChecked();
3886 v8::Local<v8::Value> r = script->Run(context).ToLocalChecked(); 3910 v8::Local<v8::Value> r = script->Run(context).ToLocalChecked();
3887 3911
3888 CHECK(r->IsFunction()); 3912 CHECK(r->IsFunction());
3889 CHECK_EQ(1, break_point_hit_count); 3913 CHECK_EQ(1, break_point_hit_count);
3890 3914
3891 // Get rid of the debug event listener. 3915 // Get rid of the debug event listener.
3892 v8::Debug::SetDebugEventListener(NULL); 3916 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3893 CheckDebuggerUnloaded(); 3917 CheckDebuggerUnloaded(env->GetIsolate());
3894 } 3918 }
3895 3919
3896 3920
3897 static void DebugEventCounterCheck(int caught, int uncaught, int message) { 3921 static void DebugEventCounterCheck(int caught, int uncaught, int message) {
3898 CHECK_EQ(caught, exception_hit_count); 3922 CHECK_EQ(caught, exception_hit_count);
3899 CHECK_EQ(uncaught, uncaught_exception_hit_count); 3923 CHECK_EQ(uncaught, uncaught_exception_hit_count);
3900 CHECK_EQ(message, message_callback_count); 3924 CHECK_EQ(message, message_callback_count);
3901 } 3925 }
3902 3926
3903 3927
(...skipping 21 matching lines...) Expand all
3925 &env, "function notCaughtFinally(){try{throws();}finally{}}", 3949 &env, "function notCaughtFinally(){try{throws();}finally{}}",
3926 "notCaughtFinally"); 3950 "notCaughtFinally");
3927 // In this edge case, even though this finally does not propagate the 3951 // In this edge case, even though this finally does not propagate the
3928 // exception, the debugger considers this uncaught, since we want to break 3952 // exception, the debugger considers this uncaught, since we want to break
3929 // at the first throw for the general case where finally implicitly rethrows. 3953 // at the first throw for the general case where finally implicitly rethrows.
3930 v8::Local<v8::Function> edgeCaseFinally = CompileFunction( 3954 v8::Local<v8::Function> edgeCaseFinally = CompileFunction(
3931 &env, "function caughtFinally(){L:try{throws();}finally{break L;}}", 3955 &env, "function caughtFinally(){L:try{throws();}finally{break L;}}",
3932 "caughtFinally"); 3956 "caughtFinally");
3933 3957
3934 env->GetIsolate()->AddMessageListener(MessageCallbackCount); 3958 env->GetIsolate()->AddMessageListener(MessageCallbackCount);
3935 v8::Debug::SetDebugEventListener(DebugEventCounter); 3959 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
3936 3960
3937 // Initial state should be no break on exceptions. 3961 // Initial state should be no break on exceptions.
3938 DebugEventCounterClear(); 3962 DebugEventCounterClear();
3939 MessageCallbackCountClear(); 3963 MessageCallbackCountClear();
3940 caught->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 3964 caught->Call(context, env->Global(), 0, NULL).ToLocalChecked();
3941 DebugEventCounterCheck(0, 0, 0); 3965 DebugEventCounterCheck(0, 0, 0);
3942 CHECK(notCaught->Call(context, env->Global(), 0, NULL).IsEmpty()); 3966 CHECK(notCaught->Call(context, env->Global(), 0, NULL).IsEmpty());
3943 DebugEventCounterCheck(0, 0, 1); 3967 DebugEventCounterCheck(0, 0, 1);
3944 CHECK(notCaughtFinally->Call(context, env->Global(), 0, NULL).IsEmpty()); 3968 CHECK(notCaughtFinally->Call(context, env->Global(), 0, NULL).IsEmpty());
3945 DebugEventCounterCheck(0, 0, 2); 3969 DebugEventCounterCheck(0, 0, 2);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
4043 ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, false); 4067 ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, false);
4044 caught->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 4068 caught->Call(context, env->Global(), 0, NULL).ToLocalChecked();
4045 DebugEventCounterCheck(1, 0, 0); 4069 DebugEventCounterCheck(1, 0, 0);
4046 CHECK(notCaught->Call(context, env->Global(), 0, NULL).IsEmpty()); 4070 CHECK(notCaught->Call(context, env->Global(), 0, NULL).IsEmpty());
4047 DebugEventCounterCheck(2, 1, 1); 4071 DebugEventCounterCheck(2, 1, 1);
4048 CHECK(notCaughtFinally->Call(context, env->Global(), 0, NULL).IsEmpty()); 4072 CHECK(notCaughtFinally->Call(context, env->Global(), 0, NULL).IsEmpty());
4049 DebugEventCounterCheck(3, 2, 2); 4073 DebugEventCounterCheck(3, 2, 2);
4050 edgeCaseFinally->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 4074 edgeCaseFinally->Call(context, env->Global(), 0, NULL).ToLocalChecked();
4051 DebugEventCounterCheck(4, 3, 2); 4075 DebugEventCounterCheck(4, 3, 2);
4052 4076
4053 v8::Debug::SetDebugEventListener(NULL); 4077 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
4054 CheckDebuggerUnloaded(); 4078 CheckDebuggerUnloaded(env->GetIsolate());
4055 env->GetIsolate()->RemoveMessageListeners(MessageCallbackCount); 4079 env->GetIsolate()->RemoveMessageListeners(MessageCallbackCount);
4056 } 4080 }
4057 4081
4058 4082
4059 static void try_finally_original_message(v8::Local<v8::Message> message, 4083 static void try_finally_original_message(v8::Local<v8::Message> message,
4060 v8::Local<v8::Value> data) { 4084 v8::Local<v8::Value> data) {
4061 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); 4085 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
4062 CHECK_EQ(2, message->GetLineNumber(context).FromJust()); 4086 CHECK_EQ(2, message->GetLineNumber(context).FromJust());
4063 CHECK_EQ(2, message->GetStartColumn(context).FromJust()); 4087 CHECK_EQ(2, message->GetStartColumn(context).FromJust());
4064 message_callback_count++; 4088 message_callback_count++;
4065 } 4089 }
4066 4090
4067 4091
4068 TEST(TryFinallyOriginalMessage) { 4092 TEST(TryFinallyOriginalMessage) {
4069 // Test that the debugger plays nicely with the pending message. 4093 // Test that the debugger plays nicely with the pending message.
4070 message_callback_count = 0; 4094 message_callback_count = 0;
4071 DebugEventCounterClear(); 4095 DebugEventCounterClear();
4072 DebugLocalContext env; 4096 DebugLocalContext env;
4073 v8::Isolate* isolate = CcTest::isolate(); 4097 v8::Isolate* isolate = CcTest::isolate();
4074 isolate->AddMessageListener(try_finally_original_message); 4098 isolate->AddMessageListener(try_finally_original_message);
4075 v8::Debug::SetDebugEventListener(DebugEventCounter); 4099 v8::Debug::SetDebugEventListener(isolate, DebugEventCounter);
4076 ChangeBreakOnException(true, true); 4100 ChangeBreakOnException(true, true);
4077 v8::HandleScope scope(isolate); 4101 v8::HandleScope scope(isolate);
4078 CompileRun( 4102 CompileRun(
4079 "try {\n" 4103 "try {\n"
4080 " throw 1;\n" 4104 " throw 1;\n"
4081 "} finally {\n" 4105 "} finally {\n"
4082 "}\n"); 4106 "}\n");
4083 DebugEventCounterCheck(1, 1, 1); 4107 DebugEventCounterCheck(1, 1, 1);
4084 v8::Debug::SetDebugEventListener(NULL); 4108 v8::Debug::SetDebugEventListener(isolate, nullptr);
4085 isolate->RemoveMessageListeners(try_finally_original_message); 4109 isolate->RemoveMessageListeners(try_finally_original_message);
4086 } 4110 }
4087 4111
4088 4112
4089 TEST(EvalJSInDebugEventListenerOnNativeReThrownException) { 4113 TEST(EvalJSInDebugEventListenerOnNativeReThrownException) {
4090 DebugLocalContext env; 4114 DebugLocalContext env;
4091 v8::HandleScope scope(env->GetIsolate()); 4115 v8::HandleScope scope(env->GetIsolate());
4092 env.ExposeDebug(); 4116 env.ExposeDebug();
4093 4117
4094 // Create functions for testing break on exception. 4118 // Create functions for testing break on exception.
4095 v8::Local<v8::Function> noThrowJS = CompileFunction( 4119 v8::Local<v8::Function> noThrowJS = CompileFunction(
4096 &env, "function noThrowJS(){var a=[1]; a.push(2); return a.length;}", 4120 &env, "function noThrowJS(){var a=[1]; a.push(2); return a.length;}",
4097 "noThrowJS"); 4121 "noThrowJS");
4098 4122
4099 debug_event_listener_callback = noThrowJS; 4123 debug_event_listener_callback = noThrowJS;
4100 debug_event_listener_callback_result = 2; 4124 debug_event_listener_callback_result = 2;
4101 4125
4102 env->GetIsolate()->AddMessageListener(MessageCallbackCount); 4126 env->GetIsolate()->AddMessageListener(MessageCallbackCount);
4103 v8::Debug::SetDebugEventListener(DebugEventCounter); 4127 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
4104 // Break on uncaught exception 4128 // Break on uncaught exception
4105 ChangeBreakOnException(false, true); 4129 ChangeBreakOnException(false, true);
4106 DebugEventCounterClear(); 4130 DebugEventCounterClear();
4107 MessageCallbackCountClear(); 4131 MessageCallbackCountClear();
4108 4132
4109 // ReThrow native error 4133 // ReThrow native error
4110 { 4134 {
4111 v8::TryCatch tryCatch(env->GetIsolate()); 4135 v8::TryCatch tryCatch(env->GetIsolate());
4112 env->GetIsolate()->ThrowException( 4136 env->GetIsolate()->ThrowException(
4113 v8::Exception::TypeError(v8_str(env->GetIsolate(), "Type error"))); 4137 v8::Exception::TypeError(v8_str(env->GetIsolate(), "Type error")));
(...skipping 17 matching lines...) Expand all
4131 v8::HandleScope scope(env->GetIsolate()); 4155 v8::HandleScope scope(env->GetIsolate());
4132 4156
4133 v8::Local<v8::Context> context = env.context(); 4157 v8::Local<v8::Context> context = env.context();
4134 // For this test, we want to break on uncaught exceptions: 4158 // For this test, we want to break on uncaught exceptions:
4135 ChangeBreakOnException(false, true); 4159 ChangeBreakOnException(false, true);
4136 4160
4137 // Create a function for checking the function when hitting a break point. 4161 // Create a function for checking the function when hitting a break point.
4138 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); 4162 frame_count = CompileFunction(&env, frame_count_source, "frame_count");
4139 4163
4140 env->GetIsolate()->AddMessageListener(MessageCallbackCount); 4164 env->GetIsolate()->AddMessageListener(MessageCallbackCount);
4141 v8::Debug::SetDebugEventListener(DebugEventCounter); 4165 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
4142 4166
4143 DebugEventCounterClear(); 4167 DebugEventCounterClear();
4144 MessageCallbackCountClear(); 4168 MessageCallbackCountClear();
4145 4169
4146 // Check initial state. 4170 // Check initial state.
4147 CHECK_EQ(0, exception_hit_count); 4171 CHECK_EQ(0, exception_hit_count);
4148 CHECK_EQ(0, uncaught_exception_hit_count); 4172 CHECK_EQ(0, uncaught_exception_hit_count);
4149 CHECK_EQ(0, message_callback_count); 4173 CHECK_EQ(0, message_callback_count);
4150 CHECK_EQ(-1, last_js_stack_height); 4174 CHECK_EQ(-1, last_js_stack_height);
4151 4175
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4193 4217
4194 // For this test, we want to break on uncaught exceptions: 4218 // For this test, we want to break on uncaught exceptions:
4195 ChangeBreakOnException(false, true); 4219 ChangeBreakOnException(false, true);
4196 4220
4197 // Create a function for checking the function when hitting a break point. 4221 // Create a function for checking the function when hitting a break point.
4198 frame_function_name = CompileFunction(&env, 4222 frame_function_name = CompileFunction(&env,
4199 frame_function_name_source, 4223 frame_function_name_source,
4200 "frame_function_name"); 4224 "frame_function_name");
4201 4225
4202 // Register a debug event listener which steps and counts. 4226 // Register a debug event listener which steps and counts.
4203 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 4227 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStepSequence);
4204 4228
4205 v8::Local<v8::Context> context = env.context(); 4229 v8::Local<v8::Context> context = env.context();
4206 // Create functions for testing stepping. 4230 // Create functions for testing stepping.
4207 const char* src = "function a() { n(); }; " 4231 const char* src = "function a() { n(); }; "
4208 "function b() { c(); }; " 4232 "function b() { c(); }; "
4209 "function c() { n(); }; " 4233 "function c() { n(); }; "
4210 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; " 4234 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; "
4211 "function e() { n(); }; " 4235 "function e() { n(); }; "
4212 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; " 4236 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; "
4213 "function g() { h(); }; " 4237 "function g() { h(); }; "
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4271 // Step through invocation of f + g + h now with break on caught exceptions. 4295 // Step through invocation of f + g + h now with break on caught exceptions.
4272 ChangeBreakOnException(true, true); 4296 ChangeBreakOnException(true, true);
4273 step_action = StepIn; 4297 step_action = StepIn;
4274 break_point_hit_count = 0; 4298 break_point_hit_count = 0;
4275 expected_step_sequence = "ffghhhff"; 4299 expected_step_sequence = "ffghhhff";
4276 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 4300 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
4277 CHECK_EQ(StrLength(expected_step_sequence), 4301 CHECK_EQ(StrLength(expected_step_sequence),
4278 break_point_hit_count); 4302 break_point_hit_count);
4279 4303
4280 // Get rid of the debug event listener. 4304 // Get rid of the debug event listener.
4281 v8::Debug::SetDebugEventListener(NULL); 4305 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
4282 CheckDebuggerUnloaded(); 4306 CheckDebuggerUnloaded(env->GetIsolate());
4283 } 4307 }
4284 4308
4285 4309
4286 TEST(DebugBreak) { 4310 TEST(DebugBreak) {
4287 i::FLAG_stress_compaction = false; 4311 i::FLAG_stress_compaction = false;
4288 #ifdef VERIFY_HEAP 4312 #ifdef VERIFY_HEAP
4289 i::FLAG_verify_heap = true; 4313 i::FLAG_verify_heap = true;
4290 #endif 4314 #endif
4291 DebugLocalContext env; 4315 DebugLocalContext env;
4292 v8::Isolate* isolate = env->GetIsolate(); 4316 v8::Isolate* isolate = env->GetIsolate();
4293 v8::HandleScope scope(isolate); 4317 v8::HandleScope scope(isolate);
4294 4318
4295 // Register a debug event listener which sets the break flag and counts. 4319 // Register a debug event listener which sets the break flag and counts.
4296 v8::Debug::SetDebugEventListener(DebugEventBreak); 4320 v8::Debug::SetDebugEventListener(isolate, DebugEventBreak);
4297 4321
4298 v8::Local<v8::Context> context = env.context(); 4322 v8::Local<v8::Context> context = env.context();
4299 // Create a function for testing stepping. 4323 // Create a function for testing stepping.
4300 const char* src = "function f0() {}" 4324 const char* src = "function f0() {}"
4301 "function f1(x1) {}" 4325 "function f1(x1) {}"
4302 "function f2(x1,x2) {}" 4326 "function f2(x1,x2) {}"
4303 "function f3(x1,x2,x3) {}"; 4327 "function f3(x1,x2,x3) {}";
4304 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); 4328 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0");
4305 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1"); 4329 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1");
4306 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2"); 4330 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2");
(...skipping 20 matching lines...) Expand all
4327 f0->Call(context, env->Global(), i, argv).ToLocalChecked(); 4351 f0->Call(context, env->Global(), i, argv).ToLocalChecked();
4328 f1->Call(context, env->Global(), i, argv).ToLocalChecked(); 4352 f1->Call(context, env->Global(), i, argv).ToLocalChecked();
4329 f2->Call(context, env->Global(), i, argv).ToLocalChecked(); 4353 f2->Call(context, env->Global(), i, argv).ToLocalChecked();
4330 f3->Call(context, env->Global(), i, argv).ToLocalChecked(); 4354 f3->Call(context, env->Global(), i, argv).ToLocalChecked();
4331 } 4355 }
4332 4356
4333 // One break for each function called. 4357 // One break for each function called.
4334 CHECK(4 * arraysize(argv) == break_point_hit_count); 4358 CHECK(4 * arraysize(argv) == break_point_hit_count);
4335 4359
4336 // Get rid of the debug event listener. 4360 // Get rid of the debug event listener.
4337 v8::Debug::SetDebugEventListener(NULL); 4361 v8::Debug::SetDebugEventListener(isolate, nullptr);
4338 CheckDebuggerUnloaded(); 4362 CheckDebuggerUnloaded(isolate);
4339 } 4363 }
4340 4364
4341 4365
4342 // Test to ensure that JavaScript code keeps running while the debug break 4366 // Test to ensure that JavaScript code keeps running while the debug break
4343 // through the stack limit flag is set but breaks are disabled. 4367 // through the stack limit flag is set but breaks are disabled.
4344 TEST(DisableBreak) { 4368 TEST(DisableBreak) {
4345 DebugLocalContext env; 4369 DebugLocalContext env;
4346 v8::HandleScope scope(env->GetIsolate()); 4370 v8::HandleScope scope(env->GetIsolate());
4347 4371
4348 // Register a debug event listener which sets the break flag and counts. 4372 // Register a debug event listener which sets the break flag and counts.
4349 v8::Debug::SetDebugEventListener(DebugEventCounter); 4373 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
4350 4374
4351 v8::Local<v8::Context> context = env.context(); 4375 v8::Local<v8::Context> context = env.context();
4352 // Create a function for testing stepping. 4376 // Create a function for testing stepping.
4353 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; 4377 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
4354 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 4378 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4355 4379
4356 // Set, test and cancel debug break. 4380 // Set, test and cancel debug break.
4357 v8::Debug::DebugBreak(env->GetIsolate()); 4381 v8::Debug::DebugBreak(env->GetIsolate());
4358 CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate())); 4382 CHECK(v8::Debug::CheckDebugBreak(env->GetIsolate()));
4359 v8::Debug::CancelDebugBreak(env->GetIsolate()); 4383 v8::Debug::CancelDebugBreak(env->GetIsolate());
(...skipping 12 matching lines...) Expand all
4372 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); 4396 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
4373 v8::internal::DisableBreak disable_break(isolate->debug(), true); 4397 v8::internal::DisableBreak disable_break(isolate->debug(), true);
4374 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 4398 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
4375 CHECK_EQ(1, break_point_hit_count); 4399 CHECK_EQ(1, break_point_hit_count);
4376 } 4400 }
4377 4401
4378 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 4402 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
4379 CHECK_EQ(2, break_point_hit_count); 4403 CHECK_EQ(2, break_point_hit_count);
4380 4404
4381 // Get rid of the debug event listener. 4405 // Get rid of the debug event listener.
4382 v8::Debug::SetDebugEventListener(NULL); 4406 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
4383 CheckDebuggerUnloaded(); 4407 CheckDebuggerUnloaded(env->GetIsolate());
4384 } 4408 }
4385 4409
4386 static const char* kSimpleExtensionSource = 4410 static const char* kSimpleExtensionSource =
4387 "(function Foo() {" 4411 "(function Foo() {"
4388 " return 4;" 4412 " return 4;"
4389 "})() "; 4413 "})() ";
4390 4414
4391 // http://crbug.com/28933 4415 // http://crbug.com/28933
4392 // Test that debug break is disabled when bootstrapper is active. 4416 // Test that debug break is disabled when bootstrapper is active.
4393 TEST(NoBreakWhenBootstrapping) { 4417 TEST(NoBreakWhenBootstrapping) {
4394 v8::Isolate* isolate = CcTest::isolate(); 4418 v8::Isolate* isolate = CcTest::isolate();
4395 v8::HandleScope scope(isolate); 4419 v8::HandleScope scope(isolate);
4396 4420
4397 // Register a debug event listener which sets the break flag and counts. 4421 // Register a debug event listener which sets the break flag and counts.
4398 v8::Debug::SetDebugEventListener(DebugEventCounter); 4422 v8::Debug::SetDebugEventListener(isolate, DebugEventCounter);
4399 4423
4400 // Set the debug break flag. 4424 // Set the debug break flag.
4401 v8::Debug::DebugBreak(isolate); 4425 v8::Debug::DebugBreak(isolate);
4402 break_point_hit_count = 0; 4426 break_point_hit_count = 0;
4403 { 4427 {
4404 // Create a context with an extension to make sure that some JavaScript 4428 // Create a context with an extension to make sure that some JavaScript
4405 // code is executed during bootstrapping. 4429 // code is executed during bootstrapping.
4406 v8::RegisterExtension(new v8::Extension("simpletest", 4430 v8::RegisterExtension(new v8::Extension("simpletest",
4407 kSimpleExtensionSource)); 4431 kSimpleExtensionSource));
4408 const char* extension_names[] = { "simpletest" }; 4432 const char* extension_names[] = { "simpletest" };
4409 v8::ExtensionConfiguration extensions(1, extension_names); 4433 v8::ExtensionConfiguration extensions(1, extension_names);
4410 v8::HandleScope handle_scope(isolate); 4434 v8::HandleScope handle_scope(isolate);
4411 v8::Context::New(isolate, &extensions); 4435 v8::Context::New(isolate, &extensions);
4412 } 4436 }
4413 // Check that no DebugBreak events occured during the context creation. 4437 // Check that no DebugBreak events occured during the context creation.
4414 CHECK_EQ(0, break_point_hit_count); 4438 CHECK_EQ(0, break_point_hit_count);
4415 4439
4416 // Get rid of the debug event listener. 4440 // Get rid of the debug event listener.
4417 v8::Debug::SetDebugEventListener(NULL); 4441 v8::Debug::SetDebugEventListener(isolate, nullptr);
4418 CheckDebuggerUnloaded(); 4442 CheckDebuggerUnloaded(isolate);
4419 } 4443 }
4420 4444
4421 4445
4422 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { 4446 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
4423 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); 4447 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate(), 3);
4424 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); 4448 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
4425 CHECK(result->Set(context, v8::Integer::New(info.GetIsolate(), 0), 4449 CHECK(result->Set(context, v8::Integer::New(info.GetIsolate(), 0),
4426 v8_str(info.GetIsolate(), "a")) 4450 v8_str(info.GetIsolate(), "a"))
4427 .FromJust()); 4451 .FromJust());
4428 CHECK(result->Set(context, v8::Integer::New(info.GetIsolate(), 1), 4452 CHECK(result->Set(context, v8::Integer::New(info.GetIsolate(), 1),
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
5220 } 5244 }
5221 5245
5222 5246
5223 // This thread runs the v8 engine. 5247 // This thread runs the v8 engine.
5224 TEST(MessageQueues) { 5248 TEST(MessageQueues) {
5225 MessageQueueDebuggerThread message_queue_debugger_thread; 5249 MessageQueueDebuggerThread message_queue_debugger_thread;
5226 5250
5227 // Create a V8 environment 5251 // Create a V8 environment
5228 DebugLocalContext env; 5252 DebugLocalContext env;
5229 v8::HandleScope scope(env->GetIsolate()); 5253 v8::HandleScope scope(env->GetIsolate());
5230 v8::Debug::SetMessageHandler(MessageHandler); 5254 v8::Debug::SetMessageHandler(env->GetIsolate(), MessageHandler);
5231 message_queue_debugger_thread.Start(); 5255 message_queue_debugger_thread.Start();
5232 5256
5233 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 5257 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
5234 const char* source_2 = "e = 17;"; 5258 const char* source_2 = "e = 17;";
5235 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; 5259 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;";
5236 5260
5237 // See MessageQueueDebuggerThread::Run for interleaved sequence of 5261 // See MessageQueueDebuggerThread::Run for interleaved sequence of
5238 // API calls and events in the two threads. 5262 // API calls and events in the two threads.
5239 CompileRun(source_1); 5263 CompileRun(source_1);
5240 message_queue_barriers.barrier_1.Wait(); 5264 message_queue_barriers.barrier_1.Wait();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
5314 5338
5315 5339
5316 // Tests that all client data passed to the debugger are sent to the handler. 5340 // Tests that all client data passed to the debugger are sent to the handler.
5317 TEST(SendClientDataToHandler) { 5341 TEST(SendClientDataToHandler) {
5318 // Create a V8 environment 5342 // Create a V8 environment
5319 DebugLocalContext env; 5343 DebugLocalContext env;
5320 v8::Isolate* isolate = env->GetIsolate(); 5344 v8::Isolate* isolate = env->GetIsolate();
5321 v8::HandleScope scope(isolate); 5345 v8::HandleScope scope(isolate);
5322 TestClientData::ResetCounters(); 5346 TestClientData::ResetCounters();
5323 handled_client_data_instances_count = 0; 5347 handled_client_data_instances_count = 0;
5324 v8::Debug::SetMessageHandler(MessageHandlerCountingClientData); 5348 v8::Debug::SetMessageHandler(isolate, MessageHandlerCountingClientData);
5325 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 5349 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
5326 const int kBufferSize = 1000; 5350 const int kBufferSize = 1000;
5327 uint16_t buffer[kBufferSize]; 5351 uint16_t buffer[kBufferSize];
5328 const char* command_1 = 5352 const char* command_1 =
5329 "{\"seq\":117," 5353 "{\"seq\":117,"
5330 "\"type\":\"request\"," 5354 "\"type\":\"request\","
5331 "\"command\":\"evaluate\"," 5355 "\"command\":\"evaluate\","
5332 "\"arguments\":{\"expression\":\"1+2\"}}"; 5356 "\"arguments\":{\"expression\":\"1+2\"}}";
5333 const char* command_2 = 5357 const char* command_2 =
5334 "{\"seq\":118," 5358 "{\"seq\":118,"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
5430 "foo();\n"; 5454 "foo();\n";
5431 5455
5432 v8::Isolate::CreateParams create_params; 5456 v8::Isolate::CreateParams create_params;
5433 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 5457 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
5434 isolate_ = v8::Isolate::New(create_params); 5458 isolate_ = v8::Isolate::New(create_params);
5435 threaded_debugging_barriers.barrier_3.Wait(); 5459 threaded_debugging_barriers.barrier_3.Wait();
5436 { 5460 {
5437 v8::Isolate::Scope isolate_scope(isolate_); 5461 v8::Isolate::Scope isolate_scope(isolate_);
5438 DebugLocalContext env(isolate_); 5462 DebugLocalContext env(isolate_);
5439 v8::HandleScope scope(isolate_); 5463 v8::HandleScope scope(isolate_);
5440 v8::Debug::SetMessageHandler(&ThreadedMessageHandler); 5464 v8::Debug::SetMessageHandler(isolate_, &ThreadedMessageHandler);
5441 v8::Local<v8::ObjectTemplate> global_template = 5465 v8::Local<v8::ObjectTemplate> global_template =
5442 v8::ObjectTemplate::New(env->GetIsolate()); 5466 v8::ObjectTemplate::New(env->GetIsolate());
5443 global_template->Set( 5467 global_template->Set(
5444 v8_str(env->GetIsolate(), "ThreadedAtBarrier1"), 5468 v8_str(env->GetIsolate(), "ThreadedAtBarrier1"),
5445 v8::FunctionTemplate::New(isolate_, ThreadedAtBarrier1)); 5469 v8::FunctionTemplate::New(isolate_, ThreadedAtBarrier1));
5446 v8::Local<v8::Context> context = 5470 v8::Local<v8::Context> context =
5447 v8::Context::New(isolate_, NULL, global_template); 5471 v8::Context::New(isolate_, NULL, global_template);
5448 v8::Context::Scope context_scope(context); 5472 v8::Context::Scope context_scope(context);
5449 5473
5450 CompileRun(source); 5474 CompileRun(source);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
5563 "cat(19);\n"; 5587 "cat(19);\n";
5564 5588
5565 v8::Isolate::CreateParams create_params; 5589 v8::Isolate::CreateParams create_params;
5566 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 5590 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
5567 isolate_ = v8::Isolate::New(create_params); 5591 isolate_ = v8::Isolate::New(create_params);
5568 breakpoints_barriers->barrier_3.Wait(); 5592 breakpoints_barriers->barrier_3.Wait();
5569 { 5593 {
5570 v8::Isolate::Scope isolate_scope(isolate_); 5594 v8::Isolate::Scope isolate_scope(isolate_);
5571 DebugLocalContext env(isolate_); 5595 DebugLocalContext env(isolate_);
5572 v8::HandleScope scope(isolate_); 5596 v8::HandleScope scope(isolate_);
5573 v8::Debug::SetMessageHandler(&BreakpointsMessageHandler); 5597 v8::Debug::SetMessageHandler(isolate_, &BreakpointsMessageHandler);
5574 5598
5575 CompileRun(source_1); 5599 CompileRun(source_1);
5576 breakpoints_barriers->barrier_1.Wait(); 5600 breakpoints_barriers->barrier_1.Wait();
5577 breakpoints_barriers->barrier_2.Wait(); 5601 breakpoints_barriers->barrier_2.Wait();
5578 CompileRun(source_2); 5602 CompileRun(source_2);
5579 } 5603 }
5580 breakpoints_barriers->barrier_4.Wait(); 5604 breakpoints_barriers->barrier_4.Wait();
5581 isolate_->Dispose(); 5605 isolate_->Dispose();
5582 } 5606 }
5583 5607
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
5719 TestRecursiveBreakpointsGeneric(false); 5743 TestRecursiveBreakpointsGeneric(false);
5720 } 5744 }
5721 5745
5722 5746
5723 TEST(RecursiveBreakpointsGlobal) { 5747 TEST(RecursiveBreakpointsGlobal) {
5724 TestRecursiveBreakpointsGeneric(true); 5748 TestRecursiveBreakpointsGeneric(true);
5725 } 5749 }
5726 5750
5727 5751
5728 TEST(SetDebugEventListenerOnUninitializedVM) { 5752 TEST(SetDebugEventListenerOnUninitializedVM) {
5729 v8::Debug::SetDebugEventListener(DummyDebugEventListener); 5753 v8::Debug::SetDebugEventListener(CcTest::isolate(), DummyDebugEventListener);
5730 } 5754 }
5731 5755
5732 5756
5733 static void DummyMessageHandler(const v8::Debug::Message& message) { 5757 static void DummyMessageHandler(const v8::Debug::Message& message) {
5734 } 5758 }
5735 5759
5736 5760
5737 TEST(SetMessageHandlerOnUninitializedVM) { 5761 TEST(SetMessageHandlerOnUninitializedVM) {
5738 v8::Debug::SetMessageHandler(DummyMessageHandler); 5762 v8::Debug::SetMessageHandler(CcTest::isolate(), DummyMessageHandler);
5739 } 5763 }
5740 5764
5741 5765
5742 // Source for a JavaScript function which returns the data parameter of a 5766 // Source for a JavaScript function which returns the data parameter of a
5743 // function called in the context of the debugger. If no data parameter is 5767 // function called in the context of the debugger. If no data parameter is
5744 // passed it throws an exception. 5768 // passed it throws an exception.
5745 static const char* debugger_call_with_data_source = 5769 static const char* debugger_call_with_data_source =
5746 "function debugger_call_with_data(exec_state, data) {" 5770 "function debugger_call_with_data(exec_state, data) {"
5747 " if (data) return data;" 5771 " if (data) return data;"
5748 " throw 'No data!'" 5772 " throw 'No data!'"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
5959 } 5983 }
5960 } 5984 }
5961 5985
5962 5986
5963 // Test that clearing the debug event listener actually clears all break points 5987 // Test that clearing the debug event listener actually clears all break points
5964 // and related information. 5988 // and related information.
5965 TEST(DebuggerUnload) { 5989 TEST(DebuggerUnload) {
5966 DebugLocalContext env; 5990 DebugLocalContext env;
5967 5991
5968 // Check debugger is unloaded before it is used. 5992 // Check debugger is unloaded before it is used.
5969 CheckDebuggerUnloaded(); 5993 CheckDebuggerUnloaded(env->GetIsolate());
5970 5994
5971 // Set a debug event listener. 5995 // Set a debug event listener.
5972 break_point_hit_count = 0; 5996 break_point_hit_count = 0;
5973 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 5997 v8::Debug::SetDebugEventListener(env->GetIsolate(),
5998 DebugEventBreakPointHitCount);
5974 v8::Local<v8::Context> context = env.context(); 5999 v8::Local<v8::Context> context = env.context();
5975 { 6000 {
5976 v8::HandleScope scope(env->GetIsolate()); 6001 v8::HandleScope scope(env->GetIsolate());
5977 // Create a couple of functions for the test. 6002 // Create a couple of functions for the test.
5978 v8::Local<v8::Function> foo = 6003 v8::Local<v8::Function> foo =
5979 CompileFunction(&env, "function foo(){x=1}", "foo"); 6004 CompileFunction(&env, "function foo(){x=1}", "foo");
5980 v8::Local<v8::Function> bar = 6005 v8::Local<v8::Function> bar =
5981 CompileFunction(&env, "function bar(){y=2}", "bar"); 6006 CompileFunction(&env, "function bar(){y=2}", "bar");
5982 6007
5983 // Set some break points. 6008 // Set some break points.
5984 SetBreakPoint(foo, 0); 6009 SetBreakPoint(foo, 0);
5985 SetBreakPoint(foo, 4); 6010 SetBreakPoint(foo, 4);
5986 SetBreakPoint(bar, 0); 6011 SetBreakPoint(bar, 0);
5987 SetBreakPoint(bar, 4); 6012 SetBreakPoint(bar, 4);
5988 6013
5989 // Make sure that the break points are there. 6014 // Make sure that the break points are there.
5990 break_point_hit_count = 0; 6015 break_point_hit_count = 0;
5991 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6016 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
5992 CHECK_EQ(2, break_point_hit_count); 6017 CHECK_EQ(2, break_point_hit_count);
5993 bar->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6018 bar->Call(context, env->Global(), 0, NULL).ToLocalChecked();
5994 CHECK_EQ(4, break_point_hit_count); 6019 CHECK_EQ(4, break_point_hit_count);
5995 } 6020 }
5996 6021
5997 // Remove the debug event listener without clearing breakpoints. Do this 6022 // Remove the debug event listener without clearing breakpoints. Do this
5998 // outside a handle scope. 6023 // outside a handle scope.
5999 v8::Debug::SetDebugEventListener(NULL); 6024 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
6000 CheckDebuggerUnloaded(true); 6025 CheckDebuggerUnloaded(env->GetIsolate(), true);
6001 6026
6002 // Now set a debug message handler. 6027 // Now set a debug message handler.
6003 break_point_hit_count = 0; 6028 break_point_hit_count = 0;
6004 v8::Debug::SetMessageHandler(MessageHandlerBreakPointHitCount); 6029 v8::Debug::SetMessageHandler(env->GetIsolate(),
6030 MessageHandlerBreakPointHitCount);
6005 { 6031 {
6006 v8::HandleScope scope(env->GetIsolate()); 6032 v8::HandleScope scope(env->GetIsolate());
6007 6033
6008 // Get the test functions again. 6034 // Get the test functions again.
6009 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( 6035 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast(
6010 env->Global() 6036 env->Global()
6011 ->Get(context, v8_str(env->GetIsolate(), "foo")) 6037 ->Get(context, v8_str(env->GetIsolate(), "foo"))
6012 .ToLocalChecked())); 6038 .ToLocalChecked()));
6013 6039
6014 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6040 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
6015 CHECK_EQ(0, break_point_hit_count); 6041 CHECK_EQ(0, break_point_hit_count);
6016 6042
6017 // Set break points and run again. 6043 // Set break points and run again.
6018 SetBreakPoint(foo, 0); 6044 SetBreakPoint(foo, 0);
6019 SetBreakPoint(foo, 4); 6045 SetBreakPoint(foo, 4);
6020 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6046 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
6021 CHECK_EQ(2, break_point_hit_count); 6047 CHECK_EQ(2, break_point_hit_count);
6022 } 6048 }
6023 6049
6024 // Remove the debug message handler without clearing breakpoints. Do this 6050 // Remove the debug message handler without clearing breakpoints. Do this
6025 // outside a handle scope. 6051 // outside a handle scope.
6026 v8::Debug::SetMessageHandler(NULL); 6052 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6027 CheckDebuggerUnloaded(true); 6053 CheckDebuggerUnloaded(env->GetIsolate(), true);
6028 } 6054 }
6029 6055
6030 6056
6031 // Sends continue command to the debugger. 6057 // Sends continue command to the debugger.
6032 static void SendContinueCommand() { 6058 static void SendContinueCommand() {
6033 const int kBufferSize = 1000; 6059 const int kBufferSize = 1000;
6034 uint16_t buffer[kBufferSize]; 6060 uint16_t buffer[kBufferSize];
6035 const char* command_continue = 6061 const char* command_continue =
6036 "{\"seq\":0," 6062 "{\"seq\":0,"
6037 "\"type\":\"request\"," 6063 "\"type\":\"request\","
(...skipping 18 matching lines...) Expand all
6056 } 6082 }
6057 } 6083 }
6058 6084
6059 6085
6060 // Test clearing the debug message handler. 6086 // Test clearing the debug message handler.
6061 TEST(DebuggerClearMessageHandler) { 6087 TEST(DebuggerClearMessageHandler) {
6062 DebugLocalContext env; 6088 DebugLocalContext env;
6063 v8::HandleScope scope(env->GetIsolate()); 6089 v8::HandleScope scope(env->GetIsolate());
6064 6090
6065 // Check debugger is unloaded before it is used. 6091 // Check debugger is unloaded before it is used.
6066 CheckDebuggerUnloaded(); 6092 CheckDebuggerUnloaded(env->GetIsolate());
6067 6093
6068 // Set a debug message handler. 6094 // Set a debug message handler.
6069 v8::Debug::SetMessageHandler(MessageHandlerHitCount); 6095 v8::Debug::SetMessageHandler(env->GetIsolate(), MessageHandlerHitCount);
6070 6096
6071 // Run code to throw a unhandled exception. This should end up in the message 6097 // Run code to throw a unhandled exception. This should end up in the message
6072 // handler. 6098 // handler.
6073 CompileRun("throw 1"); 6099 CompileRun("throw 1");
6074 6100
6075 // The message handler should be called. 6101 // The message handler should be called.
6076 CHECK_GT(message_handler_hit_count, 0); 6102 CHECK_GT(message_handler_hit_count, 0);
6077 6103
6078 // Clear debug message handler. 6104 // Clear debug message handler.
6079 message_handler_hit_count = 0; 6105 message_handler_hit_count = 0;
6080 v8::Debug::SetMessageHandler(NULL); 6106 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6081 6107
6082 // Run code to throw a unhandled exception. This should end up in the message 6108 // Run code to throw a unhandled exception. This should end up in the message
6083 // handler. 6109 // handler.
6084 CompileRun("throw 1"); 6110 CompileRun("throw 1");
6085 6111
6086 // The message handler should not be called more. 6112 // The message handler should not be called more.
6087 CHECK_EQ(0, message_handler_hit_count); 6113 CHECK_EQ(0, message_handler_hit_count);
6088 6114
6089 CheckDebuggerUnloaded(true); 6115 CheckDebuggerUnloaded(env->GetIsolate(), true);
6090 } 6116 }
6091 6117
6092 6118
6093 // Debugger message handler which clears the message handler while active. 6119 // Debugger message handler which clears the message handler while active.
6094 static void MessageHandlerClearingMessageHandler( 6120 static void MessageHandlerClearingMessageHandler(
6095 const v8::Debug::Message& message) { 6121 const v8::Debug::Message& message) {
6096 message_handler_hit_count++; 6122 message_handler_hit_count++;
6097 6123
6098 // Clear debug message handler. 6124 // Clear debug message handler.
6099 v8::Debug::SetMessageHandler(NULL); 6125 v8::Debug::SetMessageHandler(message.GetIsolate(), nullptr);
6100 } 6126 }
6101 6127
6102 6128
6103 // Test clearing the debug message handler while processing a debug event. 6129 // Test clearing the debug message handler while processing a debug event.
6104 TEST(DebuggerClearMessageHandlerWhileActive) { 6130 TEST(DebuggerClearMessageHandlerWhileActive) {
6105 DebugLocalContext env; 6131 DebugLocalContext env;
6106 v8::HandleScope scope(env->GetIsolate()); 6132 v8::HandleScope scope(env->GetIsolate());
6107 6133
6108 // Check debugger is unloaded before it is used. 6134 // Check debugger is unloaded before it is used.
6109 CheckDebuggerUnloaded(); 6135 CheckDebuggerUnloaded(env->GetIsolate());
6110 6136
6111 // Set a debug message handler. 6137 // Set a debug message handler.
6112 v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler); 6138 v8::Debug::SetMessageHandler(env->GetIsolate(),
6139 MessageHandlerClearingMessageHandler);
6113 6140
6114 // Run code to throw a unhandled exception. This should end up in the message 6141 // Run code to throw a unhandled exception. This should end up in the message
6115 // handler. 6142 // handler.
6116 CompileRun("throw 1"); 6143 CompileRun("throw 1");
6117 6144
6118 // The message handler should be called. 6145 // The message handler should be called.
6119 CHECK_EQ(1, message_handler_hit_count); 6146 CHECK_EQ(1, message_handler_hit_count);
6120 6147
6121 CheckDebuggerUnloaded(true); 6148 CheckDebuggerUnloaded(env->GetIsolate(), true);
6122 } 6149 }
6123 6150
6124 6151
6125 // Test for issue http://code.google.com/p/v8/issues/detail?id=289. 6152 // Test for issue http://code.google.com/p/v8/issues/detail?id=289.
6126 // Make sure that DebugGetLoadedScripts doesn't return scripts 6153 // Make sure that DebugGetLoadedScripts doesn't return scripts
6127 // with disposed external source. 6154 // with disposed external source.
6128 class EmptyExternalStringResource : public v8::String::ExternalStringResource { 6155 class EmptyExternalStringResource : public v8::String::ExternalStringResource {
6129 public: 6156 public:
6130 EmptyExternalStringResource() { empty_[0] = 0; } 6157 EmptyExternalStringResource() { empty_[0] = 0; }
6131 virtual ~EmptyExternalStringResource() {} 6158 virtual ~EmptyExternalStringResource() {}
(...skipping 16 matching lines...) Expand all
6148 .ToLocalChecked(); 6175 .ToLocalChecked();
6149 CHECK(v8::Script::Compile(context, source).IsEmpty()); 6176 CHECK(v8::Script::Compile(context, source).IsEmpty());
6150 Handle<i::ExternalTwoByteString> i_source( 6177 Handle<i::ExternalTwoByteString> i_source(
6151 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); 6178 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
6152 // This situation can happen if source was an external string disposed 6179 // This situation can happen if source was an external string disposed
6153 // by its owner. 6180 // by its owner.
6154 i_source->set_resource(0); 6181 i_source->set_resource(0);
6155 6182
6156 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; 6183 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
6157 i::FLAG_allow_natives_syntax = true; 6184 i::FLAG_allow_natives_syntax = true;
6158 EnableDebugger(); 6185 EnableDebugger(env->GetIsolate());
6159 v8::MaybeLocal<v8::Value> result = 6186 v8::MaybeLocal<v8::Value> result =
6160 CompileRun(env.context(), 6187 CompileRun(env.context(),
6161 "var scripts = %DebugGetLoadedScripts();" 6188 "var scripts = %DebugGetLoadedScripts();"
6162 "var count = scripts.length;" 6189 "var count = scripts.length;"
6163 "for (var i = 0; i < count; ++i) {" 6190 "for (var i = 0; i < count; ++i) {"
6164 " var lines = scripts[i].lineCount();" 6191 " var lines = scripts[i].lineCount();"
6165 " if (lines < 1) throw 'lineCount';" 6192 " if (lines < 1) throw 'lineCount';"
6166 " var last = -1;" 6193 " var last = -1;"
6167 " for (var j = 0; j < lines; ++j) {" 6194 " for (var j = 0; j < lines; ++j) {"
6168 " var end = scripts[i].lineEnd(j);" 6195 " var end = scripts[i].lineEnd(j);"
6169 " if (last >= end) throw 'lineEnd';" 6196 " if (last >= end) throw 'lineEnd';"
6170 " last = end;" 6197 " last = end;"
6171 " }" 6198 " }"
6172 "}"); 6199 "}");
6173 CHECK(!result.IsEmpty()); 6200 CHECK(!result.IsEmpty());
6174 DisableDebugger(); 6201 DisableDebugger(env->GetIsolate());
6175 // Must not crash while accessing line_ends. 6202 // Must not crash while accessing line_ends.
6176 i::FLAG_allow_natives_syntax = allow_natives_syntax; 6203 i::FLAG_allow_natives_syntax = allow_natives_syntax;
6177 6204
6178 // Some scripts are retrieved - at least the number of native scripts. 6205 // Some scripts are retrieved - at least the number of native scripts.
6179 CHECK_GT(env->Global() 6206 CHECK_GT(env->Global()
6180 ->Get(context, v8_str(env->GetIsolate(), "count")) 6207 ->Get(context, v8_str(env->GetIsolate(), "count"))
6181 .ToLocalChecked() 6208 .ToLocalChecked()
6182 ->Int32Value(context) 6209 ->Int32Value(context)
6183 .FromJust(), 6210 .FromJust(),
6184 8); 6211 8);
6185 } 6212 }
6186 6213
6187 6214
6188 // Test script break points set on lines. 6215 // Test script break points set on lines.
6189 TEST(ScriptNameAndData) { 6216 TEST(ScriptNameAndData) {
6190 DebugLocalContext env; 6217 DebugLocalContext env;
6191 v8::HandleScope scope(env->GetIsolate()); 6218 v8::HandleScope scope(env->GetIsolate());
6192 env.ExposeDebug(); 6219 env.ExposeDebug();
6193 6220
6194 // Create functions for retrieving script name and data for the function on 6221 // Create functions for retrieving script name and data for the function on
6195 // the top frame when hitting a break point. 6222 // the top frame when hitting a break point.
6196 frame_script_name = CompileFunction(&env, 6223 frame_script_name = CompileFunction(&env,
6197 frame_script_name_source, 6224 frame_script_name_source,
6198 "frame_script_name"); 6225 "frame_script_name");
6199 6226
6200 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 6227 v8::Debug::SetDebugEventListener(env->GetIsolate(),
6228 DebugEventBreakPointHitCount);
6201 6229
6202 v8::Local<v8::Context> context = env.context(); 6230 v8::Local<v8::Context> context = env.context();
6203 // Test function source. 6231 // Test function source.
6204 v8::Local<v8::String> script = v8_str(env->GetIsolate(), 6232 v8::Local<v8::String> script = v8_str(env->GetIsolate(),
6205 "function f() {\n" 6233 "function f() {\n"
6206 " debugger;\n" 6234 " debugger;\n"
6207 "}\n"); 6235 "}\n");
6208 6236
6209 v8::ScriptOrigin origin1 = 6237 v8::ScriptOrigin origin1 =
6210 v8::ScriptOrigin(v8_str(env->GetIsolate(), "name")); 6238 v8::ScriptOrigin(v8_str(env->GetIsolate(), "name"));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
6301 6329
6302 // Create two contexts. 6330 // Create two contexts.
6303 v8::Local<v8::Context> context_1; 6331 v8::Local<v8::Context> context_1;
6304 v8::Local<v8::Context> context_2; 6332 v8::Local<v8::Context> context_2;
6305 v8::Local<v8::ObjectTemplate> global_template = 6333 v8::Local<v8::ObjectTemplate> global_template =
6306 v8::Local<v8::ObjectTemplate>(); 6334 v8::Local<v8::ObjectTemplate>();
6307 v8::Local<v8::Value> global_object = v8::Local<v8::Value>(); 6335 v8::Local<v8::Value> global_object = v8::Local<v8::Value>();
6308 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); 6336 context_1 = v8::Context::New(isolate, NULL, global_template, global_object);
6309 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); 6337 context_2 = v8::Context::New(isolate, NULL, global_template, global_object);
6310 6338
6311 v8::Debug::SetMessageHandler(ContextCheckMessageHandler); 6339 v8::Debug::SetMessageHandler(isolate, ContextCheckMessageHandler);
6312 6340
6313 // Default data value is undefined. 6341 // Default data value is undefined.
6314 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); 6342 CHECK(context_1->GetEmbedderData(0)->IsUndefined());
6315 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); 6343 CHECK(context_2->GetEmbedderData(0)->IsUndefined());
6316 6344
6317 // Set and check different data values. 6345 // Set and check different data values.
6318 v8::Local<v8::String> data_1 = v8_str(isolate, "1"); 6346 v8::Local<v8::String> data_1 = v8_str(isolate, "1");
6319 v8::Local<v8::String> data_2 = v8_str(isolate, "2"); 6347 v8::Local<v8::String> data_2 = v8_str(isolate, "2");
6320 context_1->SetEmbedderData(0, data_1); 6348 context_1->SetEmbedderData(0, data_1);
6321 context_2->SetEmbedderData(0, data_2); 6349 context_2->SetEmbedderData(0, data_2);
(...skipping 18 matching lines...) Expand all
6340 v8::Context::Scope context_scope(context_2); 6368 v8::Context::Scope context_scope(context_2);
6341 expected_context = context_2; 6369 expected_context = context_2;
6342 expected_context_data = data_2; 6370 expected_context_data = data_2;
6343 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); 6371 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f");
6344 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked(); 6372 f->Call(context_2, context_2->Global(), 0, NULL).ToLocalChecked();
6345 } 6373 }
6346 6374
6347 // Two times compile event and two times break event. 6375 // Two times compile event and two times break event.
6348 CHECK_GT(message_handler_hit_count, 4); 6376 CHECK_GT(message_handler_hit_count, 4);
6349 6377
6350 v8::Debug::SetMessageHandler(NULL); 6378 v8::Debug::SetMessageHandler(isolate, nullptr);
6351 CheckDebuggerUnloaded(); 6379 CheckDebuggerUnloaded(isolate);
6352 } 6380 }
6353 6381
6354 6382
6355 // Debug message handler which issues a debug break when it hits a break event. 6383 // Debug message handler which issues a debug break when it hits a break event.
6356 static int message_handler_break_hit_count = 0; 6384 static int message_handler_break_hit_count = 0;
6357 static void DebugBreakMessageHandler(const v8::Debug::Message& message) { 6385 static void DebugBreakMessageHandler(const v8::Debug::Message& message) {
6358 // Schedule a debug break for break events. 6386 // Schedule a debug break for break events.
6359 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6387 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6360 message_handler_break_hit_count++; 6388 message_handler_break_hit_count++;
6361 if (message_handler_break_hit_count == 1) { 6389 if (message_handler_break_hit_count == 1) {
6362 v8::Debug::DebugBreak(message.GetIsolate()); 6390 v8::Debug::DebugBreak(message.GetIsolate());
6363 } 6391 }
6364 } 6392 }
6365 6393
6366 // Issue a continue command if this event will not cause the VM to start 6394 // Issue a continue command if this event will not cause the VM to start
6367 // running. 6395 // running.
6368 if (!message.WillStartRunning()) { 6396 if (!message.WillStartRunning()) {
6369 SendContinueCommand(); 6397 SendContinueCommand();
6370 } 6398 }
6371 } 6399 }
6372 6400
6373 6401
6374 // Test that a debug break can be scheduled while in a message handler. 6402 // Test that a debug break can be scheduled while in a message handler.
6375 TEST(DebugBreakInMessageHandler) { 6403 TEST(DebugBreakInMessageHandler) {
6376 i::FLAG_turbo_inlining = false; // Make sure g is not inlined into f. 6404 i::FLAG_turbo_inlining = false; // Make sure g is not inlined into f.
6377 DebugLocalContext env; 6405 DebugLocalContext env;
6378 v8::HandleScope scope(env->GetIsolate()); 6406 v8::HandleScope scope(env->GetIsolate());
6379 6407
6380 v8::Debug::SetMessageHandler(DebugBreakMessageHandler); 6408 v8::Debug::SetMessageHandler(env->GetIsolate(), DebugBreakMessageHandler);
6381 6409
6382 v8::Local<v8::Context> context = env.context(); 6410 v8::Local<v8::Context> context = env.context();
6383 // Test functions. 6411 // Test functions.
6384 const char* script = "function f() { debugger; g(); } function g() { }"; 6412 const char* script = "function f() { debugger; g(); } function g() { }";
6385 CompileRun(script); 6413 CompileRun(script);
6386 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 6414 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
6387 env->Global() 6415 env->Global()
6388 ->Get(context, v8_str(env->GetIsolate(), "f")) 6416 ->Get(context, v8_str(env->GetIsolate(), "f"))
6389 .ToLocalChecked()); 6417 .ToLocalChecked());
6390 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 6418 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
6457 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; 6485 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }";
6458 6486
6459 v8::Local<v8::Function> f = CompileFunction(env->GetIsolate(), script, "f"); 6487 v8::Local<v8::Function> f = CompileFunction(env->GetIsolate(), script, "f");
6460 const int argc = 1; 6488 const int argc = 1;
6461 v8::Local<v8::Value> argv[argc] = { 6489 v8::Local<v8::Value> argv[argc] = {
6462 v8_str(env->GetIsolate(), " /* xxx */ a=0;")}; 6490 v8_str(env->GetIsolate(), " /* xxx */ a=0;")};
6463 v8::Local<v8::Value> result = 6491 v8::Local<v8::Value> result =
6464 f->Call(context, env->Global(), argc, argv).ToLocalChecked(); 6492 f->Call(context, env->Global(), argc, argv).ToLocalChecked();
6465 CHECK_EQ(12, result->Int32Value(context).FromJust()); 6493 CHECK_EQ(12, result->Int32Value(context).FromJust());
6466 6494
6467 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); 6495 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventDebugBreak);
6468 v8::Debug::DebugBreak(env->GetIsolate()); 6496 v8::Debug::DebugBreak(env->GetIsolate());
6469 result = f->Call(context, env->Global(), argc, argv).ToLocalChecked(); 6497 result = f->Call(context, env->Global(), argc, argv).ToLocalChecked();
6470 6498
6471 // Check that there was only one break event. Matching RegExp should not 6499 // Check that there was only one break event. Matching RegExp should not
6472 // cause Break events. 6500 // cause Break events.
6473 CHECK_EQ(1, break_point_hit_count); 6501 CHECK_EQ(1, break_point_hit_count);
6474 CHECK_EQ(0, strcmp("f", last_function_hit)); 6502 CHECK_EQ(0, strcmp("f", last_function_hit));
6475 } 6503 }
6476 #endif // V8_INTERPRETED_REGEXP 6504 #endif // V8_INTERPRETED_REGEXP
6477 6505
6478 6506
6479 // Common part of EvalContextData and NestedBreakEventContextData tests. 6507 // Common part of EvalContextData and NestedBreakEventContextData tests.
6480 static void ExecuteScriptForContextCheck( 6508 static void ExecuteScriptForContextCheck(
6481 v8::Debug::MessageHandler message_handler) { 6509 v8::Debug::MessageHandler message_handler) {
6482 // Create a context. 6510 // Create a context.
6483 v8::Local<v8::Context> context_1; 6511 v8::Local<v8::Context> context_1;
6484 v8::Local<v8::ObjectTemplate> global_template = 6512 v8::Local<v8::ObjectTemplate> global_template =
6485 v8::Local<v8::ObjectTemplate>(); 6513 v8::Local<v8::ObjectTemplate>();
6486 context_1 = 6514 context_1 =
6487 v8::Context::New(CcTest::isolate(), NULL, global_template); 6515 v8::Context::New(CcTest::isolate(), NULL, global_template);
6488 6516
6489 v8::Debug::SetMessageHandler(message_handler); 6517 v8::Debug::SetMessageHandler(CcTest::isolate(), message_handler);
6490 6518
6491 // Default data value is undefined. 6519 // Default data value is undefined.
6492 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); 6520 CHECK(context_1->GetEmbedderData(0)->IsUndefined());
6493 6521
6494 // Set and check a data value. 6522 // Set and check a data value.
6495 v8::Local<v8::String> data_1 = v8_str(CcTest::isolate(), "1"); 6523 v8::Local<v8::String> data_1 = v8_str(CcTest::isolate(), "1");
6496 context_1->SetEmbedderData(0, data_1); 6524 context_1->SetEmbedderData(0, data_1);
6497 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); 6525 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
6498 6526
6499 // Simple test function with eval that causes a break. 6527 // Simple test function with eval that causes a break.
6500 const char* source = "function f() { eval('debugger;'); }"; 6528 const char* source = "function f() { eval('debugger;'); }";
6501 6529
6502 // Enter and run function in the context. 6530 // Enter and run function in the context.
6503 { 6531 {
6504 v8::Context::Scope context_scope(context_1); 6532 v8::Context::Scope context_scope(context_1);
6505 expected_context = context_1; 6533 expected_context = context_1;
6506 expected_context_data = data_1; 6534 expected_context_data = data_1;
6507 v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f"); 6535 v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f");
6508 f->Call(context_1, context_1->Global(), 0, NULL).ToLocalChecked(); 6536 f->Call(context_1, context_1->Global(), 0, NULL).ToLocalChecked();
6509 } 6537 }
6510 6538
6511 v8::Debug::SetMessageHandler(NULL); 6539 v8::Debug::SetMessageHandler(CcTest::isolate(), nullptr);
6512 } 6540 }
6513 6541
6514 6542
6515 // Test which creates a context and sets embedder data on it. Checks that this 6543 // Test which creates a context and sets embedder data on it. Checks that this
6516 // data is set correctly and that when the debug message handler is called for 6544 // data is set correctly and that when the debug message handler is called for
6517 // break event in an eval statement the expected context is the one returned by 6545 // break event in an eval statement the expected context is the one returned by
6518 // Message.GetEventContext. 6546 // Message.GetEventContext.
6519 TEST(EvalContextData) { 6547 TEST(EvalContextData) {
6520 v8::HandleScope scope(CcTest::isolate()); 6548 v8::HandleScope scope(CcTest::isolate());
6521 6549
6522 ExecuteScriptForContextCheck(ContextCheckMessageHandler); 6550 ExecuteScriptForContextCheck(ContextCheckMessageHandler);
6523 6551
6524 // One time compile event and one time break event. 6552 // One time compile event and one time break event.
6525 CHECK_GT(message_handler_hit_count, 2); 6553 CHECK_GT(message_handler_hit_count, 2);
6526 CheckDebuggerUnloaded(); 6554 CheckDebuggerUnloaded(CcTest::isolate());
6527 } 6555 }
6528 6556
6529 6557
6530 static bool sent_eval = false; 6558 static bool sent_eval = false;
6531 static int break_count = 0; 6559 static int break_count = 0;
6532 static int continue_command_send_count = 0; 6560 static int continue_command_send_count = 0;
6533 // Check that the expected context is the one generating the debug event 6561 // Check that the expected context is the one generating the debug event
6534 // including the case of nested break event. 6562 // including the case of nested break event.
6535 static void DebugEvalContextCheckMessageHandler( 6563 static void DebugEvalContextCheckMessageHandler(
6536 const v8::Debug::Message& message) { 6564 const v8::Debug::Message& message) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
6584 break_count = 0; 6612 break_count = 0;
6585 message_handler_hit_count = 0; 6613 message_handler_hit_count = 0;
6586 6614
6587 ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler); 6615 ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler);
6588 6616
6589 // One time compile event and two times break event. 6617 // One time compile event and two times break event.
6590 CHECK_GT(message_handler_hit_count, 3); 6618 CHECK_GT(message_handler_hit_count, 3);
6591 6619
6592 // One break from the source and another from the evaluate request. 6620 // One break from the source and another from the evaluate request.
6593 CHECK_EQ(break_count, 2); 6621 CHECK_EQ(break_count, 2);
6594 CheckDebuggerUnloaded(); 6622 CheckDebuggerUnloaded(CcTest::isolate());
6595 } 6623 }
6596 6624
6597 6625
6598 // Debug event listener which counts the after compile events. 6626 // Debug event listener which counts the after compile events.
6599 int after_compile_message_count = 0; 6627 int after_compile_message_count = 0;
6600 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { 6628 static void AfterCompileMessageHandler(const v8::Debug::Message& message) {
6601 // Count the number of scripts collected. 6629 // Count the number of scripts collected.
6602 if (message.IsEvent()) { 6630 if (message.IsEvent()) {
6603 if (message.GetEvent() == v8::AfterCompile) { 6631 if (message.GetEvent() == v8::AfterCompile) {
6604 after_compile_message_count++; 6632 after_compile_message_count++;
6605 } else if (message.GetEvent() == v8::Break) { 6633 } else if (message.GetEvent() == v8::Break) {
6606 SendContinueCommand(); 6634 SendContinueCommand();
6607 } 6635 }
6608 } 6636 }
6609 } 6637 }
6610 6638
6611 6639
6612 // Tests that after compile event is sent as many times as there are scripts 6640 // Tests that after compile event is sent as many times as there are scripts
6613 // compiled. 6641 // compiled.
6614 TEST(AfterCompileMessageWhenMessageHandlerIsReset) { 6642 TEST(AfterCompileMessageWhenMessageHandlerIsReset) {
6615 DebugLocalContext env; 6643 DebugLocalContext env;
6616 v8::HandleScope scope(env->GetIsolate()); 6644 v8::HandleScope scope(env->GetIsolate());
6617 v8::Local<v8::Context> context = env.context(); 6645 v8::Local<v8::Context> context = env.context();
6618 after_compile_message_count = 0; 6646 after_compile_message_count = 0;
6619 const char* script = "var a=1"; 6647 const char* script = "var a=1";
6620 6648
6621 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6649 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6622 v8::Script::Compile(context, v8_str(env->GetIsolate(), script)) 6650 v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
6623 .ToLocalChecked() 6651 .ToLocalChecked()
6624 ->Run(context) 6652 ->Run(context)
6625 .ToLocalChecked(); 6653 .ToLocalChecked();
6626 v8::Debug::SetMessageHandler(NULL); 6654 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6627 6655
6628 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6656 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6629 v8::Debug::DebugBreak(env->GetIsolate()); 6657 v8::Debug::DebugBreak(env->GetIsolate());
6630 v8::Script::Compile(context, v8_str(env->GetIsolate(), script)) 6658 v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
6631 .ToLocalChecked() 6659 .ToLocalChecked()
6632 ->Run(context) 6660 ->Run(context)
6633 .ToLocalChecked(); 6661 .ToLocalChecked();
6634 6662
6635 // Setting listener to NULL should cause debugger unload. 6663 // Setting listener to NULL should cause debugger unload.
6636 v8::Debug::SetMessageHandler(NULL); 6664 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6637 CheckDebuggerUnloaded(); 6665 CheckDebuggerUnloaded(env->GetIsolate());
6638 6666
6639 // Compilation cache should be disabled when debugger is active. 6667 // Compilation cache should be disabled when debugger is active.
6640 CHECK_EQ(2, after_compile_message_count); 6668 CHECK_EQ(2, after_compile_message_count);
6641 } 6669 }
6642 6670
6643 6671
6644 // Syntax error event handler which counts a number of events. 6672 // Syntax error event handler which counts a number of events.
6645 int compile_error_event_count = 0; 6673 int compile_error_event_count = 0;
6646 6674
6647 static void CompileErrorEventCounterClear() { 6675 static void CompileErrorEventCounterClear() {
(...skipping 12 matching lines...) Expand all
6660 6688
6661 // Tests that syntax error event is sent as many times as there are scripts 6689 // Tests that syntax error event is sent as many times as there are scripts
6662 // with syntax error compiled. 6690 // with syntax error compiled.
6663 TEST(SyntaxErrorMessageOnSyntaxException) { 6691 TEST(SyntaxErrorMessageOnSyntaxException) {
6664 DebugLocalContext env; 6692 DebugLocalContext env;
6665 v8::HandleScope scope(env->GetIsolate()); 6693 v8::HandleScope scope(env->GetIsolate());
6666 6694
6667 // For this test, we want to break on uncaught exceptions: 6695 // For this test, we want to break on uncaught exceptions:
6668 ChangeBreakOnException(false, true); 6696 ChangeBreakOnException(false, true);
6669 6697
6670 v8::Debug::SetDebugEventListener(CompileErrorEventCounter); 6698 v8::Debug::SetDebugEventListener(env->GetIsolate(), CompileErrorEventCounter);
6671 v8::Local<v8::Context> context = env.context(); 6699 v8::Local<v8::Context> context = env.context();
6672 6700
6673 CompileErrorEventCounterClear(); 6701 CompileErrorEventCounterClear();
6674 6702
6675 // Check initial state. 6703 // Check initial state.
6676 CHECK_EQ(0, compile_error_event_count); 6704 CHECK_EQ(0, compile_error_event_count);
6677 6705
6678 // Throws SyntaxError: Unexpected end of input 6706 // Throws SyntaxError: Unexpected end of input
6679 CHECK( 6707 CHECK(
6680 v8::Script::Compile(context, v8_str(env->GetIsolate(), "+++")).IsEmpty()); 6708 v8::Script::Compile(context, v8_str(env->GetIsolate(), "+++")).IsEmpty());
(...skipping 23 matching lines...) Expand all
6704 6732
6705 6733
6706 // Tests that break event is sent when message handler is reset. 6734 // Tests that break event is sent when message handler is reset.
6707 TEST(BreakMessageWhenMessageHandlerIsReset) { 6735 TEST(BreakMessageWhenMessageHandlerIsReset) {
6708 DebugLocalContext env; 6736 DebugLocalContext env;
6709 v8::HandleScope scope(env->GetIsolate()); 6737 v8::HandleScope scope(env->GetIsolate());
6710 v8::Local<v8::Context> context = env.context(); 6738 v8::Local<v8::Context> context = env.context();
6711 after_compile_message_count = 0; 6739 after_compile_message_count = 0;
6712 const char* script = "function f() {};"; 6740 const char* script = "function f() {};";
6713 6741
6714 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6742 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6715 v8::Script::Compile(context, v8_str(env->GetIsolate(), script)) 6743 v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
6716 .ToLocalChecked() 6744 .ToLocalChecked()
6717 ->Run(context) 6745 ->Run(context)
6718 .ToLocalChecked(); 6746 .ToLocalChecked();
6719 v8::Debug::SetMessageHandler(NULL); 6747 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6720 6748
6721 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6749 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6722 v8::Debug::DebugBreak(env->GetIsolate()); 6750 v8::Debug::DebugBreak(env->GetIsolate());
6723 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 6751 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
6724 env->Global() 6752 env->Global()
6725 ->Get(context, v8_str(env->GetIsolate(), "f")) 6753 ->Get(context, v8_str(env->GetIsolate(), "f"))
6726 .ToLocalChecked()); 6754 .ToLocalChecked());
6727 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6755 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
6728 6756
6729 // Setting message handler to NULL should cause debugger unload. 6757 // Setting message handler to NULL should cause debugger unload.
6730 v8::Debug::SetMessageHandler(NULL); 6758 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6731 CheckDebuggerUnloaded(); 6759 CheckDebuggerUnloaded(env->GetIsolate());
6732 6760
6733 // Compilation cache should be disabled when debugger is active. 6761 // Compilation cache should be disabled when debugger is active.
6734 CHECK_EQ(1, after_compile_message_count); 6762 CHECK_EQ(1, after_compile_message_count);
6735 } 6763 }
6736 6764
6737 6765
6738 static int exception_event_count = 0; 6766 static int exception_event_count = 0;
6739 static void ExceptionMessageHandler(const v8::Debug::Message& message) { 6767 static void ExceptionMessageHandler(const v8::Debug::Message& message) {
6740 if (message.IsEvent() && message.GetEvent() == v8::Exception) { 6768 if (message.IsEvent() && message.GetEvent() == v8::Exception) {
6741 exception_event_count++; 6769 exception_event_count++;
6742 SendContinueCommand(); 6770 SendContinueCommand();
6743 } 6771 }
6744 } 6772 }
6745 6773
6746 6774
6747 // Tests that exception event is sent when message handler is reset. 6775 // Tests that exception event is sent when message handler is reset.
6748 TEST(ExceptionMessageWhenMessageHandlerIsReset) { 6776 TEST(ExceptionMessageWhenMessageHandlerIsReset) {
6749 DebugLocalContext env; 6777 DebugLocalContext env;
6750 v8::HandleScope scope(env->GetIsolate()); 6778 v8::HandleScope scope(env->GetIsolate());
6751 6779
6752 v8::Local<v8::Context> context = env.context(); 6780 v8::Local<v8::Context> context = env.context();
6753 // For this test, we want to break on uncaught exceptions: 6781 // For this test, we want to break on uncaught exceptions:
6754 ChangeBreakOnException(false, true); 6782 ChangeBreakOnException(false, true);
6755 6783
6756 exception_event_count = 0; 6784 exception_event_count = 0;
6757 const char* script = "function f() {throw new Error()};"; 6785 const char* script = "function f() {throw new Error()};";
6758 6786
6759 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6787 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6760 v8::Script::Compile(context, v8_str(env->GetIsolate(), script)) 6788 v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
6761 .ToLocalChecked() 6789 .ToLocalChecked()
6762 ->Run(context) 6790 ->Run(context)
6763 .ToLocalChecked(); 6791 .ToLocalChecked();
6764 v8::Debug::SetMessageHandler(NULL); 6792 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6765 6793
6766 v8::Debug::SetMessageHandler(ExceptionMessageHandler); 6794 v8::Debug::SetMessageHandler(env->GetIsolate(), ExceptionMessageHandler);
6767 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 6795 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
6768 env->Global() 6796 env->Global()
6769 ->Get(context, v8_str(env->GetIsolate(), "f")) 6797 ->Get(context, v8_str(env->GetIsolate(), "f"))
6770 .ToLocalChecked()); 6798 .ToLocalChecked());
6771 CHECK(f->Call(context, env->Global(), 0, NULL).IsEmpty()); 6799 CHECK(f->Call(context, env->Global(), 0, NULL).IsEmpty());
6772 6800
6773 // Setting message handler to NULL should cause debugger unload. 6801 // Setting message handler to NULL should cause debugger unload.
6774 v8::Debug::SetMessageHandler(NULL); 6802 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6775 CheckDebuggerUnloaded(); 6803 CheckDebuggerUnloaded(env->GetIsolate());
6776 6804
6777 CHECK_EQ(1, exception_event_count); 6805 CHECK_EQ(1, exception_event_count);
6778 } 6806 }
6779 6807
6780 6808
6781 // Tests after compile event is sent when there are some provisional 6809 // Tests after compile event is sent when there are some provisional
6782 // breakpoints out of the scripts lines range. 6810 // breakpoints out of the scripts lines range.
6783 TEST(ProvisionalBreakpointOnLineOutOfRange) { 6811 TEST(ProvisionalBreakpointOnLineOutOfRange) {
6784 DebugLocalContext env; 6812 DebugLocalContext env;
6785 v8::HandleScope scope(env->GetIsolate()); 6813 v8::HandleScope scope(env->GetIsolate());
6786 env.ExposeDebug(); 6814 env.ExposeDebug();
6787 const char* script = "function f() {};"; 6815 const char* script = "function f() {};";
6788 const char* resource_name = "test_resource"; 6816 const char* resource_name = "test_resource";
6789 6817
6790 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); 6818 v8::Debug::SetMessageHandler(env->GetIsolate(), AfterCompileMessageHandler);
6791 v8::Local<v8::Context> context = env.context(); 6819 v8::Local<v8::Context> context = env.context();
6792 6820
6793 // Set a couple of provisional breakpoint on lines out of the script lines 6821 // Set a couple of provisional breakpoint on lines out of the script lines
6794 // range. 6822 // range.
6795 int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 6823 int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name,
6796 3, -1 /* no column */); 6824 3, -1 /* no column */);
6797 int sbp2 = 6825 int sbp2 =
6798 SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5); 6826 SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5);
6799 6827
6800 after_compile_message_count = 0; 6828 after_compile_message_count = 0;
6801 6829
6802 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), resource_name), 6830 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), resource_name),
6803 v8::Integer::New(env->GetIsolate(), 10), 6831 v8::Integer::New(env->GetIsolate(), 10),
6804 v8::Integer::New(env->GetIsolate(), 1)); 6832 v8::Integer::New(env->GetIsolate(), 1));
6805 // Compile a script whose first line number is greater than the breakpoints' 6833 // Compile a script whose first line number is greater than the breakpoints'
6806 // lines. 6834 // lines.
6807 v8::Script::Compile(context, v8_str(env->GetIsolate(), script), &origin) 6835 v8::Script::Compile(context, v8_str(env->GetIsolate(), script), &origin)
6808 .ToLocalChecked() 6836 .ToLocalChecked()
6809 ->Run(context) 6837 ->Run(context)
6810 .ToLocalChecked(); 6838 .ToLocalChecked();
6811 6839
6812 // If the script is compiled successfully there is exactly one after compile 6840 // If the script is compiled successfully there is exactly one after compile
6813 // event. In case of an exception in debugger code after compile event is not 6841 // event. In case of an exception in debugger code after compile event is not
6814 // sent. 6842 // sent.
6815 CHECK_EQ(1, after_compile_message_count); 6843 CHECK_EQ(1, after_compile_message_count);
6816 6844
6817 ClearBreakPointFromJS(env->GetIsolate(), sbp1); 6845 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
6818 ClearBreakPointFromJS(env->GetIsolate(), sbp2); 6846 ClearBreakPointFromJS(env->GetIsolate(), sbp2);
6819 v8::Debug::SetMessageHandler(NULL); 6847 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6820 } 6848 }
6821 6849
6822 6850
6823 static void BreakMessageHandler(const v8::Debug::Message& message) { 6851 static void BreakMessageHandler(const v8::Debug::Message& message) {
6824 i::Isolate* isolate = CcTest::i_isolate(); 6852 i::Isolate* isolate = CcTest::i_isolate();
6825 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6853 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6826 // Count the number of breaks. 6854 // Count the number of breaks.
6827 break_point_hit_count++; 6855 break_point_hit_count++;
6828 6856
6829 i::HandleScope scope(isolate); 6857 i::HandleScope scope(isolate);
(...skipping 14 matching lines...) Expand all
6844 6872
6845 6873
6846 // Test that if DebugBreak is forced it is ignored when code from 6874 // Test that if DebugBreak is forced it is ignored when code from
6847 // debug-delay.js is executed. 6875 // debug-delay.js is executed.
6848 TEST(NoDebugBreakInAfterCompileMessageHandler) { 6876 TEST(NoDebugBreakInAfterCompileMessageHandler) {
6849 DebugLocalContext env; 6877 DebugLocalContext env;
6850 v8::HandleScope scope(env->GetIsolate()); 6878 v8::HandleScope scope(env->GetIsolate());
6851 v8::Local<v8::Context> context = env.context(); 6879 v8::Local<v8::Context> context = env.context();
6852 6880
6853 // Register a debug event listener which sets the break flag and counts. 6881 // Register a debug event listener which sets the break flag and counts.
6854 v8::Debug::SetMessageHandler(BreakMessageHandler); 6882 v8::Debug::SetMessageHandler(env->GetIsolate(), BreakMessageHandler);
6855 6883
6856 // Set the debug break flag. 6884 // Set the debug break flag.
6857 v8::Debug::DebugBreak(env->GetIsolate()); 6885 v8::Debug::DebugBreak(env->GetIsolate());
6858 6886
6859 // Create a function for testing stepping. 6887 // Create a function for testing stepping.
6860 const char* src = "function f() { eval('var x = 10;'); } "; 6888 const char* src = "function f() { eval('var x = 10;'); } ";
6861 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 6889 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
6862 6890
6863 // There should be only one break event. 6891 // There should be only one break event.
6864 CHECK_EQ(1, break_point_hit_count); 6892 CHECK_EQ(1, break_point_hit_count);
6865 6893
6866 // Set the debug break flag again. 6894 // Set the debug break flag again.
6867 v8::Debug::DebugBreak(env->GetIsolate()); 6895 v8::Debug::DebugBreak(env->GetIsolate());
6868 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 6896 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
6869 // There should be one more break event when the script is evaluated in 'f'. 6897 // There should be one more break event when the script is evaluated in 'f'.
6870 CHECK_EQ(2, break_point_hit_count); 6898 CHECK_EQ(2, break_point_hit_count);
6871 6899
6872 // Get rid of the debug message handler. 6900 // Get rid of the debug message handler.
6873 v8::Debug::SetMessageHandler(NULL); 6901 v8::Debug::SetMessageHandler(env->GetIsolate(), nullptr);
6874 CheckDebuggerUnloaded(); 6902 CheckDebuggerUnloaded(env->GetIsolate());
6875 } 6903 }
6876 6904
6877 6905
6878 static int counting_message_handler_counter; 6906 static int counting_message_handler_counter;
6879 6907
6880 static void CountingMessageHandler(const v8::Debug::Message& message) { 6908 static void CountingMessageHandler(const v8::Debug::Message& message) {
6881 if (message.IsResponse()) counting_message_handler_counter++; 6909 if (message.IsResponse()) counting_message_handler_counter++;
6882 } 6910 }
6883 6911
6884 6912
6885 // Test that debug messages get processed when ProcessDebugMessages is called. 6913 // Test that debug messages get processed when ProcessDebugMessages is called.
6886 TEST(ProcessDebugMessages) { 6914 TEST(ProcessDebugMessages) {
6887 DebugLocalContext env; 6915 DebugLocalContext env;
6888 v8::Isolate* isolate = env->GetIsolate(); 6916 v8::Isolate* isolate = env->GetIsolate();
6889 v8::HandleScope scope(isolate); 6917 v8::HandleScope scope(isolate);
6890 6918
6891 counting_message_handler_counter = 0; 6919 counting_message_handler_counter = 0;
6892 6920
6893 v8::Debug::SetMessageHandler(CountingMessageHandler); 6921 v8::Debug::SetMessageHandler(isolate, CountingMessageHandler);
6894 6922
6895 const int kBufferSize = 1000; 6923 const int kBufferSize = 1000;
6896 uint16_t buffer[kBufferSize]; 6924 uint16_t buffer[kBufferSize];
6897 const char* scripts_command = 6925 const char* scripts_command =
6898 "{\"seq\":0," 6926 "{\"seq\":0,"
6899 "\"type\":\"request\"," 6927 "\"type\":\"request\","
6900 "\"command\":\"scripts\"}"; 6928 "\"command\":\"scripts\"}";
6901 6929
6902 // Send scripts command. 6930 // Send scripts command.
6903 v8::Debug::SendCommand( 6931 v8::Debug::SendCommand(
6904 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); 6932 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6905 6933
6906 CHECK_EQ(0, counting_message_handler_counter); 6934 CHECK_EQ(0, counting_message_handler_counter);
6907 v8::Debug::ProcessDebugMessages(); 6935 v8::Debug::ProcessDebugMessages(isolate);
6908 // At least one message should come 6936 // At least one message should come
6909 CHECK_GE(counting_message_handler_counter, 1); 6937 CHECK_GE(counting_message_handler_counter, 1);
6910 6938
6911 counting_message_handler_counter = 0; 6939 counting_message_handler_counter = 0;
6912 6940
6913 v8::Debug::SendCommand( 6941 v8::Debug::SendCommand(
6914 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); 6942 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6915 v8::Debug::SendCommand( 6943 v8::Debug::SendCommand(
6916 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); 6944 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6917 CHECK_EQ(0, counting_message_handler_counter); 6945 CHECK_EQ(0, counting_message_handler_counter);
6918 v8::Debug::ProcessDebugMessages(); 6946 v8::Debug::ProcessDebugMessages(isolate);
6919 // At least two messages should come 6947 // At least two messages should come
6920 CHECK_GE(counting_message_handler_counter, 2); 6948 CHECK_GE(counting_message_handler_counter, 2);
6921 6949
6922 // Get rid of the debug message handler. 6950 // Get rid of the debug message handler.
6923 v8::Debug::SetMessageHandler(NULL); 6951 v8::Debug::SetMessageHandler(isolate, nullptr);
6924 CheckDebuggerUnloaded(); 6952 CheckDebuggerUnloaded(isolate);
6925 } 6953 }
6926 6954
6927 6955
6928 class SendCommandThread; 6956 class SendCommandThread;
6929 static SendCommandThread* send_command_thread_ = NULL; 6957 static SendCommandThread* send_command_thread_ = NULL;
6930 6958
6931 6959
6932 class SendCommandThread : public v8::base::Thread { 6960 class SendCommandThread : public v8::base::Thread {
6933 public: 6961 public:
6934 explicit SendCommandThread(v8::Isolate* isolate) 6962 explicit SendCommandThread(v8::Isolate* isolate)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6986 7014
6987 TEST(ProcessDebugMessagesThreaded) { 7015 TEST(ProcessDebugMessagesThreaded) {
6988 DebugLocalContext env; 7016 DebugLocalContext env;
6989 v8::Isolate* isolate = env->GetIsolate(); 7017 v8::Isolate* isolate = env->GetIsolate();
6990 v8::HandleScope scope(isolate); 7018 v8::HandleScope scope(isolate);
6991 v8::Local<v8::Context> context = env.context(); 7019 v8::Local<v8::Context> context = env.context();
6992 7020
6993 counting_message_handler_counter = 0; 7021 counting_message_handler_counter = 0;
6994 7022
6995 v8::Debug::SetMessageHandler( 7023 v8::Debug::SetMessageHandler(
6996 SendCommandThread::CountingAndSignallingMessageHandler); 7024 isolate, SendCommandThread::CountingAndSignallingMessageHandler);
6997 send_command_thread_ = new SendCommandThread(isolate); 7025 send_command_thread_ = new SendCommandThread(isolate);
6998 send_command_thread_->Start(); 7026 send_command_thread_->Start();
6999 7027
7000 v8::Local<v8::FunctionTemplate> start = 7028 v8::Local<v8::FunctionTemplate> start =
7001 v8::FunctionTemplate::New(isolate, StartSendingCommands); 7029 v8::FunctionTemplate::New(isolate, StartSendingCommands);
7002 CHECK(env->Global() 7030 CHECK(env->Global()
7003 ->Set(context, v8_str("start"), 7031 ->Set(context, v8_str("start"),
7004 start->GetFunction(context).ToLocalChecked()) 7032 start->GetFunction(context).ToLocalChecked())
7005 .FromJust()); 7033 .FromJust());
7006 7034
7007 CompileRun("start(); while (true) { }"); 7035 CompileRun("start(); while (true) { }");
7008 7036
7009 CHECK_EQ(20, counting_message_handler_counter); 7037 CHECK_EQ(20, counting_message_handler_counter);
7010 7038
7011 v8::Debug::SetMessageHandler(NULL); 7039 v8::Debug::SetMessageHandler(isolate, nullptr);
7012 CheckDebuggerUnloaded(); 7040 CheckDebuggerUnloaded(isolate);
7013 } 7041 }
7014 7042
7015 7043
7016 struct BacktraceData { 7044 struct BacktraceData {
7017 static int frame_counter; 7045 static int frame_counter;
7018 static void MessageHandler(const v8::Debug::Message& message) { 7046 static void MessageHandler(const v8::Debug::Message& message) {
7019 char print_buffer[1000]; 7047 char print_buffer[1000];
7020 v8::String::Value json(message.GetJSON()); 7048 v8::String::Value json(message.GetJSON());
7021 Utf16ToAscii(*json, json.length(), print_buffer, 1000); 7049 Utf16ToAscii(*json, json.length(), print_buffer, 1000);
7022 7050
7023 if (strstr(print_buffer, "backtrace") == NULL) { 7051 if (strstr(print_buffer, "backtrace") == NULL) {
7024 return; 7052 return;
7025 } 7053 }
7026 frame_counter = GetTotalFramesInt(print_buffer); 7054 frame_counter = GetTotalFramesInt(print_buffer);
7027 } 7055 }
7028 }; 7056 };
7029 7057
7030 int BacktraceData::frame_counter; 7058 int BacktraceData::frame_counter;
7031 7059
7032 7060
7033 // Test that debug messages get processed when ProcessDebugMessages is called. 7061 // Test that debug messages get processed when ProcessDebugMessages is called.
7034 TEST(Backtrace) { 7062 TEST(Backtrace) {
7035 DebugLocalContext env; 7063 DebugLocalContext env;
7036 v8::Isolate* isolate = env->GetIsolate(); 7064 v8::Isolate* isolate = env->GetIsolate();
7037 v8::HandleScope scope(isolate); 7065 v8::HandleScope scope(isolate);
7038 v8::Local<v8::Context> context = env.context(); 7066 v8::Local<v8::Context> context = env.context();
7039 7067
7040 v8::Debug::SetMessageHandler(BacktraceData::MessageHandler); 7068 v8::Debug::SetMessageHandler(isolate, BacktraceData::MessageHandler);
7041 7069
7042 const int kBufferSize = 1000; 7070 const int kBufferSize = 1000;
7043 uint16_t buffer[kBufferSize]; 7071 uint16_t buffer[kBufferSize];
7044 const char* scripts_command = 7072 const char* scripts_command =
7045 "{\"seq\":0," 7073 "{\"seq\":0,"
7046 "\"type\":\"request\"," 7074 "\"type\":\"request\","
7047 "\"command\":\"backtrace\"}"; 7075 "\"command\":\"backtrace\"}";
7048 7076
7049 // Check backtrace from ProcessDebugMessages. 7077 // Check backtrace from ProcessDebugMessages.
7050 BacktraceData::frame_counter = -10; 7078 BacktraceData::frame_counter = -10;
7051 v8::Debug::SendCommand( 7079 v8::Debug::SendCommand(
7052 isolate, 7080 isolate,
7053 buffer, 7081 buffer,
7054 AsciiToUtf16(scripts_command, buffer), 7082 AsciiToUtf16(scripts_command, buffer),
7055 NULL); 7083 NULL);
7056 v8::Debug::ProcessDebugMessages(); 7084 v8::Debug::ProcessDebugMessages(isolate);
7057 CHECK_EQ(BacktraceData::frame_counter, 0); 7085 CHECK_EQ(BacktraceData::frame_counter, 0);
7058 7086
7059 v8::Local<v8::String> void0 = v8_str(env->GetIsolate(), "void(0)"); 7087 v8::Local<v8::String> void0 = v8_str(env->GetIsolate(), "void(0)");
7060 v8::Local<v8::Script> script = CompileWithOrigin(void0, void0); 7088 v8::Local<v8::Script> script = CompileWithOrigin(void0, void0);
7061 7089
7062 // Check backtrace from "void(0)" script. 7090 // Check backtrace from "void(0)" script.
7063 BacktraceData::frame_counter = -10; 7091 BacktraceData::frame_counter = -10;
7064 v8::Debug::SendCommand( 7092 v8::Debug::SendCommand(
7065 isolate, 7093 isolate,
7066 buffer, 7094 buffer,
7067 AsciiToUtf16(scripts_command, buffer), 7095 AsciiToUtf16(scripts_command, buffer),
7068 NULL); 7096 NULL);
7069 script->Run(context).ToLocalChecked(); 7097 script->Run(context).ToLocalChecked();
7070 CHECK_EQ(BacktraceData::frame_counter, 1); 7098 CHECK_EQ(BacktraceData::frame_counter, 1);
7071 7099
7072 // Get rid of the debug message handler. 7100 // Get rid of the debug message handler.
7073 v8::Debug::SetMessageHandler(NULL); 7101 v8::Debug::SetMessageHandler(isolate, nullptr);
7074 CheckDebuggerUnloaded(); 7102 CheckDebuggerUnloaded(isolate);
7075 } 7103 }
7076 7104
7077 7105
7078 TEST(GetMirror) { 7106 TEST(GetMirror) {
7079 DebugLocalContext env; 7107 DebugLocalContext env;
7080 v8::Isolate* isolate = env->GetIsolate(); 7108 v8::Isolate* isolate = env->GetIsolate();
7081 v8::HandleScope scope(isolate); 7109 v8::HandleScope scope(isolate);
7082 v8::Local<v8::Context> context = env.context(); 7110 v8::Local<v8::Context> context = env.context();
7083 v8::Local<v8::Value> obj = 7111 v8::Local<v8::Value> obj =
7084 v8::Debug::GetMirror(context, v8_str(isolate, "hodja")).ToLocalChecked(); 7112 v8::Debug::GetMirror(context, v8_str(isolate, "hodja")).ToLocalChecked();
(...skipping 23 matching lines...) Expand all
7108 7136
7109 // Create a function for testing breaking in apply. 7137 // Create a function for testing breaking in apply.
7110 v8::Local<v8::Function> foo = CompileFunction( 7138 v8::Local<v8::Function> foo = CompileFunction(
7111 &env, 7139 &env,
7112 "function baz(x) { }" 7140 "function baz(x) { }"
7113 "function bar(x) { baz(); }" 7141 "function bar(x) { baz(); }"
7114 "function foo(){ bar.apply(this, [1]); }", 7142 "function foo(){ bar.apply(this, [1]); }",
7115 "foo"); 7143 "foo");
7116 7144
7117 // Register a debug event listener which steps and counts. 7145 // Register a debug event listener which steps and counts.
7118 v8::Debug::SetDebugEventListener(DebugEventBreakMax); 7146 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventBreakMax);
7119 7147
7120 // Set the debug break flag before calling the code using function.apply. 7148 // Set the debug break flag before calling the code using function.apply.
7121 v8::Debug::DebugBreak(env->GetIsolate()); 7149 v8::Debug::DebugBreak(env->GetIsolate());
7122 7150
7123 // Limit the number of debug breaks. This is a regression test for issue 493 7151 // Limit the number of debug breaks. This is a regression test for issue 493
7124 // where this test would enter an infinite loop. 7152 // where this test would enter an infinite loop.
7125 break_point_hit_count = 0; 7153 break_point_hit_count = 0;
7126 max_break_point_hit_count = 10000; // 10000 => infinite loop. 7154 max_break_point_hit_count = 10000; // 10000 => infinite loop.
7127 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 7155 foo->Call(context, env->Global(), 0, NULL).ToLocalChecked();
7128 7156
7129 // When keeping the debug break several break will happen. 7157 // When keeping the debug break several break will happen.
7130 CHECK_GT(break_point_hit_count, 1); 7158 CHECK_GT(break_point_hit_count, 1);
7131 7159
7132 v8::Debug::SetDebugEventListener(NULL); 7160 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7133 CheckDebuggerUnloaded(); 7161 CheckDebuggerUnloaded(env->GetIsolate());
7134 } 7162 }
7135 7163
7136 7164
7137 v8::Local<v8::Context> debugee_context; 7165 v8::Local<v8::Context> debugee_context;
7138 v8::Local<v8::Context> debugger_context; 7166 v8::Local<v8::Context> debugger_context;
7139 7167
7140 7168
7141 // Property getter that checks that current and calling contexts 7169 // Property getter that checks that current and calling contexts
7142 // are both the debugee contexts. 7170 // are both the debugee contexts.
7143 static void NamedGetterWithCallingContextCheck( 7171 static void NamedGetterWithCallingContextCheck(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7190 7218
7191 // Create object with 'a' property accessor. 7219 // Create object with 'a' property accessor.
7192 v8::Local<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate); 7220 v8::Local<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate);
7193 named->SetAccessor(v8_str(isolate, "a"), NamedGetterWithCallingContextCheck); 7221 named->SetAccessor(v8_str(isolate, "a"), NamedGetterWithCallingContextCheck);
7194 CHECK(env->Global() 7222 CHECK(env->Global()
7195 ->Set(debugee_context, v8_str(isolate, "obj"), 7223 ->Set(debugee_context, v8_str(isolate, "obj"),
7196 named->NewInstance(debugee_context).ToLocalChecked()) 7224 named->NewInstance(debugee_context).ToLocalChecked())
7197 .FromJust()); 7225 .FromJust());
7198 7226
7199 // Register the debug event listener 7227 // Register the debug event listener
7200 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue); 7228 v8::Debug::SetDebugEventListener(isolate, DebugEventGetAtgumentPropertyValue);
7201 7229
7202 // Create a function that invokes debugger. 7230 // Create a function that invokes debugger.
7203 v8::Local<v8::Function> foo = CompileFunction( 7231 v8::Local<v8::Function> foo = CompileFunction(
7204 &env, 7232 &env,
7205 "function bar(x) { debugger; }" 7233 "function bar(x) { debugger; }"
7206 "function foo(){ bar(obj); }", 7234 "function foo(){ bar(obj); }",
7207 "foo"); 7235 "foo");
7208 7236
7209 break_point_hit_count = 0; 7237 break_point_hit_count = 0;
7210 foo->Call(debugee_context, env->Global(), 0, NULL).ToLocalChecked(); 7238 foo->Call(debugee_context, env->Global(), 0, NULL).ToLocalChecked();
7211 CHECK_EQ(1, break_point_hit_count); 7239 CHECK_EQ(1, break_point_hit_count);
7212 7240
7213 v8::Debug::SetDebugEventListener(NULL); 7241 v8::Debug::SetDebugEventListener(isolate, nullptr);
7214 debugee_context = v8::Local<v8::Context>(); 7242 debugee_context = v8::Local<v8::Context>();
7215 debugger_context = v8::Local<v8::Context>(); 7243 debugger_context = v8::Local<v8::Context>();
7216 CheckDebuggerUnloaded(); 7244 CheckDebuggerUnloaded(isolate);
7217 } 7245 }
7218 7246
7219 7247
7220 TEST(DebugContextIsPreservedBetweenAccesses) { 7248 TEST(DebugContextIsPreservedBetweenAccesses) {
7221 v8::HandleScope scope(CcTest::isolate()); 7249 v8::HandleScope scope(CcTest::isolate());
7222 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); 7250 v8::Debug::SetDebugEventListener(CcTest::isolate(),
7223 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); 7251 DebugEventBreakPointHitCount);
7224 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); 7252 v8::Local<v8::Context> context1 =
7253 v8::Debug::GetDebugContext(CcTest::isolate());
7254 v8::Local<v8::Context> context2 =
7255 v8::Debug::GetDebugContext(CcTest::isolate());
7225 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to( 7256 CHECK(v8::Utils::OpenHandle(*context1).is_identical_to(
7226 v8::Utils::OpenHandle(*context2))); 7257 v8::Utils::OpenHandle(*context2)));
7227 v8::Debug::SetDebugEventListener(NULL); 7258 v8::Debug::SetDebugEventListener(CcTest::isolate(), nullptr);
7228 } 7259 }
7229 7260
7230 7261
7231 TEST(NoDebugContextWhenDebuggerDisabled) { 7262 TEST(NoDebugContextWhenDebuggerDisabled) {
7232 v8::HandleScope scope(CcTest::isolate()); 7263 v8::HandleScope scope(CcTest::isolate());
7233 v8::Local<v8::Context> context = v8::Debug::GetDebugContext(); 7264 v8::Local<v8::Context> context =
7265 v8::Debug::GetDebugContext(CcTest::isolate());
7234 CHECK(context.IsEmpty()); 7266 CHECK(context.IsEmpty());
7235 } 7267 }
7236 7268
7237 7269
7238 static v8::Local<v8::Value> expected_callback_data; 7270 static v8::Local<v8::Value> expected_callback_data;
7239 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { 7271 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
7240 CHECK(details.GetEventContext() == expected_context); 7272 CHECK(details.GetEventContext() == expected_context);
7241 CHECK(expected_callback_data->Equals(details.GetEventContext(), 7273 CHECK(expected_callback_data->Equals(details.GetEventContext(),
7242 details.GetCallbackData()) 7274 details.GetCallbackData())
7243 .FromJust()); 7275 .FromJust());
7244 } 7276 }
7245 7277
7246 7278
7247 // Check that event details contain context where debug event occured. 7279 // Check that event details contain context where debug event occured.
7248 TEST(DebugEventContext) { 7280 TEST(DebugEventContext) {
7249 v8::Isolate* isolate = CcTest::isolate(); 7281 v8::Isolate* isolate = CcTest::isolate();
7250 v8::HandleScope scope(isolate); 7282 v8::HandleScope scope(isolate);
7251 expected_context = v8::Context::New(isolate); 7283 expected_context = v8::Context::New(isolate);
7252 expected_callback_data = v8::Int32::New(isolate, 2010); 7284 expected_callback_data = v8::Int32::New(isolate, 2010);
7253 v8::Debug::SetDebugEventListener(DebugEventContextChecker, 7285 v8::Debug::SetDebugEventListener(isolate, DebugEventContextChecker,
7254 expected_callback_data); 7286 expected_callback_data);
7255 v8::Context::Scope context_scope(expected_context); 7287 v8::Context::Scope context_scope(expected_context);
7256 v8::Script::Compile(expected_context, 7288 v8::Script::Compile(expected_context,
7257 v8_str(isolate, "(function(){debugger;})();")) 7289 v8_str(isolate, "(function(){debugger;})();"))
7258 .ToLocalChecked() 7290 .ToLocalChecked()
7259 ->Run(expected_context) 7291 ->Run(expected_context)
7260 .ToLocalChecked(); 7292 .ToLocalChecked();
7261 expected_context.Clear(); 7293 expected_context.Clear();
7262 v8::Debug::SetDebugEventListener(NULL); 7294 v8::Debug::SetDebugEventListener(isolate, nullptr);
7263 expected_context_data = v8::Local<v8::Value>(); 7295 expected_context_data = v8::Local<v8::Value>();
7264 CheckDebuggerUnloaded(); 7296 CheckDebuggerUnloaded(isolate);
7265 } 7297 }
7266 7298
7267 7299
7268 static bool debug_event_break_deoptimize_done = false; 7300 static bool debug_event_break_deoptimize_done = false;
7269 7301
7270 static void DebugEventBreakDeoptimize( 7302 static void DebugEventBreakDeoptimize(
7271 const v8::Debug::EventDetails& event_details) { 7303 const v8::Debug::EventDetails& event_details) {
7272 v8::DebugEvent event = event_details.GetEvent(); 7304 v8::DebugEvent event = event_details.GetEvent();
7273 v8::Local<v8::Object> exec_state = event_details.GetExecutionState(); 7305 v8::Local<v8::Object> exec_state = event_details.GetExecutionState();
7274 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); 7306 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7310 // Create a function for checking the function when hitting a break point. 7342 // Create a function for checking the function when hitting a break point.
7311 frame_function_name = CompileFunction(&env, 7343 frame_function_name = CompileFunction(&env,
7312 frame_function_name_source, 7344 frame_function_name_source,
7313 "frame_function_name"); 7345 "frame_function_name");
7314 7346
7315 // Set a debug event listener which will keep interrupting execution until 7347 // Set a debug event listener which will keep interrupting execution until
7316 // debug break. When inside function bar it will deoptimize all functions. 7348 // debug break. When inside function bar it will deoptimize all functions.
7317 // This tests lazy deoptimization bailout for the stack check, as the first 7349 // This tests lazy deoptimization bailout for the stack check, as the first
7318 // time in function bar when using debug break and no break points will be at 7350 // time in function bar when using debug break and no break points will be at
7319 // the initial stack check. 7351 // the initial stack check.
7320 v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize); 7352 v8::Debug::SetDebugEventListener(env->GetIsolate(),
7353 DebugEventBreakDeoptimize);
7321 7354
7322 // Compile and run function bar which will optimize it for some flag settings. 7355 // Compile and run function bar which will optimize it for some flag settings.
7323 v8::Local<v8::Function> f = CompileFunction(&env, "function bar(){}", "bar"); 7356 v8::Local<v8::Function> f = CompileFunction(&env, "function bar(){}", "bar");
7324 f->Call(context, v8::Undefined(env->GetIsolate()), 0, NULL).ToLocalChecked(); 7357 f->Call(context, v8::Undefined(env->GetIsolate()), 0, NULL).ToLocalChecked();
7325 7358
7326 // Set debug break and call bar again. 7359 // Set debug break and call bar again.
7327 v8::Debug::DebugBreak(env->GetIsolate()); 7360 v8::Debug::DebugBreak(env->GetIsolate());
7328 f->Call(context, v8::Undefined(env->GetIsolate()), 0, NULL).ToLocalChecked(); 7361 f->Call(context, v8::Undefined(env->GetIsolate()), 0, NULL).ToLocalChecked();
7329 7362
7330 CHECK(debug_event_break_deoptimize_done); 7363 CHECK(debug_event_break_deoptimize_done);
7331 7364
7332 v8::Debug::SetDebugEventListener(NULL); 7365 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7333 } 7366 }
7334 7367
7335 7368
7336 static void DebugEventBreakWithOptimizedStack( 7369 static void DebugEventBreakWithOptimizedStack(
7337 const v8::Debug::EventDetails& event_details) { 7370 const v8::Debug::EventDetails& event_details) {
7338 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); 7371 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate();
7339 v8::DebugEvent event = event_details.GetEvent(); 7372 v8::DebugEvent event = event_details.GetEvent();
7340 v8::Local<v8::Object> exec_state = event_details.GetExecutionState(); 7373 v8::Local<v8::Object> exec_state = event_details.GetExecutionState();
7341 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 7374 v8::Local<v8::Context> context = isolate->GetCurrentContext();
7342 if (event == v8::Break) { 7375 if (event == v8::Break) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7389 .ToLocalChecked(); 7422 .ToLocalChecked();
7390 CHECK(result->IsUndefined() || 7423 CHECK(result->IsUndefined() ||
7391 (result->Int32Value(context).FromJust() == 42)); 7424 (result->Int32Value(context).FromJust() == 42));
7392 } 7425 }
7393 } 7426 }
7394 } 7427 }
7395 } 7428 }
7396 7429
7397 7430
7398 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { 7431 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
7399 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack); 7432 v8::Debug::SetDebugEventListener(args.GetIsolate(),
7433 DebugEventBreakWithOptimizedStack);
7400 v8::Debug::DebugBreak(args.GetIsolate()); 7434 v8::Debug::DebugBreak(args.GetIsolate());
7401 } 7435 }
7402 7436
7403 7437
7404 TEST(DebugBreakStackInspection) { 7438 TEST(DebugBreakStackInspection) {
7405 DebugLocalContext env; 7439 DebugLocalContext env;
7406 v8::HandleScope scope(env->GetIsolate()); 7440 v8::HandleScope scope(env->GetIsolate());
7407 v8::Local<v8::Context> context = env.context(); 7441 v8::Local<v8::Context> context = env.context();
7408 7442
7409 frame_function_name = 7443 frame_function_name =
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
7499 "switch (a) { case 1: continue; break; default: h() }", 7533 "switch (a) { case 1: continue; break; default: h() }",
7500 NULL}; 7534 NULL};
7501 7535
7502 7536
7503 void DebugBreakLoop(const char* loop_header, const char** loop_bodies, 7537 void DebugBreakLoop(const char* loop_header, const char** loop_bodies,
7504 const char* loop_footer) { 7538 const char* loop_footer) {
7505 DebugLocalContext env; 7539 DebugLocalContext env;
7506 v8::HandleScope scope(env->GetIsolate()); 7540 v8::HandleScope scope(env->GetIsolate());
7507 7541
7508 // Register a debug event listener which sets the break flag and counts. 7542 // Register a debug event listener which sets the break flag and counts.
7509 v8::Debug::SetDebugEventListener(DebugEventBreakMax); 7543 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventBreakMax);
7510 7544
7511 CompileRun( 7545 CompileRun(
7512 "var a = 1;\n" 7546 "var a = 1;\n"
7513 "function g() { }\n" 7547 "function g() { }\n"
7514 "function h() { }"); 7548 "function h() { }");
7515 7549
7516 TestDebugBreakInLoop(loop_header, loop_bodies, loop_footer); 7550 TestDebugBreakInLoop(loop_header, loop_bodies, loop_footer);
7517 7551
7518 // Get rid of the debug event listener. 7552 // Get rid of the debug event listener.
7519 v8::Debug::SetDebugEventListener(NULL); 7553 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7520 CheckDebuggerUnloaded(); 7554 CheckDebuggerUnloaded(env->GetIsolate());
7521 } 7555 }
7522 7556
7523 7557
7524 TEST(DebugBreakInWhileTrue1) { 7558 TEST(DebugBreakInWhileTrue1) {
7525 DebugBreakLoop("while (true) {", loop_bodies_1, "}"); 7559 DebugBreakLoop("while (true) {", loop_bodies_1, "}");
7526 } 7560 }
7527 7561
7528 7562
7529 TEST(DebugBreakInWhileTrue2) { 7563 TEST(DebugBreakInWhileTrue2) {
7530 DebugBreakLoop("while (true) {", loop_bodies_2, "}"); 7564 DebugBreakLoop("while (true) {", loop_bodies_2, "}");
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
7603 7637
7604 for (int i = 0; i < frame_count; i++) { 7638 for (int i = 0; i < frame_count; i++) {
7605 // The 5. element in the returned array of GetFrameDetails contains the 7639 // The 5. element in the returned array of GetFrameDetails contains the
7606 // source position of that frame. 7640 // source position of that frame.
7607 SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); 7641 SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
7608 v8::Local<v8::Value> result = CompileRun(script); 7642 v8::Local<v8::Value> result = CompileRun(script);
7609 CHECK_EQ(expected_line_number[i], 7643 CHECK_EQ(expected_line_number[i],
7610 i::Script::GetLineNumber(source_script, 7644 i::Script::GetLineNumber(source_script,
7611 result->Int32Value(context).FromJust())); 7645 result->Int32Value(context).FromJust()));
7612 } 7646 }
7613 v8::Debug::SetDebugEventListener(NULL); 7647 v8::Debug::SetDebugEventListener(CcTest::isolate(), nullptr);
7614 CcTest::isolate()->TerminateExecution(); 7648 CcTest::isolate()->TerminateExecution();
7615 } 7649 }
7616 7650
7617 7651
7618 TEST(DebugBreakInline) { 7652 TEST(DebugBreakInline) {
7619 i::FLAG_allow_natives_syntax = true; 7653 i::FLAG_allow_natives_syntax = true;
7620 DebugLocalContext env; 7654 DebugLocalContext env;
7621 v8::HandleScope scope(env->GetIsolate()); 7655 v8::HandleScope scope(env->GetIsolate());
7622 v8::Local<v8::Context> context = env.context(); 7656 v8::Local<v8::Context> context = env.context();
7623 const char* source = 7657 const char* source =
7624 "function debug(b) { \n" 7658 "function debug(b) { \n"
7625 " if (b) debugger; \n" 7659 " if (b) debugger; \n"
7626 "} \n" 7660 "} \n"
7627 "function f(b) { \n" 7661 "function f(b) { \n"
7628 " debug(b) \n" 7662 " debug(b) \n"
7629 "}; \n" 7663 "}; \n"
7630 "function g(b) { \n" 7664 "function g(b) { \n"
7631 " f(b); \n" 7665 " f(b); \n"
7632 "}; \n" 7666 "}; \n"
7633 "g(false); \n" 7667 "g(false); \n"
7634 "g(false); \n" 7668 "g(false); \n"
7635 "%OptimizeFunctionOnNextCall(g); \n" 7669 "%OptimizeFunctionOnNextCall(g); \n"
7636 "g(true);"; 7670 "g(true);";
7637 v8::Debug::SetDebugEventListener(DebugBreakInlineListener); 7671 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugBreakInlineListener);
7638 inline_script = 7672 inline_script =
7639 v8::Script::Compile(context, v8_str(env->GetIsolate(), source)) 7673 v8::Script::Compile(context, v8_str(env->GetIsolate(), source))
7640 .ToLocalChecked(); 7674 .ToLocalChecked();
7641 inline_script->Run(context).ToLocalChecked(); 7675 inline_script->Run(context).ToLocalChecked();
7642 } 7676 }
7643 7677
7644 7678
7645 static void DebugEventStepNext( 7679 static void DebugEventStepNext(
7646 const v8::Debug::EventDetails& event_details) { 7680 const v8::Debug::EventDetails& event_details) {
7647 v8::DebugEvent event = event_details.GetEvent(); 7681 v8::DebugEvent event = event_details.GetEvent();
(...skipping 14 matching lines...) Expand all
7662 // Bug description: 7696 // Bug description:
7663 // When doing StepNext through the first script, the debugger is not reset 7697 // When doing StepNext through the first script, the debugger is not reset
7664 // after exiting through exception. A flawed implementation enabling the 7698 // after exiting through exception. A flawed implementation enabling the
7665 // debugger to step into Array.prototype.forEach breaks inside the callback 7699 // debugger to step into Array.prototype.forEach breaks inside the callback
7666 // for forEach in the second script under the assumption that we are in a 7700 // for forEach in the second script under the assumption that we are in a
7667 // recursive call. In an attempt to step out, we crawl the stack using the 7701 // recursive call. In an attempt to step out, we crawl the stack using the
7668 // recorded frame pointer from the first script and fail when not finding it 7702 // recorded frame pointer from the first script and fail when not finding it
7669 // on the stack. 7703 // on the stack.
7670 DebugLocalContext env; 7704 DebugLocalContext env;
7671 v8::HandleScope scope(env->GetIsolate()); 7705 v8::HandleScope scope(env->GetIsolate());
7672 v8::Debug::SetDebugEventListener(DebugEventStepNext); 7706 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventStepNext);
7673 7707
7674 // We step through the first script. It exits through an exception. We run 7708 // We step through the first script. It exits through an exception. We run
7675 // this inside a new frame to record a different FP than the second script 7709 // this inside a new frame to record a different FP than the second script
7676 // would expect. 7710 // would expect.
7677 const char* script_1 = "debugger; throw new Error();"; 7711 const char* script_1 = "debugger; throw new Error();";
7678 RunScriptInANewCFrame(script_1); 7712 RunScriptInANewCFrame(script_1);
7679 7713
7680 // The second script uses forEach. 7714 // The second script uses forEach.
7681 const char* script_2 = "[0].forEach(function() { });"; 7715 const char* script_2 = "[0].forEach(function() { });";
7682 CompileRun(script_2); 7716 CompileRun(script_2);
7683 7717
7684 v8::Debug::SetDebugEventListener(NULL); 7718 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7685 } 7719 }
7686 7720
7687 7721
7688 // Import from test-heap.cc 7722 // Import from test-heap.cc
7689 namespace v8 { 7723 namespace v8 {
7690 namespace internal { 7724 namespace internal {
7691 7725
7692 int CountNativeContexts(); 7726 int CountNativeContexts();
7693 } 7727 }
7694 } 7728 }
7695 7729
7696 7730
7697 static void NopListener(const v8::Debug::EventDetails& event_details) { 7731 static void NopListener(const v8::Debug::EventDetails& event_details) {
7698 } 7732 }
7699 7733
7700 7734
7701 TEST(DebuggerCreatesContextIffActive) { 7735 TEST(DebuggerCreatesContextIffActive) {
7702 DebugLocalContext env; 7736 DebugLocalContext env;
7703 v8::HandleScope scope(env->GetIsolate()); 7737 v8::HandleScope scope(env->GetIsolate());
7704 CHECK_EQ(1, v8::internal::CountNativeContexts()); 7738 CHECK_EQ(1, v8::internal::CountNativeContexts());
7705 7739
7706 v8::Debug::SetDebugEventListener(NULL); 7740 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7707 CompileRun("debugger;"); 7741 CompileRun("debugger;");
7708 CHECK_EQ(1, v8::internal::CountNativeContexts()); 7742 CHECK_EQ(1, v8::internal::CountNativeContexts());
7709 7743
7710 v8::Debug::SetDebugEventListener(NopListener); 7744 v8::Debug::SetDebugEventListener(env->GetIsolate(), NopListener);
7711 CompileRun("debugger;"); 7745 CompileRun("debugger;");
7712 CHECK_EQ(2, v8::internal::CountNativeContexts()); 7746 CHECK_EQ(2, v8::internal::CountNativeContexts());
7713 7747
7714 v8::Debug::SetDebugEventListener(NULL); 7748 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7715 } 7749 }
7716 7750
7717 7751
7718 TEST(LiveEditEnabled) { 7752 TEST(LiveEditEnabled) {
7719 v8::internal::FLAG_allow_natives_syntax = true; 7753 v8::internal::FLAG_allow_natives_syntax = true;
7720 LocalContext env; 7754 LocalContext env;
7721 v8::HandleScope scope(env->GetIsolate()); 7755 v8::HandleScope scope(env->GetIsolate());
7722 v8::Debug::SetLiveEditEnabled(env->GetIsolate(), true); 7756 v8::Debug::SetLiveEditEnabled(env->GetIsolate(), true);
7723 CompileRun("%LiveEditCompareStrings('', '')"); 7757 CompileRun("%LiveEditCompareStrings('', '')");
7724 } 7758 }
7725 7759
7726 7760
7727 TEST(LiveEditDisabled) { 7761 TEST(LiveEditDisabled) {
7728 v8::internal::FLAG_allow_natives_syntax = true; 7762 v8::internal::FLAG_allow_natives_syntax = true;
7729 LocalContext env; 7763 LocalContext env;
7730 v8::HandleScope scope(env->GetIsolate()); 7764 v8::HandleScope scope(env->GetIsolate());
7731 v8::Debug::SetLiveEditEnabled(env->GetIsolate(), false); 7765 v8::Debug::SetLiveEditEnabled(env->GetIsolate(), false);
7732 CompileRun("%LiveEditCompareStrings('', '')"); 7766 CompileRun("%LiveEditCompareStrings('', '')");
7733 } 7767 }
7734 7768
7735 7769
7736 TEST(PrecompiledFunction) { 7770 TEST(PrecompiledFunction) {
7737 // Regression test for crbug.com/346207. If we have preparse data, parsing the 7771 // Regression test for crbug.com/346207. If we have preparse data, parsing the
7738 // function in the presence of the debugger (and breakpoints) should still 7772 // function in the presence of the debugger (and breakpoints) should still
7739 // succeed. The bug was that preparsing was done lazily and parsing was done 7773 // succeed. The bug was that preparsing was done lazily and parsing was done
7740 // eagerly, so, the symbol streams didn't match. 7774 // eagerly, so, the symbol streams didn't match.
7741 DebugLocalContext env; 7775 DebugLocalContext env;
7742 v8::HandleScope scope(env->GetIsolate()); 7776 v8::HandleScope scope(env->GetIsolate());
7743 env.ExposeDebug(); 7777 env.ExposeDebug();
7744 v8::Debug::SetDebugEventListener(DebugBreakInlineListener); 7778 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugBreakInlineListener);
7745 7779
7746 v8::Local<v8::Function> break_here = 7780 v8::Local<v8::Function> break_here =
7747 CompileFunction(&env, "function break_here(){}", "break_here"); 7781 CompileFunction(&env, "function break_here(){}", "break_here");
7748 SetBreakPoint(break_here, 0); 7782 SetBreakPoint(break_here, 0);
7749 7783
7750 const char* source = 7784 const char* source =
7751 "var a = b = c = 1; \n" 7785 "var a = b = c = 1; \n"
7752 "function this_is_lazy() { \n" 7786 "function this_is_lazy() { \n"
7753 // This symbol won't appear in the preparse data. 7787 // This symbol won't appear in the preparse data.
7754 " var a; \n" 7788 " var a; \n"
7755 "} \n" 7789 "} \n"
7756 "function bar() { \n" 7790 "function bar() { \n"
7757 " return \"bar\"; \n" 7791 " return \"bar\"; \n"
7758 "}; \n" 7792 "}; \n"
7759 "a = b = c = 2; \n" 7793 "a = b = c = 2; \n"
7760 "bar(); \n"; 7794 "bar(); \n";
7761 v8::Local<v8::Value> result = ParserCacheCompileRun(source); 7795 v8::Local<v8::Value> result = ParserCacheCompileRun(source);
7762 CHECK(result->IsString()); 7796 CHECK(result->IsString());
7763 v8::String::Utf8Value utf8(result); 7797 v8::String::Utf8Value utf8(result);
7764 CHECK_EQ(0, strcmp("bar", *utf8)); 7798 CHECK_EQ(0, strcmp("bar", *utf8));
7765 7799
7766 v8::Debug::SetDebugEventListener(NULL); 7800 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
7767 CheckDebuggerUnloaded(); 7801 CheckDebuggerUnloaded(env->GetIsolate());
7768 } 7802 }
7769 7803
7770 7804
7771 static void DebugBreakStackTraceListener( 7805 static void DebugBreakStackTraceListener(
7772 const v8::Debug::EventDetails& event_details) { 7806 const v8::Debug::EventDetails& event_details) {
7773 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); 7807 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10);
7774 } 7808 }
7775 7809
7776 7810
7777 static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { 7811 static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
7778 v8::Debug::DebugBreak(args.GetIsolate()); 7812 v8::Debug::DebugBreak(args.GetIsolate());
7779 } 7813 }
7780 7814
7781 7815
7782 TEST(DebugBreakStackTrace) { 7816 TEST(DebugBreakStackTrace) {
7783 DebugLocalContext env; 7817 DebugLocalContext env;
7784 v8::HandleScope scope(env->GetIsolate()); 7818 v8::HandleScope scope(env->GetIsolate());
7785 v8::Debug::SetDebugEventListener(DebugBreakStackTraceListener); 7819 v8::Debug::SetDebugEventListener(env->GetIsolate(),
7820 DebugBreakStackTraceListener);
7786 v8::Local<v8::Context> context = env.context(); 7821 v8::Local<v8::Context> context = env.context();
7787 v8::Local<v8::FunctionTemplate> add_debug_break_template = 7822 v8::Local<v8::FunctionTemplate> add_debug_break_template =
7788 v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak); 7823 v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak);
7789 v8::Local<v8::Function> add_debug_break = 7824 v8::Local<v8::Function> add_debug_break =
7790 add_debug_break_template->GetFunction(context).ToLocalChecked(); 7825 add_debug_break_template->GetFunction(context).ToLocalChecked();
7791 CHECK(env->Global() 7826 CHECK(env->Global()
7792 ->Set(context, v8_str("add_debug_break"), add_debug_break) 7827 ->Set(context, v8_str("add_debug_break"), add_debug_break)
7793 .FromJust()); 7828 .FromJust());
7794 7829
7795 CompileRun("(function loop() {" 7830 CompileRun("(function loop() {"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
7830 7865
7831 private: 7866 private:
7832 v8::Isolate* isolate_; 7867 v8::Isolate* isolate_;
7833 }; 7868 };
7834 7869
7835 7870
7836 TEST(DebugBreakOffThreadTerminate) { 7871 TEST(DebugBreakOffThreadTerminate) {
7837 DebugLocalContext env; 7872 DebugLocalContext env;
7838 v8::Isolate* isolate = env->GetIsolate(); 7873 v8::Isolate* isolate = env->GetIsolate();
7839 v8::HandleScope scope(isolate); 7874 v8::HandleScope scope(isolate);
7840 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); 7875 v8::Debug::SetDebugEventListener(isolate, DebugBreakTriggerTerminate);
7841 TerminationThread terminator(isolate); 7876 TerminationThread terminator(isolate);
7842 terminator.Start(); 7877 terminator.Start();
7843 v8::TryCatch try_catch(env->GetIsolate()); 7878 v8::TryCatch try_catch(env->GetIsolate());
7844 v8::Debug::DebugBreak(isolate); 7879 v8::Debug::DebugBreak(isolate);
7845 CompileRun("while (true);"); 7880 CompileRun("while (true);");
7846 CHECK(try_catch.HasTerminated()); 7881 CHECK(try_catch.HasTerminated());
7847 } 7882 }
7848 7883
7849 7884
7850 static void DebugEventExpectNoException( 7885 static void DebugEventExpectNoException(
7851 const v8::Debug::EventDetails& event_details) { 7886 const v8::Debug::EventDetails& event_details) {
7852 v8::DebugEvent event = event_details.GetEvent(); 7887 v8::DebugEvent event = event_details.GetEvent();
7853 CHECK_NE(v8::Exception, event); 7888 CHECK_NE(v8::Exception, event);
7854 } 7889 }
7855 7890
7856 7891
7857 static void TryCatchWrappedThrowCallback( 7892 static void TryCatchWrappedThrowCallback(
7858 const v8::FunctionCallbackInfo<v8::Value>& args) { 7893 const v8::FunctionCallbackInfo<v8::Value>& args) {
7859 v8::TryCatch try_catch(args.GetIsolate()); 7894 v8::TryCatch try_catch(args.GetIsolate());
7860 CompileRun("throw 'rejection';"); 7895 CompileRun("throw 'rejection';");
7861 CHECK(try_catch.HasCaught()); 7896 CHECK(try_catch.HasCaught());
7862 } 7897 }
7863 7898
7864 7899
7865 TEST(DebugPromiseInterceptedByTryCatch) { 7900 TEST(DebugPromiseInterceptedByTryCatch) {
7866 DebugLocalContext env; 7901 DebugLocalContext env;
7867 v8::Isolate* isolate = env->GetIsolate(); 7902 v8::Isolate* isolate = env->GetIsolate();
7868 v8::HandleScope scope(isolate); 7903 v8::HandleScope scope(isolate);
7869 v8::Debug::SetDebugEventListener(&DebugEventExpectNoException); 7904 v8::Debug::SetDebugEventListener(isolate, &DebugEventExpectNoException);
7870 v8::Local<v8::Context> context = env.context(); 7905 v8::Local<v8::Context> context = env.context();
7871 ChangeBreakOnException(false, true); 7906 ChangeBreakOnException(false, true);
7872 7907
7873 v8::Local<v8::FunctionTemplate> fun = 7908 v8::Local<v8::FunctionTemplate> fun =
7874 v8::FunctionTemplate::New(isolate, TryCatchWrappedThrowCallback); 7909 v8::FunctionTemplate::New(isolate, TryCatchWrappedThrowCallback);
7875 CHECK(env->Global() 7910 CHECK(env->Global()
7876 ->Set(context, v8_str("fun"), 7911 ->Set(context, v8_str("fun"),
7877 fun->GetFunction(context).ToLocalChecked()) 7912 fun->GetFunction(context).ToLocalChecked())
7878 .FromJust()); 7913 .FromJust());
7879 7914
(...skipping 18 matching lines...) Expand all
7898 7933
7899 static void ThrowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 7934 static void ThrowCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
7900 CompileRun("throw 'rejection';"); 7935 CompileRun("throw 'rejection';");
7901 } 7936 }
7902 7937
7903 7938
7904 TEST(DebugPromiseRejectedByCallback) { 7939 TEST(DebugPromiseRejectedByCallback) {
7905 DebugLocalContext env; 7940 DebugLocalContext env;
7906 v8::Isolate* isolate = env->GetIsolate(); 7941 v8::Isolate* isolate = env->GetIsolate();
7907 v8::HandleScope scope(isolate); 7942 v8::HandleScope scope(isolate);
7908 v8::Debug::SetDebugEventListener(&DebugEventCountException); 7943 v8::Debug::SetDebugEventListener(isolate, &DebugEventCountException);
7909 v8::Local<v8::Context> context = env.context(); 7944 v8::Local<v8::Context> context = env.context();
7910 ChangeBreakOnException(false, true); 7945 ChangeBreakOnException(false, true);
7911 exception_event_counter = 0; 7946 exception_event_counter = 0;
7912 7947
7913 v8::Local<v8::FunctionTemplate> fun = 7948 v8::Local<v8::FunctionTemplate> fun =
7914 v8::FunctionTemplate::New(isolate, ThrowCallback); 7949 v8::FunctionTemplate::New(isolate, ThrowCallback);
7915 CHECK(env->Global() 7950 CHECK(env->Global()
7916 ->Set(context, v8_str("fun"), 7951 ->Set(context, v8_str("fun"),
7917 fun->GetFunction(context).ToLocalChecked()) 7952 fun->GetFunction(context).ToLocalChecked())
7918 .FromJust()); 7953 .FromJust());
7919 7954
7920 CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });"); 7955 CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });");
7921 CompileRun( 7956 CompileRun(
7922 "var r;" 7957 "var r;"
7923 "p.chain(function() { r = 'resolved'; }," 7958 "p.chain(function() { r = 'resolved'; },"
7924 " function(e) { r = 'rejected' + e; });"); 7959 " function(e) { r = 'rejected' + e; });");
7925 CHECK( 7960 CHECK(
7926 CompileRun("r")->Equals(context, v8_str("rejectedrejection")).FromJust()); 7961 CompileRun("r")->Equals(context, v8_str("rejectedrejection")).FromJust());
7927 CHECK_EQ(1, exception_event_counter); 7962 CHECK_EQ(1, exception_event_counter);
7928 } 7963 }
7929 7964
7930 7965
7931 TEST(DebugBreakOnExceptionInObserveCallback) { 7966 TEST(DebugBreakOnExceptionInObserveCallback) {
7932 DebugLocalContext env; 7967 DebugLocalContext env;
7933 v8::Isolate* isolate = env->GetIsolate(); 7968 v8::Isolate* isolate = env->GetIsolate();
7934 v8::HandleScope scope(isolate); 7969 v8::HandleScope scope(isolate);
7935 v8::Debug::SetDebugEventListener(&DebugEventCountException); 7970 v8::Debug::SetDebugEventListener(isolate, &DebugEventCountException);
7936 v8::Local<v8::Context> context = env.context(); 7971 v8::Local<v8::Context> context = env.context();
7937 // Break on uncaught exception 7972 // Break on uncaught exception
7938 ChangeBreakOnException(false, true); 7973 ChangeBreakOnException(false, true);
7939 exception_event_counter = 0; 7974 exception_event_counter = 0;
7940 7975
7941 v8::Local<v8::FunctionTemplate> fun = 7976 v8::Local<v8::FunctionTemplate> fun =
7942 v8::FunctionTemplate::New(isolate, ThrowCallback); 7977 v8::FunctionTemplate::New(isolate, ThrowCallback);
7943 CHECK(env->Global() 7978 CHECK(env->Global()
7944 ->Set(context, v8_str("fun"), 7979 ->Set(context, v8_str("fun"),
7945 fun->GetFunction(context).ToLocalChecked()) 7980 fun->GetFunction(context).ToLocalChecked())
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
7989 ExpectInt32("frame.evaluate('x + y').value_", 11); 8024 ExpectInt32("frame.evaluate('x + y').value_", 11);
7990 } 8025 }
7991 8026
7992 8027
7993 TEST(DebugBreakInLexicalScopes) { 8028 TEST(DebugBreakInLexicalScopes) {
7994 i::FLAG_allow_natives_syntax = true; 8029 i::FLAG_allow_natives_syntax = true;
7995 8030
7996 DebugLocalContext env; 8031 DebugLocalContext env;
7997 v8::Isolate* isolate = env->GetIsolate(); 8032 v8::Isolate* isolate = env->GetIsolate();
7998 v8::HandleScope scope(isolate); 8033 v8::HandleScope scope(isolate);
7999 v8::Debug::SetDebugEventListener(DebugHarmonyScopingListener); 8034 v8::Debug::SetDebugEventListener(isolate, DebugHarmonyScopingListener);
8000 8035
8001 CompileRun( 8036 CompileRun(
8002 "'use strict'; \n" 8037 "'use strict'; \n"
8003 "let x = 1; \n"); 8038 "let x = 1; \n");
8004 ExpectInt32( 8039 ExpectInt32(
8005 "'use strict'; \n" 8040 "'use strict'; \n"
8006 "let y = 2; \n" 8041 "let y = 2; \n"
8007 "debugger; \n" 8042 "debugger; \n"
8008 "x * y", 8043 "x * y",
8009 30); 8044 30);
(...skipping 17 matching lines...) Expand all
8027 CHECK(after_compile_handler_depth <= 1); 8062 CHECK(after_compile_handler_depth <= 1);
8028 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); 8063 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate();
8029 isolate->RequestInterrupt(&HandleInterrupt, nullptr); 8064 isolate->RequestInterrupt(&HandleInterrupt, nullptr);
8030 CompileRun("function foo() {}; foo();"); 8065 CompileRun("function foo() {}; foo();");
8031 --after_compile_handler_depth; 8066 --after_compile_handler_depth;
8032 } 8067 }
8033 8068
8034 8069
8035 TEST(NoInterruptsInDebugListener) { 8070 TEST(NoInterruptsInDebugListener) {
8036 DebugLocalContext env; 8071 DebugLocalContext env;
8037 v8::Debug::SetDebugEventListener(NoInterruptsOnDebugEvent); 8072 v8::Debug::SetDebugEventListener(env->GetIsolate(), NoInterruptsOnDebugEvent);
8038 CompileRun("void(0);"); 8073 CompileRun("void(0);");
8039 } 8074 }
OLDNEW
« src/api.cc ('K') | « test/cctest/test-api.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698