OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 CHECK(!HasDebugInfo(bar)); | 1087 CHECK(!HasDebugInfo(bar)); |
1088 } | 1088 } |
1089 | 1089 |
1090 | 1090 |
1091 // Test that a break point can be set at an IC store location. | 1091 // Test that a break point can be set at an IC store location. |
1092 TEST(BreakPointICStore) { | 1092 TEST(BreakPointICStore) { |
1093 break_point_hit_count = 0; | 1093 break_point_hit_count = 0; |
1094 DebugLocalContext env; | 1094 DebugLocalContext env; |
1095 v8::HandleScope scope(env->GetIsolate()); | 1095 v8::HandleScope scope(env->GetIsolate()); |
1096 | 1096 |
1097 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1097 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1098 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1098 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1099 "function foo(){bar=0;}"))->Run(); | 1099 "function foo(){bar=0;}"))->Run(); |
1100 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1100 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1101 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1101 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1102 | 1102 |
1103 // Run without breakpoints. | 1103 // Run without breakpoints. |
1104 foo->Call(env->Global(), 0, NULL); | 1104 foo->Call(env->Global(), 0, NULL); |
1105 CHECK_EQ(0, break_point_hit_count); | 1105 CHECK_EQ(0, break_point_hit_count); |
1106 | 1106 |
1107 // Run with breakpoint | 1107 // Run with breakpoint |
1108 int bp = SetBreakPoint(foo, 0); | 1108 int bp = SetBreakPoint(foo, 0); |
1109 foo->Call(env->Global(), 0, NULL); | 1109 foo->Call(env->Global(), 0, NULL); |
1110 CHECK_EQ(1, break_point_hit_count); | 1110 CHECK_EQ(1, break_point_hit_count); |
1111 foo->Call(env->Global(), 0, NULL); | 1111 foo->Call(env->Global(), 0, NULL); |
1112 CHECK_EQ(2, break_point_hit_count); | 1112 CHECK_EQ(2, break_point_hit_count); |
1113 | 1113 |
1114 // Run without breakpoints. | 1114 // Run without breakpoints. |
1115 ClearBreakPoint(bp); | 1115 ClearBreakPoint(bp); |
1116 foo->Call(env->Global(), 0, NULL); | 1116 foo->Call(env->Global(), 0, NULL); |
1117 CHECK_EQ(2, break_point_hit_count); | 1117 CHECK_EQ(2, break_point_hit_count); |
1118 | 1118 |
1119 v8::Debug::SetDebugEventListener2(NULL); | 1119 v8::Debug::SetDebugEventListener(NULL); |
1120 CheckDebuggerUnloaded(); | 1120 CheckDebuggerUnloaded(); |
1121 } | 1121 } |
1122 | 1122 |
1123 | 1123 |
1124 // Test that a break point can be set at an IC load location. | 1124 // Test that a break point can be set at an IC load location. |
1125 TEST(BreakPointICLoad) { | 1125 TEST(BreakPointICLoad) { |
1126 break_point_hit_count = 0; | 1126 break_point_hit_count = 0; |
1127 DebugLocalContext env; | 1127 DebugLocalContext env; |
1128 v8::HandleScope scope(env->GetIsolate()); | 1128 v8::HandleScope scope(env->GetIsolate()); |
1129 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1129 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1130 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar=1")) | 1130 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar=1")) |
1131 ->Run(); | 1131 ->Run(); |
1132 v8::Script::Compile( | 1132 v8::Script::Compile( |
1133 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){var x=bar;}")) | 1133 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){var x=bar;}")) |
1134 ->Run(); | 1134 ->Run(); |
1135 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1135 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1136 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1136 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1137 | 1137 |
1138 // Run without breakpoints. | 1138 // Run without breakpoints. |
1139 foo->Call(env->Global(), 0, NULL); | 1139 foo->Call(env->Global(), 0, NULL); |
1140 CHECK_EQ(0, break_point_hit_count); | 1140 CHECK_EQ(0, break_point_hit_count); |
1141 | 1141 |
1142 // Run with breakpoint. | 1142 // Run with breakpoint. |
1143 int bp = SetBreakPoint(foo, 0); | 1143 int bp = SetBreakPoint(foo, 0); |
1144 foo->Call(env->Global(), 0, NULL); | 1144 foo->Call(env->Global(), 0, NULL); |
1145 CHECK_EQ(1, break_point_hit_count); | 1145 CHECK_EQ(1, break_point_hit_count); |
1146 foo->Call(env->Global(), 0, NULL); | 1146 foo->Call(env->Global(), 0, NULL); |
1147 CHECK_EQ(2, break_point_hit_count); | 1147 CHECK_EQ(2, break_point_hit_count); |
1148 | 1148 |
1149 // Run without breakpoints. | 1149 // Run without breakpoints. |
1150 ClearBreakPoint(bp); | 1150 ClearBreakPoint(bp); |
1151 foo->Call(env->Global(), 0, NULL); | 1151 foo->Call(env->Global(), 0, NULL); |
1152 CHECK_EQ(2, break_point_hit_count); | 1152 CHECK_EQ(2, break_point_hit_count); |
1153 | 1153 |
1154 v8::Debug::SetDebugEventListener2(NULL); | 1154 v8::Debug::SetDebugEventListener(NULL); |
1155 CheckDebuggerUnloaded(); | 1155 CheckDebuggerUnloaded(); |
1156 } | 1156 } |
1157 | 1157 |
1158 | 1158 |
1159 // Test that a break point can be set at an IC call location. | 1159 // Test that a break point can be set at an IC call location. |
1160 TEST(BreakPointICCall) { | 1160 TEST(BreakPointICCall) { |
1161 break_point_hit_count = 0; | 1161 break_point_hit_count = 0; |
1162 DebugLocalContext env; | 1162 DebugLocalContext env; |
1163 v8::HandleScope scope(env->GetIsolate()); | 1163 v8::HandleScope scope(env->GetIsolate()); |
1164 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1164 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1165 v8::Script::Compile( | 1165 v8::Script::Compile( |
1166 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run(); | 1166 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run(); |
1167 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1167 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1168 "function foo(){bar();}"))->Run(); | 1168 "function foo(){bar();}"))->Run(); |
1169 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1169 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1170 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1170 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1171 | 1171 |
1172 // Run without breakpoints. | 1172 // Run without breakpoints. |
1173 foo->Call(env->Global(), 0, NULL); | 1173 foo->Call(env->Global(), 0, NULL); |
1174 CHECK_EQ(0, break_point_hit_count); | 1174 CHECK_EQ(0, break_point_hit_count); |
1175 | 1175 |
1176 // Run with breakpoint | 1176 // Run with breakpoint |
1177 int bp = SetBreakPoint(foo, 0); | 1177 int bp = SetBreakPoint(foo, 0); |
1178 foo->Call(env->Global(), 0, NULL); | 1178 foo->Call(env->Global(), 0, NULL); |
1179 CHECK_EQ(1, break_point_hit_count); | 1179 CHECK_EQ(1, break_point_hit_count); |
1180 foo->Call(env->Global(), 0, NULL); | 1180 foo->Call(env->Global(), 0, NULL); |
1181 CHECK_EQ(2, break_point_hit_count); | 1181 CHECK_EQ(2, break_point_hit_count); |
1182 | 1182 |
1183 // Run without breakpoints. | 1183 // Run without breakpoints. |
1184 ClearBreakPoint(bp); | 1184 ClearBreakPoint(bp); |
1185 foo->Call(env->Global(), 0, NULL); | 1185 foo->Call(env->Global(), 0, NULL); |
1186 CHECK_EQ(2, break_point_hit_count); | 1186 CHECK_EQ(2, break_point_hit_count); |
1187 | 1187 |
1188 v8::Debug::SetDebugEventListener2(NULL); | 1188 v8::Debug::SetDebugEventListener(NULL); |
1189 CheckDebuggerUnloaded(); | 1189 CheckDebuggerUnloaded(); |
1190 } | 1190 } |
1191 | 1191 |
1192 | 1192 |
1193 // Test that a break point can be set at an IC call location and survive a GC. | 1193 // Test that a break point can be set at an IC call location and survive a GC. |
1194 TEST(BreakPointICCallWithGC) { | 1194 TEST(BreakPointICCallWithGC) { |
1195 break_point_hit_count = 0; | 1195 break_point_hit_count = 0; |
1196 DebugLocalContext env; | 1196 DebugLocalContext env; |
1197 v8::HandleScope scope(env->GetIsolate()); | 1197 v8::HandleScope scope(env->GetIsolate()); |
1198 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); | 1198 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); |
1199 v8::Script::Compile( | 1199 v8::Script::Compile( |
1200 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){return 1;}")) | 1200 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){return 1;}")) |
1201 ->Run(); | 1201 ->Run(); |
1202 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1202 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1203 "function foo(){return bar();}")) | 1203 "function foo(){return bar();}")) |
1204 ->Run(); | 1204 ->Run(); |
1205 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1205 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1206 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1206 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1207 | 1207 |
1208 // Run without breakpoints. | 1208 // Run without breakpoints. |
1209 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1209 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1210 CHECK_EQ(0, break_point_hit_count); | 1210 CHECK_EQ(0, break_point_hit_count); |
1211 | 1211 |
1212 // Run with breakpoint. | 1212 // Run with breakpoint. |
1213 int bp = SetBreakPoint(foo, 0); | 1213 int bp = SetBreakPoint(foo, 0); |
1214 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1214 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1215 CHECK_EQ(1, break_point_hit_count); | 1215 CHECK_EQ(1, break_point_hit_count); |
1216 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1216 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1217 CHECK_EQ(2, break_point_hit_count); | 1217 CHECK_EQ(2, break_point_hit_count); |
1218 | 1218 |
1219 // Run without breakpoints. | 1219 // Run without breakpoints. |
1220 ClearBreakPoint(bp); | 1220 ClearBreakPoint(bp); |
1221 foo->Call(env->Global(), 0, NULL); | 1221 foo->Call(env->Global(), 0, NULL); |
1222 CHECK_EQ(2, break_point_hit_count); | 1222 CHECK_EQ(2, break_point_hit_count); |
1223 | 1223 |
1224 v8::Debug::SetDebugEventListener2(NULL); | 1224 v8::Debug::SetDebugEventListener(NULL); |
1225 CheckDebuggerUnloaded(); | 1225 CheckDebuggerUnloaded(); |
1226 } | 1226 } |
1227 | 1227 |
1228 | 1228 |
1229 // Test that a break point can be set at an IC call location and survive a GC. | 1229 // Test that a break point can be set at an IC call location and survive a GC. |
1230 TEST(BreakPointConstructCallWithGC) { | 1230 TEST(BreakPointConstructCallWithGC) { |
1231 break_point_hit_count = 0; | 1231 break_point_hit_count = 0; |
1232 DebugLocalContext env; | 1232 DebugLocalContext env; |
1233 v8::HandleScope scope(env->GetIsolate()); | 1233 v8::HandleScope scope(env->GetIsolate()); |
1234 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); | 1234 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); |
1235 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1235 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1236 "function bar(){ this.x = 1;}")) | 1236 "function bar(){ this.x = 1;}")) |
1237 ->Run(); | 1237 ->Run(); |
1238 v8::Script::Compile( | 1238 v8::Script::Compile( |
1239 v8::String::NewFromUtf8(env->GetIsolate(), | 1239 v8::String::NewFromUtf8(env->GetIsolate(), |
1240 "function foo(){return new bar(1).x;}"))->Run(); | 1240 "function foo(){return new bar(1).x;}"))->Run(); |
1241 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1241 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1242 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1242 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1243 | 1243 |
1244 // Run without breakpoints. | 1244 // Run without breakpoints. |
1245 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1245 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1246 CHECK_EQ(0, break_point_hit_count); | 1246 CHECK_EQ(0, break_point_hit_count); |
1247 | 1247 |
1248 // Run with breakpoint. | 1248 // Run with breakpoint. |
1249 int bp = SetBreakPoint(foo, 0); | 1249 int bp = SetBreakPoint(foo, 0); |
1250 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1250 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1251 CHECK_EQ(1, break_point_hit_count); | 1251 CHECK_EQ(1, break_point_hit_count); |
1252 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); | 1252 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); |
1253 CHECK_EQ(2, break_point_hit_count); | 1253 CHECK_EQ(2, break_point_hit_count); |
1254 | 1254 |
1255 // Run without breakpoints. | 1255 // Run without breakpoints. |
1256 ClearBreakPoint(bp); | 1256 ClearBreakPoint(bp); |
1257 foo->Call(env->Global(), 0, NULL); | 1257 foo->Call(env->Global(), 0, NULL); |
1258 CHECK_EQ(2, break_point_hit_count); | 1258 CHECK_EQ(2, break_point_hit_count); |
1259 | 1259 |
1260 v8::Debug::SetDebugEventListener2(NULL); | 1260 v8::Debug::SetDebugEventListener(NULL); |
1261 CheckDebuggerUnloaded(); | 1261 CheckDebuggerUnloaded(); |
1262 } | 1262 } |
1263 | 1263 |
1264 | 1264 |
1265 // Test that a break point can be set at a return store location. | 1265 // Test that a break point can be set at a return store location. |
1266 TEST(BreakPointReturn) { | 1266 TEST(BreakPointReturn) { |
1267 break_point_hit_count = 0; | 1267 break_point_hit_count = 0; |
1268 DebugLocalContext env; | 1268 DebugLocalContext env; |
1269 v8::HandleScope scope(env->GetIsolate()); | 1269 v8::HandleScope scope(env->GetIsolate()); |
1270 | 1270 |
1271 // Create a functions for checking the source line and column when hitting | 1271 // Create a functions for checking the source line and column when hitting |
1272 // a break point. | 1272 // a break point. |
1273 frame_source_line = CompileFunction(&env, | 1273 frame_source_line = CompileFunction(&env, |
1274 frame_source_line_source, | 1274 frame_source_line_source, |
1275 "frame_source_line"); | 1275 "frame_source_line"); |
1276 frame_source_column = CompileFunction(&env, | 1276 frame_source_column = CompileFunction(&env, |
1277 frame_source_column_source, | 1277 frame_source_column_source, |
1278 "frame_source_column"); | 1278 "frame_source_column"); |
1279 | 1279 |
1280 | 1280 |
1281 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1281 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1282 v8::Script::Compile( | 1282 v8::Script::Compile( |
1283 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){}"))->Run(); | 1283 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){}"))->Run(); |
1284 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 1284 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
1285 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 1285 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
1286 | 1286 |
1287 // Run without breakpoints. | 1287 // Run without breakpoints. |
1288 foo->Call(env->Global(), 0, NULL); | 1288 foo->Call(env->Global(), 0, NULL); |
1289 CHECK_EQ(0, break_point_hit_count); | 1289 CHECK_EQ(0, break_point_hit_count); |
1290 | 1290 |
1291 // Run with breakpoint | 1291 // Run with breakpoint |
1292 int bp = SetBreakPoint(foo, 0); | 1292 int bp = SetBreakPoint(foo, 0); |
1293 foo->Call(env->Global(), 0, NULL); | 1293 foo->Call(env->Global(), 0, NULL); |
1294 CHECK_EQ(1, break_point_hit_count); | 1294 CHECK_EQ(1, break_point_hit_count); |
1295 CHECK_EQ(0, last_source_line); | 1295 CHECK_EQ(0, last_source_line); |
1296 CHECK_EQ(15, last_source_column); | 1296 CHECK_EQ(15, last_source_column); |
1297 foo->Call(env->Global(), 0, NULL); | 1297 foo->Call(env->Global(), 0, NULL); |
1298 CHECK_EQ(2, break_point_hit_count); | 1298 CHECK_EQ(2, break_point_hit_count); |
1299 CHECK_EQ(0, last_source_line); | 1299 CHECK_EQ(0, last_source_line); |
1300 CHECK_EQ(15, last_source_column); | 1300 CHECK_EQ(15, last_source_column); |
1301 | 1301 |
1302 // Run without breakpoints. | 1302 // Run without breakpoints. |
1303 ClearBreakPoint(bp); | 1303 ClearBreakPoint(bp); |
1304 foo->Call(env->Global(), 0, NULL); | 1304 foo->Call(env->Global(), 0, NULL); |
1305 CHECK_EQ(2, break_point_hit_count); | 1305 CHECK_EQ(2, break_point_hit_count); |
1306 | 1306 |
1307 v8::Debug::SetDebugEventListener2(NULL); | 1307 v8::Debug::SetDebugEventListener(NULL); |
1308 CheckDebuggerUnloaded(); | 1308 CheckDebuggerUnloaded(); |
1309 } | 1309 } |
1310 | 1310 |
1311 | 1311 |
1312 static void CallWithBreakPoints(v8::Local<v8::Object> recv, | 1312 static void CallWithBreakPoints(v8::Local<v8::Object> recv, |
1313 v8::Local<v8::Function> f, | 1313 v8::Local<v8::Function> f, |
1314 int break_point_count, | 1314 int break_point_count, |
1315 int call_count) { | 1315 int call_count) { |
1316 break_point_hit_count = 0; | 1316 break_point_hit_count = 0; |
1317 for (int i = 0; i < call_count; i++) { | 1317 for (int i = 0; i < call_count; i++) { |
1318 f->Call(recv, 0, NULL); | 1318 f->Call(recv, 0, NULL); |
1319 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); | 1319 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); |
1320 } | 1320 } |
1321 } | 1321 } |
1322 | 1322 |
1323 | 1323 |
1324 // Test GC during break point processing. | 1324 // Test GC during break point processing. |
1325 TEST(GCDuringBreakPointProcessing) { | 1325 TEST(GCDuringBreakPointProcessing) { |
1326 break_point_hit_count = 0; | 1326 break_point_hit_count = 0; |
1327 DebugLocalContext env; | 1327 DebugLocalContext env; |
1328 v8::HandleScope scope(env->GetIsolate()); | 1328 v8::HandleScope scope(env->GetIsolate()); |
1329 | 1329 |
1330 v8::Debug::SetDebugEventListener2(DebugEventBreakPointCollectGarbage); | 1330 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage); |
1331 v8::Local<v8::Function> foo; | 1331 v8::Local<v8::Function> foo; |
1332 | 1332 |
1333 // Test IC store break point with garbage collection. | 1333 // Test IC store break point with garbage collection. |
1334 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1334 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
1335 SetBreakPoint(foo, 0); | 1335 SetBreakPoint(foo, 0); |
1336 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1336 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1337 | 1337 |
1338 // Test IC load break point with garbage collection. | 1338 // Test IC load break point with garbage collection. |
1339 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); | 1339 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); |
1340 SetBreakPoint(foo, 0); | 1340 SetBreakPoint(foo, 0); |
1341 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1341 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1342 | 1342 |
1343 // Test IC call break point with garbage collection. | 1343 // Test IC call break point with garbage collection. |
1344 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); | 1344 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); |
1345 SetBreakPoint(foo, 0); | 1345 SetBreakPoint(foo, 0); |
1346 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1346 CallWithBreakPoints(env->Global(), foo, 1, 10); |
1347 | 1347 |
1348 // Test return break point with garbage collection. | 1348 // Test return break point with garbage collection. |
1349 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1349 foo = CompileFunction(&env, "function foo(){}", "foo"); |
1350 SetBreakPoint(foo, 0); | 1350 SetBreakPoint(foo, 0); |
1351 CallWithBreakPoints(env->Global(), foo, 1, 25); | 1351 CallWithBreakPoints(env->Global(), foo, 1, 25); |
1352 | 1352 |
1353 // Test debug break slot break point with garbage collection. | 1353 // Test debug break slot break point with garbage collection. |
1354 foo = CompileFunction(&env, "function foo(){var a;}", "foo"); | 1354 foo = CompileFunction(&env, "function foo(){var a;}", "foo"); |
1355 SetBreakPoint(foo, 0); | 1355 SetBreakPoint(foo, 0); |
1356 CallWithBreakPoints(env->Global(), foo, 1, 25); | 1356 CallWithBreakPoints(env->Global(), foo, 1, 25); |
1357 | 1357 |
1358 v8::Debug::SetDebugEventListener2(NULL); | 1358 v8::Debug::SetDebugEventListener(NULL); |
1359 CheckDebuggerUnloaded(); | 1359 CheckDebuggerUnloaded(); |
1360 } | 1360 } |
1361 | 1361 |
1362 | 1362 |
1363 // Call the function three times with different garbage collections in between | 1363 // Call the function three times with different garbage collections in between |
1364 // and make sure that the break point survives. | 1364 // and make sure that the break point survives. |
1365 static void CallAndGC(v8::Local<v8::Object> recv, | 1365 static void CallAndGC(v8::Local<v8::Object> recv, |
1366 v8::Local<v8::Function> f) { | 1366 v8::Local<v8::Function> f) { |
1367 break_point_hit_count = 0; | 1367 break_point_hit_count = 0; |
1368 | 1368 |
(...skipping 14 matching lines...) Expand all Loading... |
1383 } | 1383 } |
1384 } | 1384 } |
1385 | 1385 |
1386 | 1386 |
1387 // Test that a break point can be set at a return store location. | 1387 // Test that a break point can be set at a return store location. |
1388 TEST(BreakPointSurviveGC) { | 1388 TEST(BreakPointSurviveGC) { |
1389 break_point_hit_count = 0; | 1389 break_point_hit_count = 0; |
1390 DebugLocalContext env; | 1390 DebugLocalContext env; |
1391 v8::HandleScope scope(env->GetIsolate()); | 1391 v8::HandleScope scope(env->GetIsolate()); |
1392 | 1392 |
1393 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1393 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1394 v8::Local<v8::Function> foo; | 1394 v8::Local<v8::Function> foo; |
1395 | 1395 |
1396 // Test IC store break point with garbage collection. | 1396 // Test IC store break point with garbage collection. |
1397 { | 1397 { |
1398 CompileFunction(&env, "function foo(){}", "foo"); | 1398 CompileFunction(&env, "function foo(){}", "foo"); |
1399 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1399 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
1400 SetBreakPoint(foo, 0); | 1400 SetBreakPoint(foo, 0); |
1401 } | 1401 } |
1402 CallAndGC(env->Global(), foo); | 1402 CallAndGC(env->Global(), foo); |
1403 | 1403 |
(...skipping 25 matching lines...) Expand all Loading... |
1429 | 1429 |
1430 // Test non IC break point with garbage collection. | 1430 // Test non IC break point with garbage collection. |
1431 { | 1431 { |
1432 CompileFunction(&env, "function foo(){}", "foo"); | 1432 CompileFunction(&env, "function foo(){}", "foo"); |
1433 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); | 1433 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); |
1434 SetBreakPoint(foo, 0); | 1434 SetBreakPoint(foo, 0); |
1435 } | 1435 } |
1436 CallAndGC(env->Global(), foo); | 1436 CallAndGC(env->Global(), foo); |
1437 | 1437 |
1438 | 1438 |
1439 v8::Debug::SetDebugEventListener2(NULL); | 1439 v8::Debug::SetDebugEventListener(NULL); |
1440 CheckDebuggerUnloaded(); | 1440 CheckDebuggerUnloaded(); |
1441 } | 1441 } |
1442 | 1442 |
1443 | 1443 |
1444 // Test that break points can be set using the global Debug object. | 1444 // Test that break points can be set using the global Debug object. |
1445 TEST(BreakPointThroughJavaScript) { | 1445 TEST(BreakPointThroughJavaScript) { |
1446 break_point_hit_count = 0; | 1446 break_point_hit_count = 0; |
1447 DebugLocalContext env; | 1447 DebugLocalContext env; |
1448 v8::HandleScope scope(env->GetIsolate()); | 1448 v8::HandleScope scope(env->GetIsolate()); |
1449 env.ExposeDebug(); | 1449 env.ExposeDebug(); |
1450 | 1450 |
1451 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1451 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1452 v8::Script::Compile( | 1452 v8::Script::Compile( |
1453 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run(); | 1453 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){}"))->Run(); |
1454 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1454 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1455 "function foo(){bar();bar();}")) | 1455 "function foo(){bar();bar();}")) |
1456 ->Run(); | 1456 ->Run(); |
1457 // 012345678901234567890 | 1457 // 012345678901234567890 |
1458 // 1 2 | 1458 // 1 2 |
1459 // Break points are set at position 3 and 9 | 1459 // Break points are set at position 3 and 9 |
1460 v8::Local<v8::Script> foo = | 1460 v8::Local<v8::Script> foo = |
1461 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "foo()")); | 1461 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "foo()")); |
(...skipping 21 matching lines...) Expand all Loading... |
1483 foo->Run(); | 1483 foo->Run(); |
1484 CHECK_EQ(7, break_point_hit_count); | 1484 CHECK_EQ(7, break_point_hit_count); |
1485 foo->Run(); | 1485 foo->Run(); |
1486 CHECK_EQ(8, break_point_hit_count); | 1486 CHECK_EQ(8, break_point_hit_count); |
1487 | 1487 |
1488 // Run without breakpoints. | 1488 // Run without breakpoints. |
1489 ClearBreakPointFromJS(env->GetIsolate(), bp1); | 1489 ClearBreakPointFromJS(env->GetIsolate(), bp1); |
1490 foo->Run(); | 1490 foo->Run(); |
1491 CHECK_EQ(8, break_point_hit_count); | 1491 CHECK_EQ(8, break_point_hit_count); |
1492 | 1492 |
1493 v8::Debug::SetDebugEventListener2(NULL); | 1493 v8::Debug::SetDebugEventListener(NULL); |
1494 CheckDebuggerUnloaded(); | 1494 CheckDebuggerUnloaded(); |
1495 | 1495 |
1496 // Make sure that the break point numbers are consecutive. | 1496 // Make sure that the break point numbers are consecutive. |
1497 CHECK_EQ(1, bp1); | 1497 CHECK_EQ(1, bp1); |
1498 CHECK_EQ(2, bp2); | 1498 CHECK_EQ(2, bp2); |
1499 } | 1499 } |
1500 | 1500 |
1501 | 1501 |
1502 // Test that break points on scripts identified by name can be set using the | 1502 // Test that break points on scripts identified by name can be set using the |
1503 // global Debug object. | 1503 // global Debug object. |
1504 TEST(ScriptBreakPointByNameThroughJavaScript) { | 1504 TEST(ScriptBreakPointByNameThroughJavaScript) { |
1505 break_point_hit_count = 0; | 1505 break_point_hit_count = 0; |
1506 DebugLocalContext env; | 1506 DebugLocalContext env; |
1507 v8::HandleScope scope(env->GetIsolate()); | 1507 v8::HandleScope scope(env->GetIsolate()); |
1508 env.ExposeDebug(); | 1508 env.ExposeDebug(); |
1509 | 1509 |
1510 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1510 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1511 | 1511 |
1512 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 1512 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
1513 env->GetIsolate(), | 1513 env->GetIsolate(), |
1514 "function f() {\n" | 1514 "function f() {\n" |
1515 " function h() {\n" | 1515 " function h() {\n" |
1516 " a = 0; // line 2\n" | 1516 " a = 0; // line 2\n" |
1517 " }\n" | 1517 " }\n" |
1518 " b = 1; // line 4\n" | 1518 " b = 1; // line 4\n" |
1519 " return h();\n" | 1519 " return h();\n" |
1520 "}\n" | 1520 "}\n" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 ClearBreakPointFromJS(env->GetIsolate(), sbp2); | 1585 ClearBreakPointFromJS(env->GetIsolate(), sbp2); |
1586 ClearBreakPointFromJS(env->GetIsolate(), sbp3); | 1586 ClearBreakPointFromJS(env->GetIsolate(), sbp3); |
1587 ClearBreakPointFromJS(env->GetIsolate(), sbp4); | 1587 ClearBreakPointFromJS(env->GetIsolate(), sbp4); |
1588 ClearBreakPointFromJS(env->GetIsolate(), sbp5); | 1588 ClearBreakPointFromJS(env->GetIsolate(), sbp5); |
1589 ClearBreakPointFromJS(env->GetIsolate(), sbp6); | 1589 ClearBreakPointFromJS(env->GetIsolate(), sbp6); |
1590 f->Call(env->Global(), 0, NULL); | 1590 f->Call(env->Global(), 0, NULL); |
1591 CHECK_EQ(0, break_point_hit_count); | 1591 CHECK_EQ(0, break_point_hit_count); |
1592 g->Call(env->Global(), 0, NULL); | 1592 g->Call(env->Global(), 0, NULL); |
1593 CHECK_EQ(0, break_point_hit_count); | 1593 CHECK_EQ(0, break_point_hit_count); |
1594 | 1594 |
1595 v8::Debug::SetDebugEventListener2(NULL); | 1595 v8::Debug::SetDebugEventListener(NULL); |
1596 CheckDebuggerUnloaded(); | 1596 CheckDebuggerUnloaded(); |
1597 | 1597 |
1598 // Make sure that the break point numbers are consecutive. | 1598 // Make sure that the break point numbers are consecutive. |
1599 CHECK_EQ(1, sbp1); | 1599 CHECK_EQ(1, sbp1); |
1600 CHECK_EQ(2, sbp2); | 1600 CHECK_EQ(2, sbp2); |
1601 CHECK_EQ(3, sbp3); | 1601 CHECK_EQ(3, sbp3); |
1602 CHECK_EQ(4, sbp4); | 1602 CHECK_EQ(4, sbp4); |
1603 CHECK_EQ(5, sbp5); | 1603 CHECK_EQ(5, sbp5); |
1604 CHECK_EQ(6, sbp6); | 1604 CHECK_EQ(6, sbp6); |
1605 } | 1605 } |
1606 | 1606 |
1607 | 1607 |
1608 TEST(ScriptBreakPointByIdThroughJavaScript) { | 1608 TEST(ScriptBreakPointByIdThroughJavaScript) { |
1609 break_point_hit_count = 0; | 1609 break_point_hit_count = 0; |
1610 DebugLocalContext env; | 1610 DebugLocalContext env; |
1611 v8::HandleScope scope(env->GetIsolate()); | 1611 v8::HandleScope scope(env->GetIsolate()); |
1612 env.ExposeDebug(); | 1612 env.ExposeDebug(); |
1613 | 1613 |
1614 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1614 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1615 | 1615 |
1616 v8::Local<v8::String> source = v8::String::NewFromUtf8( | 1616 v8::Local<v8::String> source = v8::String::NewFromUtf8( |
1617 env->GetIsolate(), | 1617 env->GetIsolate(), |
1618 "function f() {\n" | 1618 "function f() {\n" |
1619 " function h() {\n" | 1619 " function h() {\n" |
1620 " a = 0; // line 2\n" | 1620 " a = 0; // line 2\n" |
1621 " }\n" | 1621 " }\n" |
1622 " b = 1; // line 4\n" | 1622 " b = 1; // line 4\n" |
1623 " return h();\n" | 1623 " return h();\n" |
1624 "}\n" | 1624 "}\n" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 ClearBreakPointFromJS(env->GetIsolate(), sbp2); | 1693 ClearBreakPointFromJS(env->GetIsolate(), sbp2); |
1694 ClearBreakPointFromJS(env->GetIsolate(), sbp3); | 1694 ClearBreakPointFromJS(env->GetIsolate(), sbp3); |
1695 ClearBreakPointFromJS(env->GetIsolate(), sbp4); | 1695 ClearBreakPointFromJS(env->GetIsolate(), sbp4); |
1696 ClearBreakPointFromJS(env->GetIsolate(), sbp5); | 1696 ClearBreakPointFromJS(env->GetIsolate(), sbp5); |
1697 ClearBreakPointFromJS(env->GetIsolate(), sbp6); | 1697 ClearBreakPointFromJS(env->GetIsolate(), sbp6); |
1698 f->Call(env->Global(), 0, NULL); | 1698 f->Call(env->Global(), 0, NULL); |
1699 CHECK_EQ(0, break_point_hit_count); | 1699 CHECK_EQ(0, break_point_hit_count); |
1700 g->Call(env->Global(), 0, NULL); | 1700 g->Call(env->Global(), 0, NULL); |
1701 CHECK_EQ(0, break_point_hit_count); | 1701 CHECK_EQ(0, break_point_hit_count); |
1702 | 1702 |
1703 v8::Debug::SetDebugEventListener2(NULL); | 1703 v8::Debug::SetDebugEventListener(NULL); |
1704 CheckDebuggerUnloaded(); | 1704 CheckDebuggerUnloaded(); |
1705 | 1705 |
1706 // Make sure that the break point numbers are consecutive. | 1706 // Make sure that the break point numbers are consecutive. |
1707 CHECK_EQ(1, sbp1); | 1707 CHECK_EQ(1, sbp1); |
1708 CHECK_EQ(2, sbp2); | 1708 CHECK_EQ(2, sbp2); |
1709 CHECK_EQ(3, sbp3); | 1709 CHECK_EQ(3, sbp3); |
1710 CHECK_EQ(4, sbp4); | 1710 CHECK_EQ(4, sbp4); |
1711 CHECK_EQ(5, sbp5); | 1711 CHECK_EQ(5, sbp5); |
1712 CHECK_EQ(6, sbp6); | 1712 CHECK_EQ(6, sbp6); |
1713 } | 1713 } |
1714 | 1714 |
1715 | 1715 |
1716 // Test conditional script break points. | 1716 // Test conditional script break points. |
1717 TEST(EnableDisableScriptBreakPoint) { | 1717 TEST(EnableDisableScriptBreakPoint) { |
1718 break_point_hit_count = 0; | 1718 break_point_hit_count = 0; |
1719 DebugLocalContext env; | 1719 DebugLocalContext env; |
1720 v8::HandleScope scope(env->GetIsolate()); | 1720 v8::HandleScope scope(env->GetIsolate()); |
1721 env.ExposeDebug(); | 1721 env.ExposeDebug(); |
1722 | 1722 |
1723 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1723 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1724 | 1724 |
1725 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 1725 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
1726 env->GetIsolate(), | 1726 env->GetIsolate(), |
1727 "function f() {\n" | 1727 "function f() {\n" |
1728 " a = 0; // line 1\n" | 1728 " a = 0; // line 1\n" |
1729 "};"); | 1729 "};"); |
1730 | 1730 |
1731 // Compile the script and get function f. | 1731 // Compile the script and get function f. |
1732 v8::ScriptOrigin origin = | 1732 v8::ScriptOrigin origin = |
1733 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 1733 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); |
(...skipping 25 matching lines...) Expand all Loading... |
1759 v8::Script::Compile(script, &origin)->Run(); | 1759 v8::Script::Compile(script, &origin)->Run(); |
1760 f = v8::Local<v8::Function>::Cast( | 1760 f = v8::Local<v8::Function>::Cast( |
1761 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 1761 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
1762 f->Call(env->Global(), 0, NULL); | 1762 f->Call(env->Global(), 0, NULL); |
1763 CHECK_EQ(2, break_point_hit_count); | 1763 CHECK_EQ(2, break_point_hit_count); |
1764 | 1764 |
1765 EnableScriptBreakPointFromJS(env->GetIsolate(), sbp); | 1765 EnableScriptBreakPointFromJS(env->GetIsolate(), sbp); |
1766 f->Call(env->Global(), 0, NULL); | 1766 f->Call(env->Global(), 0, NULL); |
1767 CHECK_EQ(3, break_point_hit_count); | 1767 CHECK_EQ(3, break_point_hit_count); |
1768 | 1768 |
1769 v8::Debug::SetDebugEventListener2(NULL); | 1769 v8::Debug::SetDebugEventListener(NULL); |
1770 CheckDebuggerUnloaded(); | 1770 CheckDebuggerUnloaded(); |
1771 } | 1771 } |
1772 | 1772 |
1773 | 1773 |
1774 // Test conditional script break points. | 1774 // Test conditional script break points. |
1775 TEST(ConditionalScriptBreakPoint) { | 1775 TEST(ConditionalScriptBreakPoint) { |
1776 break_point_hit_count = 0; | 1776 break_point_hit_count = 0; |
1777 DebugLocalContext env; | 1777 DebugLocalContext env; |
1778 v8::HandleScope scope(env->GetIsolate()); | 1778 v8::HandleScope scope(env->GetIsolate()); |
1779 env.ExposeDebug(); | 1779 env.ExposeDebug(); |
1780 | 1780 |
1781 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1781 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1782 | 1782 |
1783 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 1783 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
1784 env->GetIsolate(), | 1784 env->GetIsolate(), |
1785 "count = 0;\n" | 1785 "count = 0;\n" |
1786 "function f() {\n" | 1786 "function f() {\n" |
1787 " g(count++); // line 2\n" | 1787 " g(count++); // line 2\n" |
1788 "};\n" | 1788 "};\n" |
1789 "function g(x) {\n" | 1789 "function g(x) {\n" |
1790 " var a=x; // line 5\n" | 1790 " var a=x; // line 5\n" |
1791 "};"); | 1791 "};"); |
(...skipping 30 matching lines...) Expand all Loading... |
1822 v8::Script::Compile(script, &origin)->Run(); | 1822 v8::Script::Compile(script, &origin)->Run(); |
1823 f = v8::Local<v8::Function>::Cast( | 1823 f = v8::Local<v8::Function>::Cast( |
1824 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 1824 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
1825 | 1825 |
1826 break_point_hit_count = 0; | 1826 break_point_hit_count = 0; |
1827 for (int i = 0; i < 10; i++) { | 1827 for (int i = 0; i < 10; i++) { |
1828 f->Call(env->Global(), 0, NULL); | 1828 f->Call(env->Global(), 0, NULL); |
1829 } | 1829 } |
1830 CHECK_EQ(5, break_point_hit_count); | 1830 CHECK_EQ(5, break_point_hit_count); |
1831 | 1831 |
1832 v8::Debug::SetDebugEventListener2(NULL); | 1832 v8::Debug::SetDebugEventListener(NULL); |
1833 CheckDebuggerUnloaded(); | 1833 CheckDebuggerUnloaded(); |
1834 } | 1834 } |
1835 | 1835 |
1836 | 1836 |
1837 // Test ignore count on script break points. | 1837 // Test ignore count on script break points. |
1838 TEST(ScriptBreakPointIgnoreCount) { | 1838 TEST(ScriptBreakPointIgnoreCount) { |
1839 break_point_hit_count = 0; | 1839 break_point_hit_count = 0; |
1840 DebugLocalContext env; | 1840 DebugLocalContext env; |
1841 v8::HandleScope scope(env->GetIsolate()); | 1841 v8::HandleScope scope(env->GetIsolate()); |
1842 env.ExposeDebug(); | 1842 env.ExposeDebug(); |
1843 | 1843 |
1844 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1844 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1845 | 1845 |
1846 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 1846 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
1847 env->GetIsolate(), | 1847 env->GetIsolate(), |
1848 "function f() {\n" | 1848 "function f() {\n" |
1849 " a = 0; // line 1\n" | 1849 " a = 0; // line 1\n" |
1850 "};"); | 1850 "};"); |
1851 | 1851 |
1852 // Compile the script and get function f. | 1852 // Compile the script and get function f. |
1853 v8::ScriptOrigin origin = | 1853 v8::ScriptOrigin origin = |
1854 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 1854 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); |
(...skipping 23 matching lines...) Expand all Loading... |
1878 v8::Script::Compile(script, &origin)->Run(); | 1878 v8::Script::Compile(script, &origin)->Run(); |
1879 f = v8::Local<v8::Function>::Cast( | 1879 f = v8::Local<v8::Function>::Cast( |
1880 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 1880 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
1881 | 1881 |
1882 break_point_hit_count = 0; | 1882 break_point_hit_count = 0; |
1883 for (int i = 0; i < 10; i++) { | 1883 for (int i = 0; i < 10; i++) { |
1884 f->Call(env->Global(), 0, NULL); | 1884 f->Call(env->Global(), 0, NULL); |
1885 } | 1885 } |
1886 CHECK_EQ(5, break_point_hit_count); | 1886 CHECK_EQ(5, break_point_hit_count); |
1887 | 1887 |
1888 v8::Debug::SetDebugEventListener2(NULL); | 1888 v8::Debug::SetDebugEventListener(NULL); |
1889 CheckDebuggerUnloaded(); | 1889 CheckDebuggerUnloaded(); |
1890 } | 1890 } |
1891 | 1891 |
1892 | 1892 |
1893 // Test that script break points survive when a script is reloaded. | 1893 // Test that script break points survive when a script is reloaded. |
1894 TEST(ScriptBreakPointReload) { | 1894 TEST(ScriptBreakPointReload) { |
1895 break_point_hit_count = 0; | 1895 break_point_hit_count = 0; |
1896 DebugLocalContext env; | 1896 DebugLocalContext env; |
1897 v8::HandleScope scope(env->GetIsolate()); | 1897 v8::HandleScope scope(env->GetIsolate()); |
1898 env.ExposeDebug(); | 1898 env.ExposeDebug(); |
1899 | 1899 |
1900 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1900 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1901 | 1901 |
1902 v8::Local<v8::Function> f; | 1902 v8::Local<v8::Function> f; |
1903 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 1903 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
1904 env->GetIsolate(), | 1904 env->GetIsolate(), |
1905 "function f() {\n" | 1905 "function f() {\n" |
1906 " function h() {\n" | 1906 " function h() {\n" |
1907 " a = 0; // line 2\n" | 1907 " a = 0; // line 2\n" |
1908 " }\n" | 1908 " }\n" |
1909 " b = 1; // line 4\n" | 1909 " b = 1; // line 4\n" |
1910 " return h();\n" | 1910 " return h();\n" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 // Compile the script again and get the function. | 1942 // Compile the script again and get the function. |
1943 v8::Script::Compile(script, &origin_1)->Run(); | 1943 v8::Script::Compile(script, &origin_1)->Run(); |
1944 f = v8::Local<v8::Function>::Cast( | 1944 f = v8::Local<v8::Function>::Cast( |
1945 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 1945 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
1946 | 1946 |
1947 // Call f and check that the script break point is active. | 1947 // Call f and check that the script break point is active. |
1948 break_point_hit_count = 0; | 1948 break_point_hit_count = 0; |
1949 f->Call(env->Global(), 0, NULL); | 1949 f->Call(env->Global(), 0, NULL); |
1950 CHECK_EQ(1, break_point_hit_count); | 1950 CHECK_EQ(1, break_point_hit_count); |
1951 | 1951 |
1952 v8::Debug::SetDebugEventListener2(NULL); | 1952 v8::Debug::SetDebugEventListener(NULL); |
1953 CheckDebuggerUnloaded(); | 1953 CheckDebuggerUnloaded(); |
1954 } | 1954 } |
1955 | 1955 |
1956 | 1956 |
1957 // Test when several scripts has the same script data | 1957 // Test when several scripts has the same script data |
1958 TEST(ScriptBreakPointMultiple) { | 1958 TEST(ScriptBreakPointMultiple) { |
1959 break_point_hit_count = 0; | 1959 break_point_hit_count = 0; |
1960 DebugLocalContext env; | 1960 DebugLocalContext env; |
1961 v8::HandleScope scope(env->GetIsolate()); | 1961 v8::HandleScope scope(env->GetIsolate()); |
1962 env.ExposeDebug(); | 1962 env.ExposeDebug(); |
1963 | 1963 |
1964 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 1964 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
1965 | 1965 |
1966 v8::Local<v8::Function> f; | 1966 v8::Local<v8::Function> f; |
1967 v8::Local<v8::String> script_f = | 1967 v8::Local<v8::String> script_f = |
1968 v8::String::NewFromUtf8(env->GetIsolate(), | 1968 v8::String::NewFromUtf8(env->GetIsolate(), |
1969 "function f() {\n" | 1969 "function f() {\n" |
1970 " a = 0; // line 1\n" | 1970 " a = 0; // line 1\n" |
1971 "}"); | 1971 "}"); |
1972 | 1972 |
1973 v8::Local<v8::Function> g; | 1973 v8::Local<v8::Function> g; |
1974 v8::Local<v8::String> script_g = | 1974 v8::Local<v8::String> script_g = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 // Set script break point with the scripts loaded. | 2011 // Set script break point with the scripts loaded. |
2012 sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0); | 2012 sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0); |
2013 | 2013 |
2014 // Call f and g and check that the script break point is active. | 2014 // Call f and g and check that the script break point is active. |
2015 break_point_hit_count = 0; | 2015 break_point_hit_count = 0; |
2016 f->Call(env->Global(), 0, NULL); | 2016 f->Call(env->Global(), 0, NULL); |
2017 CHECK_EQ(1, break_point_hit_count); | 2017 CHECK_EQ(1, break_point_hit_count); |
2018 g->Call(env->Global(), 0, NULL); | 2018 g->Call(env->Global(), 0, NULL); |
2019 CHECK_EQ(2, break_point_hit_count); | 2019 CHECK_EQ(2, break_point_hit_count); |
2020 | 2020 |
2021 v8::Debug::SetDebugEventListener2(NULL); | 2021 v8::Debug::SetDebugEventListener(NULL); |
2022 CheckDebuggerUnloaded(); | 2022 CheckDebuggerUnloaded(); |
2023 } | 2023 } |
2024 | 2024 |
2025 | 2025 |
2026 // Test the script origin which has both name and line offset. | 2026 // Test the script origin which has both name and line offset. |
2027 TEST(ScriptBreakPointLineOffset) { | 2027 TEST(ScriptBreakPointLineOffset) { |
2028 break_point_hit_count = 0; | 2028 break_point_hit_count = 0; |
2029 DebugLocalContext env; | 2029 DebugLocalContext env; |
2030 v8::HandleScope scope(env->GetIsolate()); | 2030 v8::HandleScope scope(env->GetIsolate()); |
2031 env.ExposeDebug(); | 2031 env.ExposeDebug(); |
2032 | 2032 |
2033 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2033 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2034 | 2034 |
2035 v8::Local<v8::Function> f; | 2035 v8::Local<v8::Function> f; |
2036 v8::Local<v8::String> script = v8::String::NewFromUtf8( | 2036 v8::Local<v8::String> script = v8::String::NewFromUtf8( |
2037 env->GetIsolate(), | 2037 env->GetIsolate(), |
2038 "function f() {\n" | 2038 "function f() {\n" |
2039 " a = 0; // line 8 as this script has line offset 7\n" | 2039 " a = 0; // line 8 as this script has line offset 7\n" |
2040 " b = 0; // line 9 as this script has line offset 7\n" | 2040 " b = 0; // line 9 as this script has line offset 7\n" |
2041 "}"); | 2041 "}"); |
2042 | 2042 |
2043 // Create script origin both name and line offset. | 2043 // Create script origin both name and line offset. |
(...skipping 27 matching lines...) Expand all Loading... |
2071 CHECK_EQ(0, break_point_hit_count); | 2071 CHECK_EQ(0, break_point_hit_count); |
2072 | 2072 |
2073 // Set a script break point with the script loaded. | 2073 // Set a script break point with the script loaded. |
2074 sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0); | 2074 sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0); |
2075 | 2075 |
2076 // Call f and check that the script break point is active. | 2076 // Call f and check that the script break point is active. |
2077 break_point_hit_count = 0; | 2077 break_point_hit_count = 0; |
2078 f->Call(env->Global(), 0, NULL); | 2078 f->Call(env->Global(), 0, NULL); |
2079 CHECK_EQ(1, break_point_hit_count); | 2079 CHECK_EQ(1, break_point_hit_count); |
2080 | 2080 |
2081 v8::Debug::SetDebugEventListener2(NULL); | 2081 v8::Debug::SetDebugEventListener(NULL); |
2082 CheckDebuggerUnloaded(); | 2082 CheckDebuggerUnloaded(); |
2083 } | 2083 } |
2084 | 2084 |
2085 | 2085 |
2086 // Test script break points set on lines. | 2086 // Test script break points set on lines. |
2087 TEST(ScriptBreakPointLine) { | 2087 TEST(ScriptBreakPointLine) { |
2088 DebugLocalContext env; | 2088 DebugLocalContext env; |
2089 v8::HandleScope scope(env->GetIsolate()); | 2089 v8::HandleScope scope(env->GetIsolate()); |
2090 env.ExposeDebug(); | 2090 env.ExposeDebug(); |
2091 | 2091 |
2092 // Create a function for checking the function when hitting a break point. | 2092 // Create a function for checking the function when hitting a break point. |
2093 frame_function_name = CompileFunction(&env, | 2093 frame_function_name = CompileFunction(&env, |
2094 frame_function_name_source, | 2094 frame_function_name_source, |
2095 "frame_function_name"); | 2095 "frame_function_name"); |
2096 | 2096 |
2097 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2097 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2098 | 2098 |
2099 v8::Local<v8::Function> f; | 2099 v8::Local<v8::Function> f; |
2100 v8::Local<v8::Function> g; | 2100 v8::Local<v8::Function> g; |
2101 v8::Local<v8::String> script = | 2101 v8::Local<v8::String> script = |
2102 v8::String::NewFromUtf8(env->GetIsolate(), | 2102 v8::String::NewFromUtf8(env->GetIsolate(), |
2103 "a = 0 // line 0\n" | 2103 "a = 0 // line 0\n" |
2104 "function f() {\n" | 2104 "function f() {\n" |
2105 " a = 1; // line 2\n" | 2105 " a = 1; // line 2\n" |
2106 "}\n" | 2106 "}\n" |
2107 " a = 2; // line 4\n" | 2107 " a = 2; // line 4\n" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 | 2187 |
2188 // Clear the last break points, and reload the script which should not hit any | 2188 // Clear the last break points, and reload the script which should not hit any |
2189 // break points. | 2189 // break points. |
2190 ClearBreakPointFromJS(env->GetIsolate(), sbp1); | 2190 ClearBreakPointFromJS(env->GetIsolate(), sbp1); |
2191 ClearBreakPointFromJS(env->GetIsolate(), sbp5); | 2191 ClearBreakPointFromJS(env->GetIsolate(), sbp5); |
2192 ClearBreakPointFromJS(env->GetIsolate(), sbp6); | 2192 ClearBreakPointFromJS(env->GetIsolate(), sbp6); |
2193 break_point_hit_count = 0; | 2193 break_point_hit_count = 0; |
2194 v8::Script::Compile(script, &origin)->Run(); | 2194 v8::Script::Compile(script, &origin)->Run(); |
2195 CHECK_EQ(0, break_point_hit_count); | 2195 CHECK_EQ(0, break_point_hit_count); |
2196 | 2196 |
2197 v8::Debug::SetDebugEventListener2(NULL); | 2197 v8::Debug::SetDebugEventListener(NULL); |
2198 CheckDebuggerUnloaded(); | 2198 CheckDebuggerUnloaded(); |
2199 } | 2199 } |
2200 | 2200 |
2201 | 2201 |
2202 // Test top level script break points set on lines. | 2202 // Test top level script break points set on lines. |
2203 TEST(ScriptBreakPointLineTopLevel) { | 2203 TEST(ScriptBreakPointLineTopLevel) { |
2204 DebugLocalContext env; | 2204 DebugLocalContext env; |
2205 v8::HandleScope scope(env->GetIsolate()); | 2205 v8::HandleScope scope(env->GetIsolate()); |
2206 env.ExposeDebug(); | 2206 env.ExposeDebug(); |
2207 | 2207 |
2208 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2208 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2209 | 2209 |
2210 v8::Local<v8::String> script = | 2210 v8::Local<v8::String> script = |
2211 v8::String::NewFromUtf8(env->GetIsolate(), | 2211 v8::String::NewFromUtf8(env->GetIsolate(), |
2212 "function f() {\n" | 2212 "function f() {\n" |
2213 " a = 1; // line 1\n" | 2213 " a = 1; // line 1\n" |
2214 "}\n" | 2214 "}\n" |
2215 "a = 2; // line 3\n"); | 2215 "a = 2; // line 3\n"); |
2216 v8::Local<v8::Function> f; | 2216 v8::Local<v8::Function> f; |
2217 { | 2217 { |
2218 v8::HandleScope scope(env->GetIsolate()); | 2218 v8::HandleScope scope(env->GetIsolate()); |
(...skipping 15 matching lines...) Expand all Loading... |
2234 break_point_hit_count = 0; | 2234 break_point_hit_count = 0; |
2235 CompileRunWithOrigin(script, "test.html"); | 2235 CompileRunWithOrigin(script, "test.html"); |
2236 CHECK_EQ(1, break_point_hit_count); | 2236 CHECK_EQ(1, break_point_hit_count); |
2237 | 2237 |
2238 // Call f and check that there are still no break points. | 2238 // Call f and check that there are still no break points. |
2239 break_point_hit_count = 0; | 2239 break_point_hit_count = 0; |
2240 f = v8::Local<v8::Function>::Cast( | 2240 f = v8::Local<v8::Function>::Cast( |
2241 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 2241 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
2242 CHECK_EQ(0, break_point_hit_count); | 2242 CHECK_EQ(0, break_point_hit_count); |
2243 | 2243 |
2244 v8::Debug::SetDebugEventListener2(NULL); | 2244 v8::Debug::SetDebugEventListener(NULL); |
2245 CheckDebuggerUnloaded(); | 2245 CheckDebuggerUnloaded(); |
2246 } | 2246 } |
2247 | 2247 |
2248 | 2248 |
2249 // Test that it is possible to add and remove break points in a top level | 2249 // Test that it is possible to add and remove break points in a top level |
2250 // function which has no references but has not been collected yet. | 2250 // function which has no references but has not been collected yet. |
2251 TEST(ScriptBreakPointTopLevelCrash) { | 2251 TEST(ScriptBreakPointTopLevelCrash) { |
2252 DebugLocalContext env; | 2252 DebugLocalContext env; |
2253 v8::HandleScope scope(env->GetIsolate()); | 2253 v8::HandleScope scope(env->GetIsolate()); |
2254 env.ExposeDebug(); | 2254 env.ExposeDebug(); |
2255 | 2255 |
2256 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2256 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2257 | 2257 |
2258 v8::Local<v8::String> script_source = | 2258 v8::Local<v8::String> script_source = |
2259 v8::String::NewFromUtf8(env->GetIsolate(), | 2259 v8::String::NewFromUtf8(env->GetIsolate(), |
2260 "function f() {\n" | 2260 "function f() {\n" |
2261 " return 0;\n" | 2261 " return 0;\n" |
2262 "}\n" | 2262 "}\n" |
2263 "f()"); | 2263 "f()"); |
2264 | 2264 |
2265 int sbp1 = | 2265 int sbp1 = |
2266 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); | 2266 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); |
2267 { | 2267 { |
2268 v8::HandleScope scope(env->GetIsolate()); | 2268 v8::HandleScope scope(env->GetIsolate()); |
2269 break_point_hit_count = 0; | 2269 break_point_hit_count = 0; |
2270 CompileRunWithOrigin(script_source, "test.html"); | 2270 CompileRunWithOrigin(script_source, "test.html"); |
2271 CHECK_EQ(1, break_point_hit_count); | 2271 CHECK_EQ(1, break_point_hit_count); |
2272 } | 2272 } |
2273 | 2273 |
2274 int sbp2 = | 2274 int sbp2 = |
2275 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); | 2275 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); |
2276 ClearBreakPointFromJS(env->GetIsolate(), sbp1); | 2276 ClearBreakPointFromJS(env->GetIsolate(), sbp1); |
2277 ClearBreakPointFromJS(env->GetIsolate(), sbp2); | 2277 ClearBreakPointFromJS(env->GetIsolate(), sbp2); |
2278 | 2278 |
2279 v8::Debug::SetDebugEventListener2(NULL); | 2279 v8::Debug::SetDebugEventListener(NULL); |
2280 CheckDebuggerUnloaded(); | 2280 CheckDebuggerUnloaded(); |
2281 } | 2281 } |
2282 | 2282 |
2283 | 2283 |
2284 // Test that it is possible to remove the last break point for a function | 2284 // Test that it is possible to remove the last break point for a function |
2285 // inside the break handling of that break point. | 2285 // inside the break handling of that break point. |
2286 TEST(RemoveBreakPointInBreak) { | 2286 TEST(RemoveBreakPointInBreak) { |
2287 DebugLocalContext env; | 2287 DebugLocalContext env; |
2288 v8::HandleScope scope(env->GetIsolate()); | 2288 v8::HandleScope scope(env->GetIsolate()); |
2289 | 2289 |
2290 v8::Local<v8::Function> foo = | 2290 v8::Local<v8::Function> foo = |
2291 CompileFunction(&env, "function foo(){a=1;}", "foo"); | 2291 CompileFunction(&env, "function foo(){a=1;}", "foo"); |
2292 debug_event_remove_break_point = SetBreakPoint(foo, 0); | 2292 debug_event_remove_break_point = SetBreakPoint(foo, 0); |
2293 | 2293 |
2294 // Register the debug event listener pasing the function | 2294 // Register the debug event listener pasing the function |
2295 v8::Debug::SetDebugEventListener2(DebugEventRemoveBreakPoint, foo); | 2295 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); |
2296 | 2296 |
2297 break_point_hit_count = 0; | 2297 break_point_hit_count = 0; |
2298 foo->Call(env->Global(), 0, NULL); | 2298 foo->Call(env->Global(), 0, NULL); |
2299 CHECK_EQ(1, break_point_hit_count); | 2299 CHECK_EQ(1, break_point_hit_count); |
2300 | 2300 |
2301 break_point_hit_count = 0; | 2301 break_point_hit_count = 0; |
2302 foo->Call(env->Global(), 0, NULL); | 2302 foo->Call(env->Global(), 0, NULL); |
2303 CHECK_EQ(0, break_point_hit_count); | 2303 CHECK_EQ(0, break_point_hit_count); |
2304 | 2304 |
2305 v8::Debug::SetDebugEventListener2(NULL); | 2305 v8::Debug::SetDebugEventListener(NULL); |
2306 CheckDebuggerUnloaded(); | 2306 CheckDebuggerUnloaded(); |
2307 } | 2307 } |
2308 | 2308 |
2309 | 2309 |
2310 // Test that the debugger statement causes a break. | 2310 // Test that the debugger statement causes a break. |
2311 TEST(DebuggerStatement) { | 2311 TEST(DebuggerStatement) { |
2312 break_point_hit_count = 0; | 2312 break_point_hit_count = 0; |
2313 DebugLocalContext env; | 2313 DebugLocalContext env; |
2314 v8::HandleScope scope(env->GetIsolate()); | 2314 v8::HandleScope scope(env->GetIsolate()); |
2315 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2315 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2316 v8::Script::Compile( | 2316 v8::Script::Compile( |
2317 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){debugger}")) | 2317 v8::String::NewFromUtf8(env->GetIsolate(), "function bar(){debugger}")) |
2318 ->Run(); | 2318 ->Run(); |
2319 v8::Script::Compile( | 2319 v8::Script::Compile( |
2320 v8::String::NewFromUtf8(env->GetIsolate(), | 2320 v8::String::NewFromUtf8(env->GetIsolate(), |
2321 "function foo(){debugger;debugger;}"))->Run(); | 2321 "function foo(){debugger;debugger;}"))->Run(); |
2322 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 2322 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
2323 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 2323 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
2324 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 2324 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
2325 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); | 2325 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); |
2326 | 2326 |
2327 // Run function with debugger statement | 2327 // Run function with debugger statement |
2328 bar->Call(env->Global(), 0, NULL); | 2328 bar->Call(env->Global(), 0, NULL); |
2329 CHECK_EQ(1, break_point_hit_count); | 2329 CHECK_EQ(1, break_point_hit_count); |
2330 | 2330 |
2331 // Run function with two debugger statement | 2331 // Run function with two debugger statement |
2332 foo->Call(env->Global(), 0, NULL); | 2332 foo->Call(env->Global(), 0, NULL); |
2333 CHECK_EQ(3, break_point_hit_count); | 2333 CHECK_EQ(3, break_point_hit_count); |
2334 | 2334 |
2335 v8::Debug::SetDebugEventListener2(NULL); | 2335 v8::Debug::SetDebugEventListener(NULL); |
2336 CheckDebuggerUnloaded(); | 2336 CheckDebuggerUnloaded(); |
2337 } | 2337 } |
2338 | 2338 |
2339 | 2339 |
2340 // Test setting a breakpoint on the debugger statement. | 2340 // Test setting a breakpoint on the debugger statement. |
2341 TEST(DebuggerStatementBreakpoint) { | 2341 TEST(DebuggerStatementBreakpoint) { |
2342 break_point_hit_count = 0; | 2342 break_point_hit_count = 0; |
2343 DebugLocalContext env; | 2343 DebugLocalContext env; |
2344 v8::HandleScope scope(env->GetIsolate()); | 2344 v8::HandleScope scope(env->GetIsolate()); |
2345 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2345 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2346 v8::Script::Compile( | 2346 v8::Script::Compile( |
2347 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){debugger;}")) | 2347 v8::String::NewFromUtf8(env->GetIsolate(), "function foo(){debugger;}")) |
2348 ->Run(); | 2348 ->Run(); |
2349 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 2349 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
2350 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 2350 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
2351 | 2351 |
2352 // The debugger statement triggers breakpint hit | 2352 // The debugger statement triggers breakpint hit |
2353 foo->Call(env->Global(), 0, NULL); | 2353 foo->Call(env->Global(), 0, NULL); |
2354 CHECK_EQ(1, break_point_hit_count); | 2354 CHECK_EQ(1, break_point_hit_count); |
2355 | 2355 |
2356 int bp = SetBreakPoint(foo, 0); | 2356 int bp = SetBreakPoint(foo, 0); |
2357 | 2357 |
2358 // Set breakpoint does not duplicate hits | 2358 // Set breakpoint does not duplicate hits |
2359 foo->Call(env->Global(), 0, NULL); | 2359 foo->Call(env->Global(), 0, NULL); |
2360 CHECK_EQ(2, break_point_hit_count); | 2360 CHECK_EQ(2, break_point_hit_count); |
2361 | 2361 |
2362 ClearBreakPoint(bp); | 2362 ClearBreakPoint(bp); |
2363 v8::Debug::SetDebugEventListener2(NULL); | 2363 v8::Debug::SetDebugEventListener(NULL); |
2364 CheckDebuggerUnloaded(); | 2364 CheckDebuggerUnloaded(); |
2365 } | 2365 } |
2366 | 2366 |
2367 | 2367 |
2368 // Test that the evaluation of expressions when a break point is hit generates | 2368 // Test that the evaluation of expressions when a break point is hit generates |
2369 // the correct results. | 2369 // the correct results. |
2370 TEST(DebugEvaluate) { | 2370 TEST(DebugEvaluate) { |
2371 DebugLocalContext env; | 2371 DebugLocalContext env; |
2372 v8::Isolate* isolate = env->GetIsolate(); | 2372 v8::Isolate* isolate = env->GetIsolate(); |
2373 v8::HandleScope scope(isolate); | 2373 v8::HandleScope scope(isolate); |
2374 env.ExposeDebug(); | 2374 env.ExposeDebug(); |
2375 | 2375 |
2376 // Create a function for checking the evaluation when hitting a break point. | 2376 // Create a function for checking the evaluation when hitting a break point. |
2377 evaluate_check_function = CompileFunction(&env, | 2377 evaluate_check_function = CompileFunction(&env, |
2378 evaluate_check_source, | 2378 evaluate_check_source, |
2379 "evaluate_check"); | 2379 "evaluate_check"); |
2380 // Register the debug event listener | 2380 // Register the debug event listener |
2381 v8::Debug::SetDebugEventListener2(DebugEventEvaluate); | 2381 v8::Debug::SetDebugEventListener(DebugEventEvaluate); |
2382 | 2382 |
2383 // Different expected vaules of x and a when in a break point (u = undefined, | 2383 // Different expected vaules of x and a when in a break point (u = undefined, |
2384 // d = Hello, world!). | 2384 // d = Hello, world!). |
2385 struct EvaluateCheck checks_uu[] = { | 2385 struct EvaluateCheck checks_uu[] = { |
2386 {"x", v8::Undefined(isolate)}, | 2386 {"x", v8::Undefined(isolate)}, |
2387 {"a", v8::Undefined(isolate)}, | 2387 {"a", v8::Undefined(isolate)}, |
2388 {NULL, v8::Handle<v8::Value>()} | 2388 {NULL, v8::Handle<v8::Value>()} |
2389 }; | 2389 }; |
2390 struct EvaluateCheck checks_hu[] = { | 2390 struct EvaluateCheck checks_hu[] = { |
2391 {"x", v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")}, | 2391 {"x", v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!")}, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2472 | 2472 |
2473 // Call bar setting breakpoint after a=x in barbar and parameter | 2473 // Call bar setting breakpoint after a=x in barbar and parameter |
2474 // "Hello, world!". | 2474 // "Hello, world!". |
2475 checks = checks_hh; | 2475 checks = checks_hh; |
2476 v8::Handle<v8::Value> argv_bar_3[2] = { | 2476 v8::Handle<v8::Value> argv_bar_3[2] = { |
2477 v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!"), | 2477 v8::String::NewFromUtf8(env->GetIsolate(), "Hello, world!"), |
2478 v8::Number::New(env->GetIsolate(), barbar_break_position + 1) | 2478 v8::Number::New(env->GetIsolate(), barbar_break_position + 1) |
2479 }; | 2479 }; |
2480 bar->Call(env->Global(), 2, argv_bar_3); | 2480 bar->Call(env->Global(), 2, argv_bar_3); |
2481 | 2481 |
2482 v8::Debug::SetDebugEventListener2(NULL); | 2482 v8::Debug::SetDebugEventListener(NULL); |
2483 CheckDebuggerUnloaded(); | 2483 CheckDebuggerUnloaded(); |
2484 } | 2484 } |
2485 | 2485 |
2486 | 2486 |
2487 int debugEventCount = 0; | 2487 int debugEventCount = 0; |
2488 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { | 2488 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { |
2489 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; | 2489 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; |
2490 } | 2490 } |
2491 | 2491 |
2492 | 2492 |
2493 // Test that the conditional breakpoints work event if code generation from | 2493 // Test that the conditional breakpoints work event if code generation from |
2494 // strings is prohibited in the debugee context. | 2494 // strings is prohibited in the debugee context. |
2495 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) { | 2495 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) { |
2496 DebugLocalContext env; | 2496 DebugLocalContext env; |
2497 v8::HandleScope scope(env->GetIsolate()); | 2497 v8::HandleScope scope(env->GetIsolate()); |
2498 env.ExposeDebug(); | 2498 env.ExposeDebug(); |
2499 | 2499 |
2500 v8::Debug::SetDebugEventListener2(CheckDebugEvent); | 2500 v8::Debug::SetDebugEventListener(CheckDebugEvent); |
2501 | 2501 |
2502 v8::Local<v8::Function> foo = CompileFunction(&env, | 2502 v8::Local<v8::Function> foo = CompileFunction(&env, |
2503 "function foo(x) {\n" | 2503 "function foo(x) {\n" |
2504 " var s = 'String value2';\n" | 2504 " var s = 'String value2';\n" |
2505 " return s + x;\n" | 2505 " return s + x;\n" |
2506 "}", | 2506 "}", |
2507 "foo"); | 2507 "foo"); |
2508 | 2508 |
2509 // Set conditional breakpoint with condition 'true'. | 2509 // Set conditional breakpoint with condition 'true'. |
2510 CompileRun("debug.Debug.setBreakPoint(foo, 2, 0, 'true')"); | 2510 CompileRun("debug.Debug.setBreakPoint(foo, 2, 0, 'true')"); |
2511 | 2511 |
2512 debugEventCount = 0; | 2512 debugEventCount = 0; |
2513 env->AllowCodeGenerationFromStrings(false); | 2513 env->AllowCodeGenerationFromStrings(false); |
2514 foo->Call(env->Global(), 0, NULL); | 2514 foo->Call(env->Global(), 0, NULL); |
2515 CHECK_EQ(1, debugEventCount); | 2515 CHECK_EQ(1, debugEventCount); |
2516 | 2516 |
2517 v8::Debug::SetDebugEventListener2(NULL); | 2517 v8::Debug::SetDebugEventListener(NULL); |
2518 CheckDebuggerUnloaded(); | 2518 CheckDebuggerUnloaded(); |
2519 } | 2519 } |
2520 | 2520 |
2521 | 2521 |
2522 bool checkedDebugEvals = true; | 2522 bool checkedDebugEvals = true; |
2523 v8::Handle<v8::Function> checkGlobalEvalFunction; | 2523 v8::Handle<v8::Function> checkGlobalEvalFunction; |
2524 v8::Handle<v8::Function> checkFrameEvalFunction; | 2524 v8::Handle<v8::Function> checkFrameEvalFunction; |
2525 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) { | 2525 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) { |
2526 if (eventDetails.GetEvent() == v8::Break) { | 2526 if (eventDetails.GetEvent() == v8::Break) { |
2527 ++debugEventCount; | 2527 ++debugEventCount; |
2528 v8::HandleScope handleScope(CcTest::isolate()); | 2528 v8::HandleScope handleScope(CcTest::isolate()); |
2529 | 2529 |
2530 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() }; | 2530 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() }; |
2531 CHECK(checkGlobalEvalFunction->Call( | 2531 CHECK(checkGlobalEvalFunction->Call( |
2532 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); | 2532 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); |
2533 CHECK(checkFrameEvalFunction->Call( | 2533 CHECK(checkFrameEvalFunction->Call( |
2534 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); | 2534 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); |
2535 } | 2535 } |
2536 } | 2536 } |
2537 | 2537 |
2538 | 2538 |
2539 // Test that the evaluation of expressions when a break point is hit generates | 2539 // Test that the evaluation of expressions when a break point is hit generates |
2540 // the correct results in case code generation from strings is disallowed in the | 2540 // the correct results in case code generation from strings is disallowed in the |
2541 // debugee context. | 2541 // debugee context. |
2542 TEST(DebugEvaluateWithCodeGenerationDisallowed) { | 2542 TEST(DebugEvaluateWithCodeGenerationDisallowed) { |
2543 DebugLocalContext env; | 2543 DebugLocalContext env; |
2544 v8::HandleScope scope(env->GetIsolate()); | 2544 v8::HandleScope scope(env->GetIsolate()); |
2545 env.ExposeDebug(); | 2545 env.ExposeDebug(); |
2546 | 2546 |
2547 v8::Debug::SetDebugEventListener2(CheckDebugEval); | 2547 v8::Debug::SetDebugEventListener(CheckDebugEval); |
2548 | 2548 |
2549 v8::Local<v8::Function> foo = CompileFunction(&env, | 2549 v8::Local<v8::Function> foo = CompileFunction(&env, |
2550 "var global = 'Global';\n" | 2550 "var global = 'Global';\n" |
2551 "function foo(x) {\n" | 2551 "function foo(x) {\n" |
2552 " var local = 'Local';\n" | 2552 " var local = 'Local';\n" |
2553 " debugger;\n" | 2553 " debugger;\n" |
2554 " return local + x;\n" | 2554 " return local + x;\n" |
2555 "}", | 2555 "}", |
2556 "foo"); | 2556 "foo"); |
2557 checkGlobalEvalFunction = CompileFunction(&env, | 2557 checkGlobalEvalFunction = CompileFunction(&env, |
2558 "function checkGlobalEval(exec_state) {\n" | 2558 "function checkGlobalEval(exec_state) {\n" |
2559 " return exec_state.evaluateGlobal('global').value() === 'Global';\n" | 2559 " return exec_state.evaluateGlobal('global').value() === 'Global';\n" |
2560 "}", | 2560 "}", |
2561 "checkGlobalEval"); | 2561 "checkGlobalEval"); |
2562 | 2562 |
2563 checkFrameEvalFunction = CompileFunction(&env, | 2563 checkFrameEvalFunction = CompileFunction(&env, |
2564 "function checkFrameEval(exec_state) {\n" | 2564 "function checkFrameEval(exec_state) {\n" |
2565 " return exec_state.frame(0).evaluate('local').value() === 'Local';\n" | 2565 " return exec_state.frame(0).evaluate('local').value() === 'Local';\n" |
2566 "}", | 2566 "}", |
2567 "checkFrameEval"); | 2567 "checkFrameEval"); |
2568 debugEventCount = 0; | 2568 debugEventCount = 0; |
2569 env->AllowCodeGenerationFromStrings(false); | 2569 env->AllowCodeGenerationFromStrings(false); |
2570 foo->Call(env->Global(), 0, NULL); | 2570 foo->Call(env->Global(), 0, NULL); |
2571 CHECK_EQ(1, debugEventCount); | 2571 CHECK_EQ(1, debugEventCount); |
2572 | 2572 |
2573 checkGlobalEvalFunction.Clear(); | 2573 checkGlobalEvalFunction.Clear(); |
2574 checkFrameEvalFunction.Clear(); | 2574 checkFrameEvalFunction.Clear(); |
2575 v8::Debug::SetDebugEventListener2(NULL); | 2575 v8::Debug::SetDebugEventListener(NULL); |
2576 CheckDebuggerUnloaded(); | 2576 CheckDebuggerUnloaded(); |
2577 } | 2577 } |
2578 | 2578 |
2579 | 2579 |
2580 // Copies a C string to a 16-bit string. Does not check for buffer overflow. | 2580 // Copies a C string to a 16-bit string. Does not check for buffer overflow. |
2581 // Does not use the V8 engine to convert strings, so it can be used | 2581 // Does not use the V8 engine to convert strings, so it can be used |
2582 // in any thread. Returns the length of the string. | 2582 // in any thread. Returns the length of the string. |
2583 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { | 2583 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { |
2584 int i; | 2584 int i; |
2585 for (i = 0; input_buffer[i] != '\0'; ++i) { | 2585 for (i = 0; input_buffer[i] != '\0'; ++i) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2670 EvaluateResult::kBufferSize); | 2670 EvaluateResult::kBufferSize); |
2671 if (res) { | 2671 if (res) { |
2672 process_debug_messages_data.next(); | 2672 process_debug_messages_data.next(); |
2673 } | 2673 } |
2674 } | 2674 } |
2675 | 2675 |
2676 | 2676 |
2677 // Test that the evaluation of expressions works even from ProcessDebugMessages | 2677 // Test that the evaluation of expressions works even from ProcessDebugMessages |
2678 // i.e. with empty stack. | 2678 // i.e. with empty stack. |
2679 TEST(DebugEvaluateWithoutStack) { | 2679 TEST(DebugEvaluateWithoutStack) { |
2680 v8::Debug::SetMessageHandler2(DebugProcessDebugMessagesHandler); | 2680 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler); |
2681 | 2681 |
2682 DebugLocalContext env; | 2682 DebugLocalContext env; |
2683 v8::HandleScope scope(env->GetIsolate()); | 2683 v8::HandleScope scope(env->GetIsolate()); |
2684 | 2684 |
2685 const char* source = | 2685 const char* source = |
2686 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; | 2686 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; |
2687 | 2687 |
2688 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source)) | 2688 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source)) |
2689 ->Run(); | 2689 ->Run(); |
2690 | 2690 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2726 | 2726 |
2727 v8::Debug::ProcessDebugMessages(); | 2727 v8::Debug::ProcessDebugMessages(); |
2728 | 2728 |
2729 CHECK_EQ(3, process_debug_messages_data.counter); | 2729 CHECK_EQ(3, process_debug_messages_data.counter); |
2730 | 2730 |
2731 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); | 2731 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); |
2732 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), | 2732 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), |
2733 0); | 2733 0); |
2734 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); | 2734 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); |
2735 | 2735 |
2736 v8::Debug::SetMessageHandler2(NULL); | 2736 v8::Debug::SetMessageHandler(NULL); |
2737 v8::Debug::SetDebugEventListener2(NULL); | 2737 v8::Debug::SetDebugEventListener(NULL); |
2738 CheckDebuggerUnloaded(); | 2738 CheckDebuggerUnloaded(); |
2739 } | 2739 } |
2740 | 2740 |
2741 | 2741 |
2742 // Simple test of the stepping mechanism using only store ICs. | 2742 // Simple test of the stepping mechanism using only store ICs. |
2743 TEST(DebugStepLinear) { | 2743 TEST(DebugStepLinear) { |
2744 DebugLocalContext env; | 2744 DebugLocalContext env; |
2745 v8::HandleScope scope(env->GetIsolate()); | 2745 v8::HandleScope scope(env->GetIsolate()); |
2746 | 2746 |
2747 // Create a function for testing stepping. | 2747 // Create a function for testing stepping. |
2748 v8::Local<v8::Function> foo = CompileFunction(&env, | 2748 v8::Local<v8::Function> foo = CompileFunction(&env, |
2749 "function foo(){a=1;b=1;c=1;}", | 2749 "function foo(){a=1;b=1;c=1;}", |
2750 "foo"); | 2750 "foo"); |
2751 | 2751 |
2752 // Run foo to allow it to get optimized. | 2752 // Run foo to allow it to get optimized. |
2753 CompileRun("a=0; b=0; c=0; foo();"); | 2753 CompileRun("a=0; b=0; c=0; foo();"); |
2754 | 2754 |
2755 SetBreakPoint(foo, 3); | 2755 SetBreakPoint(foo, 3); |
2756 | 2756 |
2757 // Register a debug event listener which steps and counts. | 2757 // Register a debug event listener which steps and counts. |
2758 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2758 v8::Debug::SetDebugEventListener(DebugEventStep); |
2759 | 2759 |
2760 step_action = StepIn; | 2760 step_action = StepIn; |
2761 break_point_hit_count = 0; | 2761 break_point_hit_count = 0; |
2762 foo->Call(env->Global(), 0, NULL); | 2762 foo->Call(env->Global(), 0, NULL); |
2763 | 2763 |
2764 // With stepping all break locations are hit. | 2764 // With stepping all break locations are hit. |
2765 CHECK_EQ(4, break_point_hit_count); | 2765 CHECK_EQ(4, break_point_hit_count); |
2766 | 2766 |
2767 v8::Debug::SetDebugEventListener2(NULL); | 2767 v8::Debug::SetDebugEventListener(NULL); |
2768 CheckDebuggerUnloaded(); | 2768 CheckDebuggerUnloaded(); |
2769 | 2769 |
2770 // Register a debug event listener which just counts. | 2770 // Register a debug event listener which just counts. |
2771 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 2771 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
2772 | 2772 |
2773 SetBreakPoint(foo, 3); | 2773 SetBreakPoint(foo, 3); |
2774 break_point_hit_count = 0; | 2774 break_point_hit_count = 0; |
2775 foo->Call(env->Global(), 0, NULL); | 2775 foo->Call(env->Global(), 0, NULL); |
2776 | 2776 |
2777 // Without stepping only active break points are hit. | 2777 // Without stepping only active break points are hit. |
2778 CHECK_EQ(1, break_point_hit_count); | 2778 CHECK_EQ(1, break_point_hit_count); |
2779 | 2779 |
2780 v8::Debug::SetDebugEventListener2(NULL); | 2780 v8::Debug::SetDebugEventListener(NULL); |
2781 CheckDebuggerUnloaded(); | 2781 CheckDebuggerUnloaded(); |
2782 } | 2782 } |
2783 | 2783 |
2784 | 2784 |
2785 // Test of the stepping mechanism for keyed load in a loop. | 2785 // Test of the stepping mechanism for keyed load in a loop. |
2786 TEST(DebugStepKeyedLoadLoop) { | 2786 TEST(DebugStepKeyedLoadLoop) { |
2787 DebugLocalContext env; | 2787 DebugLocalContext env; |
2788 v8::HandleScope scope(env->GetIsolate()); | 2788 v8::HandleScope scope(env->GetIsolate()); |
2789 | 2789 |
2790 // Register a debug event listener which steps and counts. | 2790 // Register a debug event listener which steps and counts. |
2791 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2791 v8::Debug::SetDebugEventListener(DebugEventStep); |
2792 | 2792 |
2793 // Create a function for testing stepping of keyed load. The statement 'y=1' | 2793 // Create a function for testing stepping of keyed load. The statement 'y=1' |
2794 // is there to have more than one breakable statement in the loop, TODO(315). | 2794 // is there to have more than one breakable statement in the loop, TODO(315). |
2795 v8::Local<v8::Function> foo = CompileFunction( | 2795 v8::Local<v8::Function> foo = CompileFunction( |
2796 &env, | 2796 &env, |
2797 "function foo(a) {\n" | 2797 "function foo(a) {\n" |
2798 " var x;\n" | 2798 " var x;\n" |
2799 " var len = a.length;\n" | 2799 " var len = a.length;\n" |
2800 " for (var i = 0; i < len; i++) {\n" | 2800 " for (var i = 0; i < len; i++) {\n" |
2801 " y = 1;\n" | 2801 " y = 1;\n" |
(...skipping 17 matching lines...) Expand all Loading... |
2819 | 2819 |
2820 // Set up break point and step through the function. | 2820 // Set up break point and step through the function. |
2821 SetBreakPoint(foo, 3); | 2821 SetBreakPoint(foo, 3); |
2822 step_action = StepNext; | 2822 step_action = StepNext; |
2823 break_point_hit_count = 0; | 2823 break_point_hit_count = 0; |
2824 foo->Call(env->Global(), kArgc, args); | 2824 foo->Call(env->Global(), kArgc, args); |
2825 | 2825 |
2826 // With stepping all break locations are hit. | 2826 // With stepping all break locations are hit. |
2827 CHECK_EQ(35, break_point_hit_count); | 2827 CHECK_EQ(35, break_point_hit_count); |
2828 | 2828 |
2829 v8::Debug::SetDebugEventListener2(NULL); | 2829 v8::Debug::SetDebugEventListener(NULL); |
2830 CheckDebuggerUnloaded(); | 2830 CheckDebuggerUnloaded(); |
2831 } | 2831 } |
2832 | 2832 |
2833 | 2833 |
2834 // Test of the stepping mechanism for keyed store in a loop. | 2834 // Test of the stepping mechanism for keyed store in a loop. |
2835 TEST(DebugStepKeyedStoreLoop) { | 2835 TEST(DebugStepKeyedStoreLoop) { |
2836 DebugLocalContext env; | 2836 DebugLocalContext env; |
2837 v8::HandleScope scope(env->GetIsolate()); | 2837 v8::HandleScope scope(env->GetIsolate()); |
2838 | 2838 |
2839 // Register a debug event listener which steps and counts. | 2839 // Register a debug event listener which steps and counts. |
2840 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2840 v8::Debug::SetDebugEventListener(DebugEventStep); |
2841 | 2841 |
2842 // Create a function for testing stepping of keyed store. The statement 'y=1' | 2842 // Create a function for testing stepping of keyed store. The statement 'y=1' |
2843 // is there to have more than one breakable statement in the loop, TODO(315). | 2843 // is there to have more than one breakable statement in the loop, TODO(315). |
2844 v8::Local<v8::Function> foo = CompileFunction( | 2844 v8::Local<v8::Function> foo = CompileFunction( |
2845 &env, | 2845 &env, |
2846 "function foo(a) {\n" | 2846 "function foo(a) {\n" |
2847 " var len = a.length;\n" | 2847 " var len = a.length;\n" |
2848 " for (var i = 0; i < len; i++) {\n" | 2848 " for (var i = 0; i < len; i++) {\n" |
2849 " y = 1;\n" | 2849 " y = 1;\n" |
2850 " a[i] = 42;\n" | 2850 " a[i] = 42;\n" |
(...skipping 16 matching lines...) Expand all Loading... |
2867 | 2867 |
2868 // Set up break point and step through the function. | 2868 // Set up break point and step through the function. |
2869 SetBreakPoint(foo, 3); | 2869 SetBreakPoint(foo, 3); |
2870 step_action = StepNext; | 2870 step_action = StepNext; |
2871 break_point_hit_count = 0; | 2871 break_point_hit_count = 0; |
2872 foo->Call(env->Global(), kArgc, args); | 2872 foo->Call(env->Global(), kArgc, args); |
2873 | 2873 |
2874 // With stepping all break locations are hit. | 2874 // With stepping all break locations are hit. |
2875 CHECK_EQ(34, break_point_hit_count); | 2875 CHECK_EQ(34, break_point_hit_count); |
2876 | 2876 |
2877 v8::Debug::SetDebugEventListener2(NULL); | 2877 v8::Debug::SetDebugEventListener(NULL); |
2878 CheckDebuggerUnloaded(); | 2878 CheckDebuggerUnloaded(); |
2879 } | 2879 } |
2880 | 2880 |
2881 | 2881 |
2882 // Test of the stepping mechanism for named load in a loop. | 2882 // Test of the stepping mechanism for named load in a loop. |
2883 TEST(DebugStepNamedLoadLoop) { | 2883 TEST(DebugStepNamedLoadLoop) { |
2884 DebugLocalContext env; | 2884 DebugLocalContext env; |
2885 v8::HandleScope scope(env->GetIsolate()); | 2885 v8::HandleScope scope(env->GetIsolate()); |
2886 | 2886 |
2887 // Register a debug event listener which steps and counts. | 2887 // Register a debug event listener which steps and counts. |
2888 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2888 v8::Debug::SetDebugEventListener(DebugEventStep); |
2889 | 2889 |
2890 // Create a function for testing stepping of named load. | 2890 // Create a function for testing stepping of named load. |
2891 v8::Local<v8::Function> foo = CompileFunction( | 2891 v8::Local<v8::Function> foo = CompileFunction( |
2892 &env, | 2892 &env, |
2893 "function foo() {\n" | 2893 "function foo() {\n" |
2894 " var a = [];\n" | 2894 " var a = [];\n" |
2895 " var s = \"\";\n" | 2895 " var s = \"\";\n" |
2896 " for (var i = 0; i < 10; i++) {\n" | 2896 " for (var i = 0; i < 10; i++) {\n" |
2897 " var v = new V(i, i + 1);\n" | 2897 " var v = new V(i, i + 1);\n" |
2898 " v.y;\n" | 2898 " v.y;\n" |
(...skipping 12 matching lines...) Expand all Loading... |
2911 | 2911 |
2912 // Set up break point and step through the function. | 2912 // Set up break point and step through the function. |
2913 SetBreakPoint(foo, 4); | 2913 SetBreakPoint(foo, 4); |
2914 step_action = StepNext; | 2914 step_action = StepNext; |
2915 break_point_hit_count = 0; | 2915 break_point_hit_count = 0; |
2916 foo->Call(env->Global(), 0, NULL); | 2916 foo->Call(env->Global(), 0, NULL); |
2917 | 2917 |
2918 // With stepping all break locations are hit. | 2918 // With stepping all break locations are hit. |
2919 CHECK_EQ(55, break_point_hit_count); | 2919 CHECK_EQ(55, break_point_hit_count); |
2920 | 2920 |
2921 v8::Debug::SetDebugEventListener2(NULL); | 2921 v8::Debug::SetDebugEventListener(NULL); |
2922 CheckDebuggerUnloaded(); | 2922 CheckDebuggerUnloaded(); |
2923 } | 2923 } |
2924 | 2924 |
2925 | 2925 |
2926 static void DoDebugStepNamedStoreLoop(int expected) { | 2926 static void DoDebugStepNamedStoreLoop(int expected) { |
2927 DebugLocalContext env; | 2927 DebugLocalContext env; |
2928 v8::HandleScope scope(env->GetIsolate()); | 2928 v8::HandleScope scope(env->GetIsolate()); |
2929 | 2929 |
2930 // Register a debug event listener which steps and counts. | 2930 // Register a debug event listener which steps and counts. |
2931 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2931 v8::Debug::SetDebugEventListener(DebugEventStep); |
2932 | 2932 |
2933 // Create a function for testing stepping of named store. | 2933 // Create a function for testing stepping of named store. |
2934 v8::Local<v8::Function> foo = CompileFunction( | 2934 v8::Local<v8::Function> foo = CompileFunction( |
2935 &env, | 2935 &env, |
2936 "function foo() {\n" | 2936 "function foo() {\n" |
2937 " var a = {a:1};\n" | 2937 " var a = {a:1};\n" |
2938 " for (var i = 0; i < 10; i++) {\n" | 2938 " for (var i = 0; i < 10; i++) {\n" |
2939 " a.a = 2\n" | 2939 " a.a = 2\n" |
2940 " }\n" | 2940 " }\n" |
2941 "}\n", | 2941 "}\n", |
2942 "foo"); | 2942 "foo"); |
2943 | 2943 |
2944 // Call function without any break points to ensure inlining is in place. | 2944 // Call function without any break points to ensure inlining is in place. |
2945 foo->Call(env->Global(), 0, NULL); | 2945 foo->Call(env->Global(), 0, NULL); |
2946 | 2946 |
2947 // Set up break point and step through the function. | 2947 // Set up break point and step through the function. |
2948 SetBreakPoint(foo, 3); | 2948 SetBreakPoint(foo, 3); |
2949 step_action = StepNext; | 2949 step_action = StepNext; |
2950 break_point_hit_count = 0; | 2950 break_point_hit_count = 0; |
2951 foo->Call(env->Global(), 0, NULL); | 2951 foo->Call(env->Global(), 0, NULL); |
2952 | 2952 |
2953 // With stepping all expected break locations are hit. | 2953 // With stepping all expected break locations are hit. |
2954 CHECK_EQ(expected, break_point_hit_count); | 2954 CHECK_EQ(expected, break_point_hit_count); |
2955 | 2955 |
2956 v8::Debug::SetDebugEventListener2(NULL); | 2956 v8::Debug::SetDebugEventListener(NULL); |
2957 CheckDebuggerUnloaded(); | 2957 CheckDebuggerUnloaded(); |
2958 } | 2958 } |
2959 | 2959 |
2960 | 2960 |
2961 // Test of the stepping mechanism for named load in a loop. | 2961 // Test of the stepping mechanism for named load in a loop. |
2962 TEST(DebugStepNamedStoreLoop) { | 2962 TEST(DebugStepNamedStoreLoop) { |
2963 DoDebugStepNamedStoreLoop(24); | 2963 DoDebugStepNamedStoreLoop(24); |
2964 } | 2964 } |
2965 | 2965 |
2966 | 2966 |
2967 // Test the stepping mechanism with different ICs. | 2967 // Test the stepping mechanism with different ICs. |
2968 TEST(DebugStepLinearMixedICs) { | 2968 TEST(DebugStepLinearMixedICs) { |
2969 DebugLocalContext env; | 2969 DebugLocalContext env; |
2970 v8::HandleScope scope(env->GetIsolate()); | 2970 v8::HandleScope scope(env->GetIsolate()); |
2971 | 2971 |
2972 // Register a debug event listener which steps and counts. | 2972 // Register a debug event listener which steps and counts. |
2973 v8::Debug::SetDebugEventListener2(DebugEventStep); | 2973 v8::Debug::SetDebugEventListener(DebugEventStep); |
2974 | 2974 |
2975 // Create a function for testing stepping. | 2975 // Create a function for testing stepping. |
2976 v8::Local<v8::Function> foo = CompileFunction(&env, | 2976 v8::Local<v8::Function> foo = CompileFunction(&env, |
2977 "function bar() {};" | 2977 "function bar() {};" |
2978 "function foo() {" | 2978 "function foo() {" |
2979 " var x;" | 2979 " var x;" |
2980 " var index='name';" | 2980 " var index='name';" |
2981 " var y = {};" | 2981 " var y = {};" |
2982 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo"); | 2982 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo"); |
2983 | 2983 |
2984 // Run functions to allow them to get optimized. | 2984 // Run functions to allow them to get optimized. |
2985 CompileRun("a=0; b=0; bar(); foo();"); | 2985 CompileRun("a=0; b=0; bar(); foo();"); |
2986 | 2986 |
2987 SetBreakPoint(foo, 0); | 2987 SetBreakPoint(foo, 0); |
2988 | 2988 |
2989 step_action = StepIn; | 2989 step_action = StepIn; |
2990 break_point_hit_count = 0; | 2990 break_point_hit_count = 0; |
2991 foo->Call(env->Global(), 0, NULL); | 2991 foo->Call(env->Global(), 0, NULL); |
2992 | 2992 |
2993 // With stepping all break locations are hit. | 2993 // With stepping all break locations are hit. |
2994 CHECK_EQ(11, break_point_hit_count); | 2994 CHECK_EQ(11, break_point_hit_count); |
2995 | 2995 |
2996 v8::Debug::SetDebugEventListener2(NULL); | 2996 v8::Debug::SetDebugEventListener(NULL); |
2997 CheckDebuggerUnloaded(); | 2997 CheckDebuggerUnloaded(); |
2998 | 2998 |
2999 // Register a debug event listener which just counts. | 2999 // Register a debug event listener which just counts. |
3000 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 3000 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
3001 | 3001 |
3002 SetBreakPoint(foo, 0); | 3002 SetBreakPoint(foo, 0); |
3003 break_point_hit_count = 0; | 3003 break_point_hit_count = 0; |
3004 foo->Call(env->Global(), 0, NULL); | 3004 foo->Call(env->Global(), 0, NULL); |
3005 | 3005 |
3006 // Without stepping only active break points are hit. | 3006 // Without stepping only active break points are hit. |
3007 CHECK_EQ(1, break_point_hit_count); | 3007 CHECK_EQ(1, break_point_hit_count); |
3008 | 3008 |
3009 v8::Debug::SetDebugEventListener2(NULL); | 3009 v8::Debug::SetDebugEventListener(NULL); |
3010 CheckDebuggerUnloaded(); | 3010 CheckDebuggerUnloaded(); |
3011 } | 3011 } |
3012 | 3012 |
3013 | 3013 |
3014 TEST(DebugStepDeclarations) { | 3014 TEST(DebugStepDeclarations) { |
3015 DebugLocalContext env; | 3015 DebugLocalContext env; |
3016 v8::HandleScope scope(env->GetIsolate()); | 3016 v8::HandleScope scope(env->GetIsolate()); |
3017 | 3017 |
3018 // Register a debug event listener which steps and counts. | 3018 // Register a debug event listener which steps and counts. |
3019 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3019 v8::Debug::SetDebugEventListener(DebugEventStep); |
3020 | 3020 |
3021 // Create a function for testing stepping. Run it to allow it to get | 3021 // Create a function for testing stepping. Run it to allow it to get |
3022 // optimized. | 3022 // optimized. |
3023 const char* src = "function foo() { " | 3023 const char* src = "function foo() { " |
3024 " var a;" | 3024 " var a;" |
3025 " var b = 1;" | 3025 " var b = 1;" |
3026 " var c = foo;" | 3026 " var c = foo;" |
3027 " var d = Math.floor;" | 3027 " var d = Math.floor;" |
3028 " var e = b + d(1.2);" | 3028 " var e = b + d(1.2);" |
3029 "}" | 3029 "}" |
3030 "foo()"; | 3030 "foo()"; |
3031 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3031 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3032 | 3032 |
3033 SetBreakPoint(foo, 0); | 3033 SetBreakPoint(foo, 0); |
3034 | 3034 |
3035 // Stepping through the declarations. | 3035 // Stepping through the declarations. |
3036 step_action = StepIn; | 3036 step_action = StepIn; |
3037 break_point_hit_count = 0; | 3037 break_point_hit_count = 0; |
3038 foo->Call(env->Global(), 0, NULL); | 3038 foo->Call(env->Global(), 0, NULL); |
3039 CHECK_EQ(6, break_point_hit_count); | 3039 CHECK_EQ(6, break_point_hit_count); |
3040 | 3040 |
3041 // Get rid of the debug event listener. | 3041 // Get rid of the debug event listener. |
3042 v8::Debug::SetDebugEventListener2(NULL); | 3042 v8::Debug::SetDebugEventListener(NULL); |
3043 CheckDebuggerUnloaded(); | 3043 CheckDebuggerUnloaded(); |
3044 } | 3044 } |
3045 | 3045 |
3046 | 3046 |
3047 TEST(DebugStepLocals) { | 3047 TEST(DebugStepLocals) { |
3048 DebugLocalContext env; | 3048 DebugLocalContext env; |
3049 v8::HandleScope scope(env->GetIsolate()); | 3049 v8::HandleScope scope(env->GetIsolate()); |
3050 | 3050 |
3051 // Register a debug event listener which steps and counts. | 3051 // Register a debug event listener which steps and counts. |
3052 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3052 v8::Debug::SetDebugEventListener(DebugEventStep); |
3053 | 3053 |
3054 // Create a function for testing stepping. Run it to allow it to get | 3054 // Create a function for testing stepping. Run it to allow it to get |
3055 // optimized. | 3055 // optimized. |
3056 const char* src = "function foo() { " | 3056 const char* src = "function foo() { " |
3057 " var a,b;" | 3057 " var a,b;" |
3058 " a = 1;" | 3058 " a = 1;" |
3059 " b = a + 2;" | 3059 " b = a + 2;" |
3060 " b = 1 + 2 + 3;" | 3060 " b = 1 + 2 + 3;" |
3061 " a = Math.floor(b);" | 3061 " a = Math.floor(b);" |
3062 "}" | 3062 "}" |
3063 "foo()"; | 3063 "foo()"; |
3064 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3064 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3065 | 3065 |
3066 SetBreakPoint(foo, 0); | 3066 SetBreakPoint(foo, 0); |
3067 | 3067 |
3068 // Stepping through the declarations. | 3068 // Stepping through the declarations. |
3069 step_action = StepIn; | 3069 step_action = StepIn; |
3070 break_point_hit_count = 0; | 3070 break_point_hit_count = 0; |
3071 foo->Call(env->Global(), 0, NULL); | 3071 foo->Call(env->Global(), 0, NULL); |
3072 CHECK_EQ(6, break_point_hit_count); | 3072 CHECK_EQ(6, break_point_hit_count); |
3073 | 3073 |
3074 // Get rid of the debug event listener. | 3074 // Get rid of the debug event listener. |
3075 v8::Debug::SetDebugEventListener2(NULL); | 3075 v8::Debug::SetDebugEventListener(NULL); |
3076 CheckDebuggerUnloaded(); | 3076 CheckDebuggerUnloaded(); |
3077 } | 3077 } |
3078 | 3078 |
3079 | 3079 |
3080 TEST(DebugStepIf) { | 3080 TEST(DebugStepIf) { |
3081 DebugLocalContext env; | 3081 DebugLocalContext env; |
3082 v8::Isolate* isolate = env->GetIsolate(); | 3082 v8::Isolate* isolate = env->GetIsolate(); |
3083 v8::HandleScope scope(isolate); | 3083 v8::HandleScope scope(isolate); |
3084 | 3084 |
3085 // Register a debug event listener which steps and counts. | 3085 // Register a debug event listener which steps and counts. |
3086 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3086 v8::Debug::SetDebugEventListener(DebugEventStep); |
3087 | 3087 |
3088 // Create a function for testing stepping. Run it to allow it to get | 3088 // Create a function for testing stepping. Run it to allow it to get |
3089 // optimized. | 3089 // optimized. |
3090 const int argc = 1; | 3090 const int argc = 1; |
3091 const char* src = "function foo(x) { " | 3091 const char* src = "function foo(x) { " |
3092 " a = 1;" | 3092 " a = 1;" |
3093 " if (x) {" | 3093 " if (x) {" |
3094 " b = 1;" | 3094 " b = 1;" |
3095 " } else {" | 3095 " } else {" |
3096 " c = 1;" | 3096 " c = 1;" |
(...skipping 12 matching lines...) Expand all Loading... |
3109 CHECK_EQ(4, break_point_hit_count); | 3109 CHECK_EQ(4, break_point_hit_count); |
3110 | 3110 |
3111 // Stepping through the false part. | 3111 // Stepping through the false part. |
3112 step_action = StepIn; | 3112 step_action = StepIn; |
3113 break_point_hit_count = 0; | 3113 break_point_hit_count = 0; |
3114 v8::Handle<v8::Value> argv_false[argc] = { v8::False(isolate) }; | 3114 v8::Handle<v8::Value> argv_false[argc] = { v8::False(isolate) }; |
3115 foo->Call(env->Global(), argc, argv_false); | 3115 foo->Call(env->Global(), argc, argv_false); |
3116 CHECK_EQ(5, break_point_hit_count); | 3116 CHECK_EQ(5, break_point_hit_count); |
3117 | 3117 |
3118 // Get rid of the debug event listener. | 3118 // Get rid of the debug event listener. |
3119 v8::Debug::SetDebugEventListener2(NULL); | 3119 v8::Debug::SetDebugEventListener(NULL); |
3120 CheckDebuggerUnloaded(); | 3120 CheckDebuggerUnloaded(); |
3121 } | 3121 } |
3122 | 3122 |
3123 | 3123 |
3124 TEST(DebugStepSwitch) { | 3124 TEST(DebugStepSwitch) { |
3125 DebugLocalContext env; | 3125 DebugLocalContext env; |
3126 v8::Isolate* isolate = env->GetIsolate(); | 3126 v8::Isolate* isolate = env->GetIsolate(); |
3127 v8::HandleScope scope(isolate); | 3127 v8::HandleScope scope(isolate); |
3128 | 3128 |
3129 // Register a debug event listener which steps and counts. | 3129 // Register a debug event listener which steps and counts. |
3130 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3130 v8::Debug::SetDebugEventListener(DebugEventStep); |
3131 | 3131 |
3132 // Create a function for testing stepping. Run it to allow it to get | 3132 // Create a function for testing stepping. Run it to allow it to get |
3133 // optimized. | 3133 // optimized. |
3134 const int argc = 1; | 3134 const int argc = 1; |
3135 const char* src = "function foo(x) { " | 3135 const char* src = "function foo(x) { " |
3136 " a = 1;" | 3136 " a = 1;" |
3137 " switch (x) {" | 3137 " switch (x) {" |
3138 " case 1:" | 3138 " case 1:" |
3139 " b = 1;" | 3139 " b = 1;" |
3140 " case 2:" | 3140 " case 2:" |
(...skipping 25 matching lines...) Expand all Loading... |
3166 CHECK_EQ(5, break_point_hit_count); | 3166 CHECK_EQ(5, break_point_hit_count); |
3167 | 3167 |
3168 // Last case. | 3168 // Last case. |
3169 step_action = StepIn; | 3169 step_action = StepIn; |
3170 break_point_hit_count = 0; | 3170 break_point_hit_count = 0; |
3171 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(isolate, 3) }; | 3171 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(isolate, 3) }; |
3172 foo->Call(env->Global(), argc, argv_3); | 3172 foo->Call(env->Global(), argc, argv_3); |
3173 CHECK_EQ(7, break_point_hit_count); | 3173 CHECK_EQ(7, break_point_hit_count); |
3174 | 3174 |
3175 // Get rid of the debug event listener. | 3175 // Get rid of the debug event listener. |
3176 v8::Debug::SetDebugEventListener2(NULL); | 3176 v8::Debug::SetDebugEventListener(NULL); |
3177 CheckDebuggerUnloaded(); | 3177 CheckDebuggerUnloaded(); |
3178 } | 3178 } |
3179 | 3179 |
3180 | 3180 |
3181 TEST(DebugStepWhile) { | 3181 TEST(DebugStepWhile) { |
3182 DebugLocalContext env; | 3182 DebugLocalContext env; |
3183 v8::Isolate* isolate = env->GetIsolate(); | 3183 v8::Isolate* isolate = env->GetIsolate(); |
3184 v8::HandleScope scope(isolate); | 3184 v8::HandleScope scope(isolate); |
3185 | 3185 |
3186 // Register a debug event listener which steps and counts. | 3186 // Register a debug event listener which steps and counts. |
3187 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3187 v8::Debug::SetDebugEventListener(DebugEventStep); |
3188 | 3188 |
3189 // Create a function for testing stepping. Run it to allow it to get | 3189 // Create a function for testing stepping. Run it to allow it to get |
3190 // optimized. | 3190 // optimized. |
3191 const int argc = 1; | 3191 const int argc = 1; |
3192 const char* src = "function foo(x) { " | 3192 const char* src = "function foo(x) { " |
3193 " var a = 0;" | 3193 " var a = 0;" |
3194 " while (a < x) {" | 3194 " while (a < x) {" |
3195 " a++;" | 3195 " a++;" |
3196 " }" | 3196 " }" |
3197 "}" | 3197 "}" |
3198 "foo()"; | 3198 "foo()"; |
3199 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3199 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3200 SetBreakPoint(foo, 8); // "var a = 0;" | 3200 SetBreakPoint(foo, 8); // "var a = 0;" |
3201 | 3201 |
3202 // Looping 10 times. | 3202 // Looping 10 times. |
3203 step_action = StepIn; | 3203 step_action = StepIn; |
3204 break_point_hit_count = 0; | 3204 break_point_hit_count = 0; |
3205 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) }; | 3205 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) }; |
3206 foo->Call(env->Global(), argc, argv_10); | 3206 foo->Call(env->Global(), argc, argv_10); |
3207 CHECK_EQ(22, break_point_hit_count); | 3207 CHECK_EQ(22, break_point_hit_count); |
3208 | 3208 |
3209 // Looping 100 times. | 3209 // Looping 100 times. |
3210 step_action = StepIn; | 3210 step_action = StepIn; |
3211 break_point_hit_count = 0; | 3211 break_point_hit_count = 0; |
3212 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; | 3212 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; |
3213 foo->Call(env->Global(), argc, argv_100); | 3213 foo->Call(env->Global(), argc, argv_100); |
3214 CHECK_EQ(202, break_point_hit_count); | 3214 CHECK_EQ(202, break_point_hit_count); |
3215 | 3215 |
3216 // Get rid of the debug event listener. | 3216 // Get rid of the debug event listener. |
3217 v8::Debug::SetDebugEventListener2(NULL); | 3217 v8::Debug::SetDebugEventListener(NULL); |
3218 CheckDebuggerUnloaded(); | 3218 CheckDebuggerUnloaded(); |
3219 } | 3219 } |
3220 | 3220 |
3221 | 3221 |
3222 TEST(DebugStepDoWhile) { | 3222 TEST(DebugStepDoWhile) { |
3223 DebugLocalContext env; | 3223 DebugLocalContext env; |
3224 v8::Isolate* isolate = env->GetIsolate(); | 3224 v8::Isolate* isolate = env->GetIsolate(); |
3225 v8::HandleScope scope(isolate); | 3225 v8::HandleScope scope(isolate); |
3226 | 3226 |
3227 // Register a debug event listener which steps and counts. | 3227 // Register a debug event listener which steps and counts. |
3228 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3228 v8::Debug::SetDebugEventListener(DebugEventStep); |
3229 | 3229 |
3230 // Create a function for testing stepping. Run it to allow it to get | 3230 // Create a function for testing stepping. Run it to allow it to get |
3231 // optimized. | 3231 // optimized. |
3232 const int argc = 1; | 3232 const int argc = 1; |
3233 const char* src = "function foo(x) { " | 3233 const char* src = "function foo(x) { " |
3234 " var a = 0;" | 3234 " var a = 0;" |
3235 " do {" | 3235 " do {" |
3236 " a++;" | 3236 " a++;" |
3237 " } while (a < x)" | 3237 " } while (a < x)" |
3238 "}" | 3238 "}" |
3239 "foo()"; | 3239 "foo()"; |
3240 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3240 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3241 SetBreakPoint(foo, 8); // "var a = 0;" | 3241 SetBreakPoint(foo, 8); // "var a = 0;" |
3242 | 3242 |
3243 // Looping 10 times. | 3243 // Looping 10 times. |
3244 step_action = StepIn; | 3244 step_action = StepIn; |
3245 break_point_hit_count = 0; | 3245 break_point_hit_count = 0; |
3246 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) }; | 3246 v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) }; |
3247 foo->Call(env->Global(), argc, argv_10); | 3247 foo->Call(env->Global(), argc, argv_10); |
3248 CHECK_EQ(22, break_point_hit_count); | 3248 CHECK_EQ(22, break_point_hit_count); |
3249 | 3249 |
3250 // Looping 100 times. | 3250 // Looping 100 times. |
3251 step_action = StepIn; | 3251 step_action = StepIn; |
3252 break_point_hit_count = 0; | 3252 break_point_hit_count = 0; |
3253 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; | 3253 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; |
3254 foo->Call(env->Global(), argc, argv_100); | 3254 foo->Call(env->Global(), argc, argv_100); |
3255 CHECK_EQ(202, break_point_hit_count); | 3255 CHECK_EQ(202, break_point_hit_count); |
3256 | 3256 |
3257 // Get rid of the debug event listener. | 3257 // Get rid of the debug event listener. |
3258 v8::Debug::SetDebugEventListener2(NULL); | 3258 v8::Debug::SetDebugEventListener(NULL); |
3259 CheckDebuggerUnloaded(); | 3259 CheckDebuggerUnloaded(); |
3260 } | 3260 } |
3261 | 3261 |
3262 | 3262 |
3263 TEST(DebugStepFor) { | 3263 TEST(DebugStepFor) { |
3264 DebugLocalContext env; | 3264 DebugLocalContext env; |
3265 v8::Isolate* isolate = env->GetIsolate(); | 3265 v8::Isolate* isolate = env->GetIsolate(); |
3266 v8::HandleScope scope(isolate); | 3266 v8::HandleScope scope(isolate); |
3267 | 3267 |
3268 // Register a debug event listener which steps and counts. | 3268 // Register a debug event listener which steps and counts. |
3269 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3269 v8::Debug::SetDebugEventListener(DebugEventStep); |
3270 | 3270 |
3271 // Create a function for testing stepping. Run it to allow it to get | 3271 // Create a function for testing stepping. Run it to allow it to get |
3272 // optimized. | 3272 // optimized. |
3273 const int argc = 1; | 3273 const int argc = 1; |
3274 const char* src = "function foo(x) { " | 3274 const char* src = "function foo(x) { " |
3275 " a = 1;" | 3275 " a = 1;" |
3276 " for (i = 0; i < x; i++) {" | 3276 " for (i = 0; i < x; i++) {" |
3277 " b = 1;" | 3277 " b = 1;" |
3278 " }" | 3278 " }" |
3279 "}" | 3279 "}" |
(...skipping 10 matching lines...) Expand all Loading... |
3290 CHECK_EQ(23, break_point_hit_count); | 3290 CHECK_EQ(23, break_point_hit_count); |
3291 | 3291 |
3292 // Looping 100 times. | 3292 // Looping 100 times. |
3293 step_action = StepIn; | 3293 step_action = StepIn; |
3294 break_point_hit_count = 0; | 3294 break_point_hit_count = 0; |
3295 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; | 3295 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; |
3296 foo->Call(env->Global(), argc, argv_100); | 3296 foo->Call(env->Global(), argc, argv_100); |
3297 CHECK_EQ(203, break_point_hit_count); | 3297 CHECK_EQ(203, break_point_hit_count); |
3298 | 3298 |
3299 // Get rid of the debug event listener. | 3299 // Get rid of the debug event listener. |
3300 v8::Debug::SetDebugEventListener2(NULL); | 3300 v8::Debug::SetDebugEventListener(NULL); |
3301 CheckDebuggerUnloaded(); | 3301 CheckDebuggerUnloaded(); |
3302 } | 3302 } |
3303 | 3303 |
3304 | 3304 |
3305 TEST(DebugStepForContinue) { | 3305 TEST(DebugStepForContinue) { |
3306 DebugLocalContext env; | 3306 DebugLocalContext env; |
3307 v8::Isolate* isolate = env->GetIsolate(); | 3307 v8::Isolate* isolate = env->GetIsolate(); |
3308 v8::HandleScope scope(isolate); | 3308 v8::HandleScope scope(isolate); |
3309 | 3309 |
3310 // Register a debug event listener which steps and counts. | 3310 // Register a debug event listener which steps and counts. |
3311 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3311 v8::Debug::SetDebugEventListener(DebugEventStep); |
3312 | 3312 |
3313 // Create a function for testing stepping. Run it to allow it to get | 3313 // Create a function for testing stepping. Run it to allow it to get |
3314 // optimized. | 3314 // optimized. |
3315 const int argc = 1; | 3315 const int argc = 1; |
3316 const char* src = "function foo(x) { " | 3316 const char* src = "function foo(x) { " |
3317 " var a = 0;" | 3317 " var a = 0;" |
3318 " var b = 0;" | 3318 " var b = 0;" |
3319 " var c = 0;" | 3319 " var c = 0;" |
3320 " for (var i = 0; i < x; i++) {" | 3320 " for (var i = 0; i < x; i++) {" |
3321 " a++;" | 3321 " a++;" |
(...skipping 20 matching lines...) Expand all Loading... |
3342 | 3342 |
3343 // Looping 100 times. | 3343 // Looping 100 times. |
3344 step_action = StepIn; | 3344 step_action = StepIn; |
3345 break_point_hit_count = 0; | 3345 break_point_hit_count = 0; |
3346 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; | 3346 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; |
3347 result = foo->Call(env->Global(), argc, argv_100); | 3347 result = foo->Call(env->Global(), argc, argv_100); |
3348 CHECK_EQ(50, result->Int32Value()); | 3348 CHECK_EQ(50, result->Int32Value()); |
3349 CHECK_EQ(457, break_point_hit_count); | 3349 CHECK_EQ(457, break_point_hit_count); |
3350 | 3350 |
3351 // Get rid of the debug event listener. | 3351 // Get rid of the debug event listener. |
3352 v8::Debug::SetDebugEventListener2(NULL); | 3352 v8::Debug::SetDebugEventListener(NULL); |
3353 CheckDebuggerUnloaded(); | 3353 CheckDebuggerUnloaded(); |
3354 } | 3354 } |
3355 | 3355 |
3356 | 3356 |
3357 TEST(DebugStepForBreak) { | 3357 TEST(DebugStepForBreak) { |
3358 DebugLocalContext env; | 3358 DebugLocalContext env; |
3359 v8::Isolate* isolate = env->GetIsolate(); | 3359 v8::Isolate* isolate = env->GetIsolate(); |
3360 v8::HandleScope scope(isolate); | 3360 v8::HandleScope scope(isolate); |
3361 | 3361 |
3362 // Register a debug event listener which steps and counts. | 3362 // Register a debug event listener which steps and counts. |
3363 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3363 v8::Debug::SetDebugEventListener(DebugEventStep); |
3364 | 3364 |
3365 // Create a function for testing stepping. Run it to allow it to get | 3365 // Create a function for testing stepping. Run it to allow it to get |
3366 // optimized. | 3366 // optimized. |
3367 const int argc = 1; | 3367 const int argc = 1; |
3368 const char* src = "function foo(x) { " | 3368 const char* src = "function foo(x) { " |
3369 " var a = 0;" | 3369 " var a = 0;" |
3370 " var b = 0;" | 3370 " var b = 0;" |
3371 " var c = 0;" | 3371 " var c = 0;" |
3372 " for (var i = 0; i < 1000; i++) {" | 3372 " for (var i = 0; i < 1000; i++) {" |
3373 " a++;" | 3373 " a++;" |
(...skipping 21 matching lines...) Expand all Loading... |
3395 | 3395 |
3396 // Looping 100 times. | 3396 // Looping 100 times. |
3397 step_action = StepIn; | 3397 step_action = StepIn; |
3398 break_point_hit_count = 0; | 3398 break_point_hit_count = 0; |
3399 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; | 3399 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; |
3400 result = foo->Call(env->Global(), argc, argv_100); | 3400 result = foo->Call(env->Global(), argc, argv_100); |
3401 CHECK_EQ(99, result->Int32Value()); | 3401 CHECK_EQ(99, result->Int32Value()); |
3402 CHECK_EQ(505, break_point_hit_count); | 3402 CHECK_EQ(505, break_point_hit_count); |
3403 | 3403 |
3404 // Get rid of the debug event listener. | 3404 // Get rid of the debug event listener. |
3405 v8::Debug::SetDebugEventListener2(NULL); | 3405 v8::Debug::SetDebugEventListener(NULL); |
3406 CheckDebuggerUnloaded(); | 3406 CheckDebuggerUnloaded(); |
3407 } | 3407 } |
3408 | 3408 |
3409 | 3409 |
3410 TEST(DebugStepForIn) { | 3410 TEST(DebugStepForIn) { |
3411 DebugLocalContext env; | 3411 DebugLocalContext env; |
3412 v8::HandleScope scope(env->GetIsolate()); | 3412 v8::HandleScope scope(env->GetIsolate()); |
3413 | 3413 |
3414 // Register a debug event listener which steps and counts. | 3414 // Register a debug event listener which steps and counts. |
3415 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3415 v8::Debug::SetDebugEventListener(DebugEventStep); |
3416 | 3416 |
3417 // Create a function for testing stepping. Run it to allow it to get | 3417 // Create a function for testing stepping. Run it to allow it to get |
3418 // optimized. | 3418 // optimized. |
3419 v8::Local<v8::Function> foo; | 3419 v8::Local<v8::Function> foo; |
3420 const char* src_1 = "function foo() { " | 3420 const char* src_1 = "function foo() { " |
3421 " var a = [1, 2];" | 3421 " var a = [1, 2];" |
3422 " for (x in a) {" | 3422 " for (x in a) {" |
3423 " b = 0;" | 3423 " b = 0;" |
3424 " }" | 3424 " }" |
3425 "}" | 3425 "}" |
(...skipping 17 matching lines...) Expand all Loading... |
3443 "foo()"; | 3443 "foo()"; |
3444 foo = CompileFunction(&env, src_2, "foo"); | 3444 foo = CompileFunction(&env, src_2, "foo"); |
3445 SetBreakPoint(foo, 0); // "var a = ..." | 3445 SetBreakPoint(foo, 0); // "var a = ..." |
3446 | 3446 |
3447 step_action = StepIn; | 3447 step_action = StepIn; |
3448 break_point_hit_count = 0; | 3448 break_point_hit_count = 0; |
3449 foo->Call(env->Global(), 0, NULL); | 3449 foo->Call(env->Global(), 0, NULL); |
3450 CHECK_EQ(8, break_point_hit_count); | 3450 CHECK_EQ(8, break_point_hit_count); |
3451 | 3451 |
3452 // Get rid of the debug event listener. | 3452 // Get rid of the debug event listener. |
3453 v8::Debug::SetDebugEventListener2(NULL); | 3453 v8::Debug::SetDebugEventListener(NULL); |
3454 CheckDebuggerUnloaded(); | 3454 CheckDebuggerUnloaded(); |
3455 } | 3455 } |
3456 | 3456 |
3457 | 3457 |
3458 TEST(DebugStepWith) { | 3458 TEST(DebugStepWith) { |
3459 DebugLocalContext env; | 3459 DebugLocalContext env; |
3460 v8::HandleScope scope(env->GetIsolate()); | 3460 v8::HandleScope scope(env->GetIsolate()); |
3461 | 3461 |
3462 // Register a debug event listener which steps and counts. | 3462 // Register a debug event listener which steps and counts. |
3463 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3463 v8::Debug::SetDebugEventListener(DebugEventStep); |
3464 | 3464 |
3465 // Create a function for testing stepping. Run it to allow it to get | 3465 // Create a function for testing stepping. Run it to allow it to get |
3466 // optimized. | 3466 // optimized. |
3467 const char* src = "function foo(x) { " | 3467 const char* src = "function foo(x) { " |
3468 " var a = {};" | 3468 " var a = {};" |
3469 " with (a) {}" | 3469 " with (a) {}" |
3470 " with (b) {}" | 3470 " with (b) {}" |
3471 "}" | 3471 "}" |
3472 "foo()"; | 3472 "foo()"; |
3473 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "b"), | 3473 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "b"), |
3474 v8::Object::New(env->GetIsolate())); | 3474 v8::Object::New(env->GetIsolate())); |
3475 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3475 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3476 v8::Handle<v8::Value> result; | 3476 v8::Handle<v8::Value> result; |
3477 SetBreakPoint(foo, 8); // "var a = {};" | 3477 SetBreakPoint(foo, 8); // "var a = {};" |
3478 | 3478 |
3479 step_action = StepIn; | 3479 step_action = StepIn; |
3480 break_point_hit_count = 0; | 3480 break_point_hit_count = 0; |
3481 foo->Call(env->Global(), 0, NULL); | 3481 foo->Call(env->Global(), 0, NULL); |
3482 CHECK_EQ(4, break_point_hit_count); | 3482 CHECK_EQ(4, break_point_hit_count); |
3483 | 3483 |
3484 // Get rid of the debug event listener. | 3484 // Get rid of the debug event listener. |
3485 v8::Debug::SetDebugEventListener2(NULL); | 3485 v8::Debug::SetDebugEventListener(NULL); |
3486 CheckDebuggerUnloaded(); | 3486 CheckDebuggerUnloaded(); |
3487 } | 3487 } |
3488 | 3488 |
3489 | 3489 |
3490 TEST(DebugConditional) { | 3490 TEST(DebugConditional) { |
3491 DebugLocalContext env; | 3491 DebugLocalContext env; |
3492 v8::Isolate* isolate = env->GetIsolate(); | 3492 v8::Isolate* isolate = env->GetIsolate(); |
3493 v8::HandleScope scope(isolate); | 3493 v8::HandleScope scope(isolate); |
3494 | 3494 |
3495 // Register a debug event listener which steps and counts. | 3495 // Register a debug event listener which steps and counts. |
3496 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3496 v8::Debug::SetDebugEventListener(DebugEventStep); |
3497 | 3497 |
3498 // Create a function for testing stepping. Run it to allow it to get | 3498 // Create a function for testing stepping. Run it to allow it to get |
3499 // optimized. | 3499 // optimized. |
3500 const char* src = "function foo(x) { " | 3500 const char* src = "function foo(x) { " |
3501 " var a;" | 3501 " var a;" |
3502 " a = x ? 1 : 2;" | 3502 " a = x ? 1 : 2;" |
3503 " return a;" | 3503 " return a;" |
3504 "}" | 3504 "}" |
3505 "foo()"; | 3505 "foo()"; |
3506 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); | 3506 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); |
3507 SetBreakPoint(foo, 0); // "var a;" | 3507 SetBreakPoint(foo, 0); // "var a;" |
3508 | 3508 |
3509 step_action = StepIn; | 3509 step_action = StepIn; |
3510 break_point_hit_count = 0; | 3510 break_point_hit_count = 0; |
3511 foo->Call(env->Global(), 0, NULL); | 3511 foo->Call(env->Global(), 0, NULL); |
3512 CHECK_EQ(5, break_point_hit_count); | 3512 CHECK_EQ(5, break_point_hit_count); |
3513 | 3513 |
3514 step_action = StepIn; | 3514 step_action = StepIn; |
3515 break_point_hit_count = 0; | 3515 break_point_hit_count = 0; |
3516 const int argc = 1; | 3516 const int argc = 1; |
3517 v8::Handle<v8::Value> argv_true[argc] = { v8::True(isolate) }; | 3517 v8::Handle<v8::Value> argv_true[argc] = { v8::True(isolate) }; |
3518 foo->Call(env->Global(), argc, argv_true); | 3518 foo->Call(env->Global(), argc, argv_true); |
3519 CHECK_EQ(5, break_point_hit_count); | 3519 CHECK_EQ(5, break_point_hit_count); |
3520 | 3520 |
3521 // Get rid of the debug event listener. | 3521 // Get rid of the debug event listener. |
3522 v8::Debug::SetDebugEventListener2(NULL); | 3522 v8::Debug::SetDebugEventListener(NULL); |
3523 CheckDebuggerUnloaded(); | 3523 CheckDebuggerUnloaded(); |
3524 } | 3524 } |
3525 | 3525 |
3526 | 3526 |
3527 TEST(StepInOutSimple) { | 3527 TEST(StepInOutSimple) { |
3528 DebugLocalContext env; | 3528 DebugLocalContext env; |
3529 v8::HandleScope scope(env->GetIsolate()); | 3529 v8::HandleScope scope(env->GetIsolate()); |
3530 | 3530 |
3531 // Create a function for checking the function when hitting a break point. | 3531 // Create a function for checking the function when hitting a break point. |
3532 frame_function_name = CompileFunction(&env, | 3532 frame_function_name = CompileFunction(&env, |
3533 frame_function_name_source, | 3533 frame_function_name_source, |
3534 "frame_function_name"); | 3534 "frame_function_name"); |
3535 | 3535 |
3536 // Register a debug event listener which steps and counts. | 3536 // Register a debug event listener which steps and counts. |
3537 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); | 3537 v8::Debug::SetDebugEventListener(DebugEventStepSequence); |
3538 | 3538 |
3539 // Create a function for testing stepping. Run it to allow it to get | 3539 // Create a function for testing stepping. Run it to allow it to get |
3540 // optimized. | 3540 // optimized. |
3541 const char* src = "function a() {b();c();}; " | 3541 const char* src = "function a() {b();c();}; " |
3542 "function b() {c();}; " | 3542 "function b() {c();}; " |
3543 "function c() {}; " | 3543 "function c() {}; " |
3544 "a(); b(); c()"; | 3544 "a(); b(); c()"; |
3545 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3545 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3546 SetBreakPoint(a, 0); | 3546 SetBreakPoint(a, 0); |
3547 | 3547 |
(...skipping 15 matching lines...) Expand all Loading... |
3563 | 3563 |
3564 // Step through invocation of a with step out. | 3564 // Step through invocation of a with step out. |
3565 step_action = StepOut; | 3565 step_action = StepOut; |
3566 break_point_hit_count = 0; | 3566 break_point_hit_count = 0; |
3567 expected_step_sequence = "a"; | 3567 expected_step_sequence = "a"; |
3568 a->Call(env->Global(), 0, NULL); | 3568 a->Call(env->Global(), 0, NULL); |
3569 CHECK_EQ(StrLength(expected_step_sequence), | 3569 CHECK_EQ(StrLength(expected_step_sequence), |
3570 break_point_hit_count); | 3570 break_point_hit_count); |
3571 | 3571 |
3572 // Get rid of the debug event listener. | 3572 // Get rid of the debug event listener. |
3573 v8::Debug::SetDebugEventListener2(NULL); | 3573 v8::Debug::SetDebugEventListener(NULL); |
3574 CheckDebuggerUnloaded(); | 3574 CheckDebuggerUnloaded(); |
3575 } | 3575 } |
3576 | 3576 |
3577 | 3577 |
3578 TEST(StepInOutTree) { | 3578 TEST(StepInOutTree) { |
3579 DebugLocalContext env; | 3579 DebugLocalContext env; |
3580 v8::HandleScope scope(env->GetIsolate()); | 3580 v8::HandleScope scope(env->GetIsolate()); |
3581 | 3581 |
3582 // Create a function for checking the function when hitting a break point. | 3582 // Create a function for checking the function when hitting a break point. |
3583 frame_function_name = CompileFunction(&env, | 3583 frame_function_name = CompileFunction(&env, |
3584 frame_function_name_source, | 3584 frame_function_name_source, |
3585 "frame_function_name"); | 3585 "frame_function_name"); |
3586 | 3586 |
3587 // Register a debug event listener which steps and counts. | 3587 // Register a debug event listener which steps and counts. |
3588 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); | 3588 v8::Debug::SetDebugEventListener(DebugEventStepSequence); |
3589 | 3589 |
3590 // Create a function for testing stepping. Run it to allow it to get | 3590 // Create a function for testing stepping. Run it to allow it to get |
3591 // optimized. | 3591 // optimized. |
3592 const char* src = "function a() {b(c(d()),d());c(d());d()}; " | 3592 const char* src = "function a() {b(c(d()),d());c(d());d()}; " |
3593 "function b(x,y) {c();}; " | 3593 "function b(x,y) {c();}; " |
3594 "function c(x) {}; " | 3594 "function c(x) {}; " |
3595 "function d() {}; " | 3595 "function d() {}; " |
3596 "a(); b(); c(); d()"; | 3596 "a(); b(); c(); d()"; |
3597 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3597 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3598 SetBreakPoint(a, 0); | 3598 SetBreakPoint(a, 0); |
(...skipping 16 matching lines...) Expand all Loading... |
3615 | 3615 |
3616 // Step through invocation of a with step out. | 3616 // Step through invocation of a with step out. |
3617 step_action = StepOut; | 3617 step_action = StepOut; |
3618 break_point_hit_count = 0; | 3618 break_point_hit_count = 0; |
3619 expected_step_sequence = "a"; | 3619 expected_step_sequence = "a"; |
3620 a->Call(env->Global(), 0, NULL); | 3620 a->Call(env->Global(), 0, NULL); |
3621 CHECK_EQ(StrLength(expected_step_sequence), | 3621 CHECK_EQ(StrLength(expected_step_sequence), |
3622 break_point_hit_count); | 3622 break_point_hit_count); |
3623 | 3623 |
3624 // Get rid of the debug event listener. | 3624 // Get rid of the debug event listener. |
3625 v8::Debug::SetDebugEventListener2(NULL); | 3625 v8::Debug::SetDebugEventListener(NULL); |
3626 CheckDebuggerUnloaded(true); | 3626 CheckDebuggerUnloaded(true); |
3627 } | 3627 } |
3628 | 3628 |
3629 | 3629 |
3630 TEST(StepInOutBranch) { | 3630 TEST(StepInOutBranch) { |
3631 DebugLocalContext env; | 3631 DebugLocalContext env; |
3632 v8::HandleScope scope(env->GetIsolate()); | 3632 v8::HandleScope scope(env->GetIsolate()); |
3633 | 3633 |
3634 // Create a function for checking the function when hitting a break point. | 3634 // Create a function for checking the function when hitting a break point. |
3635 frame_function_name = CompileFunction(&env, | 3635 frame_function_name = CompileFunction(&env, |
3636 frame_function_name_source, | 3636 frame_function_name_source, |
3637 "frame_function_name"); | 3637 "frame_function_name"); |
3638 | 3638 |
3639 // Register a debug event listener which steps and counts. | 3639 // Register a debug event listener which steps and counts. |
3640 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); | 3640 v8::Debug::SetDebugEventListener(DebugEventStepSequence); |
3641 | 3641 |
3642 // Create a function for testing stepping. Run it to allow it to get | 3642 // Create a function for testing stepping. Run it to allow it to get |
3643 // optimized. | 3643 // optimized. |
3644 const char* src = "function a() {b(false);c();}; " | 3644 const char* src = "function a() {b(false);c();}; " |
3645 "function b(x) {if(x){c();};}; " | 3645 "function b(x) {if(x){c();};}; " |
3646 "function c() {}; " | 3646 "function c() {}; " |
3647 "a(); b(); c()"; | 3647 "a(); b(); c()"; |
3648 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); | 3648 v8::Local<v8::Function> a = CompileFunction(&env, src, "a"); |
3649 SetBreakPoint(a, 0); | 3649 SetBreakPoint(a, 0); |
3650 | 3650 |
3651 // Step through invocation of a. | 3651 // Step through invocation of a. |
3652 step_action = StepIn; | 3652 step_action = StepIn; |
3653 break_point_hit_count = 0; | 3653 break_point_hit_count = 0; |
3654 expected_step_sequence = "abbaca"; | 3654 expected_step_sequence = "abbaca"; |
3655 a->Call(env->Global(), 0, NULL); | 3655 a->Call(env->Global(), 0, NULL); |
3656 CHECK_EQ(StrLength(expected_step_sequence), | 3656 CHECK_EQ(StrLength(expected_step_sequence), |
3657 break_point_hit_count); | 3657 break_point_hit_count); |
3658 | 3658 |
3659 // Get rid of the debug event listener. | 3659 // Get rid of the debug event listener. |
3660 v8::Debug::SetDebugEventListener2(NULL); | 3660 v8::Debug::SetDebugEventListener(NULL); |
3661 CheckDebuggerUnloaded(); | 3661 CheckDebuggerUnloaded(); |
3662 } | 3662 } |
3663 | 3663 |
3664 | 3664 |
3665 // Test that step in does not step into native functions. | 3665 // Test that step in does not step into native functions. |
3666 TEST(DebugStepNatives) { | 3666 TEST(DebugStepNatives) { |
3667 DebugLocalContext env; | 3667 DebugLocalContext env; |
3668 v8::HandleScope scope(env->GetIsolate()); | 3668 v8::HandleScope scope(env->GetIsolate()); |
3669 | 3669 |
3670 // Create a function for testing stepping. | 3670 // Create a function for testing stepping. |
3671 v8::Local<v8::Function> foo = CompileFunction( | 3671 v8::Local<v8::Function> foo = CompileFunction( |
3672 &env, | 3672 &env, |
3673 "function foo(){debugger;Math.sin(1);}", | 3673 "function foo(){debugger;Math.sin(1);}", |
3674 "foo"); | 3674 "foo"); |
3675 | 3675 |
3676 // Register a debug event listener which steps and counts. | 3676 // Register a debug event listener which steps and counts. |
3677 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3677 v8::Debug::SetDebugEventListener(DebugEventStep); |
3678 | 3678 |
3679 step_action = StepIn; | 3679 step_action = StepIn; |
3680 break_point_hit_count = 0; | 3680 break_point_hit_count = 0; |
3681 foo->Call(env->Global(), 0, NULL); | 3681 foo->Call(env->Global(), 0, NULL); |
3682 | 3682 |
3683 // With stepping all break locations are hit. | 3683 // With stepping all break locations are hit. |
3684 CHECK_EQ(3, break_point_hit_count); | 3684 CHECK_EQ(3, break_point_hit_count); |
3685 | 3685 |
3686 v8::Debug::SetDebugEventListener2(NULL); | 3686 v8::Debug::SetDebugEventListener(NULL); |
3687 CheckDebuggerUnloaded(); | 3687 CheckDebuggerUnloaded(); |
3688 | 3688 |
3689 // Register a debug event listener which just counts. | 3689 // Register a debug event listener which just counts. |
3690 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 3690 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
3691 | 3691 |
3692 break_point_hit_count = 0; | 3692 break_point_hit_count = 0; |
3693 foo->Call(env->Global(), 0, NULL); | 3693 foo->Call(env->Global(), 0, NULL); |
3694 | 3694 |
3695 // Without stepping only active break points are hit. | 3695 // Without stepping only active break points are hit. |
3696 CHECK_EQ(1, break_point_hit_count); | 3696 CHECK_EQ(1, break_point_hit_count); |
3697 | 3697 |
3698 v8::Debug::SetDebugEventListener2(NULL); | 3698 v8::Debug::SetDebugEventListener(NULL); |
3699 CheckDebuggerUnloaded(); | 3699 CheckDebuggerUnloaded(); |
3700 } | 3700 } |
3701 | 3701 |
3702 | 3702 |
3703 // Test that step in works with function.apply. | 3703 // Test that step in works with function.apply. |
3704 TEST(DebugStepFunctionApply) { | 3704 TEST(DebugStepFunctionApply) { |
3705 DebugLocalContext env; | 3705 DebugLocalContext env; |
3706 v8::HandleScope scope(env->GetIsolate()); | 3706 v8::HandleScope scope(env->GetIsolate()); |
3707 | 3707 |
3708 // Create a function for testing stepping. | 3708 // Create a function for testing stepping. |
3709 v8::Local<v8::Function> foo = CompileFunction( | 3709 v8::Local<v8::Function> foo = CompileFunction( |
3710 &env, | 3710 &env, |
3711 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" | 3711 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" |
3712 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", | 3712 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", |
3713 "foo"); | 3713 "foo"); |
3714 | 3714 |
3715 // Register a debug event listener which steps and counts. | 3715 // Register a debug event listener which steps and counts. |
3716 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3716 v8::Debug::SetDebugEventListener(DebugEventStep); |
3717 | 3717 |
3718 step_action = StepIn; | 3718 step_action = StepIn; |
3719 break_point_hit_count = 0; | 3719 break_point_hit_count = 0; |
3720 foo->Call(env->Global(), 0, NULL); | 3720 foo->Call(env->Global(), 0, NULL); |
3721 | 3721 |
3722 // With stepping all break locations are hit. | 3722 // With stepping all break locations are hit. |
3723 CHECK_EQ(7, break_point_hit_count); | 3723 CHECK_EQ(7, break_point_hit_count); |
3724 | 3724 |
3725 v8::Debug::SetDebugEventListener2(NULL); | 3725 v8::Debug::SetDebugEventListener(NULL); |
3726 CheckDebuggerUnloaded(); | 3726 CheckDebuggerUnloaded(); |
3727 | 3727 |
3728 // Register a debug event listener which just counts. | 3728 // Register a debug event listener which just counts. |
3729 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 3729 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
3730 | 3730 |
3731 break_point_hit_count = 0; | 3731 break_point_hit_count = 0; |
3732 foo->Call(env->Global(), 0, NULL); | 3732 foo->Call(env->Global(), 0, NULL); |
3733 | 3733 |
3734 // Without stepping only the debugger statement is hit. | 3734 // Without stepping only the debugger statement is hit. |
3735 CHECK_EQ(1, break_point_hit_count); | 3735 CHECK_EQ(1, break_point_hit_count); |
3736 | 3736 |
3737 v8::Debug::SetDebugEventListener2(NULL); | 3737 v8::Debug::SetDebugEventListener(NULL); |
3738 CheckDebuggerUnloaded(); | 3738 CheckDebuggerUnloaded(); |
3739 } | 3739 } |
3740 | 3740 |
3741 | 3741 |
3742 // Test that step in works with function.call. | 3742 // Test that step in works with function.call. |
3743 TEST(DebugStepFunctionCall) { | 3743 TEST(DebugStepFunctionCall) { |
3744 DebugLocalContext env; | 3744 DebugLocalContext env; |
3745 v8::Isolate* isolate = env->GetIsolate(); | 3745 v8::Isolate* isolate = env->GetIsolate(); |
3746 v8::HandleScope scope(isolate); | 3746 v8::HandleScope scope(isolate); |
3747 | 3747 |
3748 // Create a function for testing stepping. | 3748 // Create a function for testing stepping. |
3749 v8::Local<v8::Function> foo = CompileFunction( | 3749 v8::Local<v8::Function> foo = CompileFunction( |
3750 &env, | 3750 &env, |
3751 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" | 3751 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" |
3752 "function foo(a){ debugger;" | 3752 "function foo(a){ debugger;" |
3753 " if (a) {" | 3753 " if (a) {" |
3754 " bar.call(this, 1, 2, 3);" | 3754 " bar.call(this, 1, 2, 3);" |
3755 " } else {" | 3755 " } else {" |
3756 " bar.call(this, 0);" | 3756 " bar.call(this, 0);" |
3757 " }" | 3757 " }" |
3758 "}", | 3758 "}", |
3759 "foo"); | 3759 "foo"); |
3760 | 3760 |
3761 // Register a debug event listener which steps and counts. | 3761 // Register a debug event listener which steps and counts. |
3762 v8::Debug::SetDebugEventListener2(DebugEventStep); | 3762 v8::Debug::SetDebugEventListener(DebugEventStep); |
3763 step_action = StepIn; | 3763 step_action = StepIn; |
3764 | 3764 |
3765 // Check stepping where the if condition in bar is false. | 3765 // Check stepping where the if condition in bar is false. |
3766 break_point_hit_count = 0; | 3766 break_point_hit_count = 0; |
3767 foo->Call(env->Global(), 0, NULL); | 3767 foo->Call(env->Global(), 0, NULL); |
3768 CHECK_EQ(6, break_point_hit_count); | 3768 CHECK_EQ(6, break_point_hit_count); |
3769 | 3769 |
3770 // Check stepping where the if condition in bar is true. | 3770 // Check stepping where the if condition in bar is true. |
3771 break_point_hit_count = 0; | 3771 break_point_hit_count = 0; |
3772 const int argc = 1; | 3772 const int argc = 1; |
3773 v8::Handle<v8::Value> argv[argc] = { v8::True(isolate) }; | 3773 v8::Handle<v8::Value> argv[argc] = { v8::True(isolate) }; |
3774 foo->Call(env->Global(), argc, argv); | 3774 foo->Call(env->Global(), argc, argv); |
3775 CHECK_EQ(8, break_point_hit_count); | 3775 CHECK_EQ(8, break_point_hit_count); |
3776 | 3776 |
3777 v8::Debug::SetDebugEventListener2(NULL); | 3777 v8::Debug::SetDebugEventListener(NULL); |
3778 CheckDebuggerUnloaded(); | 3778 CheckDebuggerUnloaded(); |
3779 | 3779 |
3780 // Register a debug event listener which just counts. | 3780 // Register a debug event listener which just counts. |
3781 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 3781 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
3782 | 3782 |
3783 break_point_hit_count = 0; | 3783 break_point_hit_count = 0; |
3784 foo->Call(env->Global(), 0, NULL); | 3784 foo->Call(env->Global(), 0, NULL); |
3785 | 3785 |
3786 // Without stepping only the debugger statement is hit. | 3786 // Without stepping only the debugger statement is hit. |
3787 CHECK_EQ(1, break_point_hit_count); | 3787 CHECK_EQ(1, break_point_hit_count); |
3788 | 3788 |
3789 v8::Debug::SetDebugEventListener2(NULL); | 3789 v8::Debug::SetDebugEventListener(NULL); |
3790 CheckDebuggerUnloaded(); | 3790 CheckDebuggerUnloaded(); |
3791 } | 3791 } |
3792 | 3792 |
3793 | 3793 |
3794 // Tests that breakpoint will be hit if it's set in script. | 3794 // Tests that breakpoint will be hit if it's set in script. |
3795 TEST(PauseInScript) { | 3795 TEST(PauseInScript) { |
3796 DebugLocalContext env; | 3796 DebugLocalContext env; |
3797 v8::HandleScope scope(env->GetIsolate()); | 3797 v8::HandleScope scope(env->GetIsolate()); |
3798 env.ExposeDebug(); | 3798 env.ExposeDebug(); |
3799 | 3799 |
3800 // Register a debug event listener which counts. | 3800 // Register a debug event listener which counts. |
3801 v8::Debug::SetDebugEventListener2(DebugEventCounter); | 3801 v8::Debug::SetDebugEventListener(DebugEventCounter); |
3802 | 3802 |
3803 // Create a script that returns a function. | 3803 // Create a script that returns a function. |
3804 const char* src = "(function (evt) {})"; | 3804 const char* src = "(function (evt) {})"; |
3805 const char* script_name = "StepInHandlerTest"; | 3805 const char* script_name = "StepInHandlerTest"; |
3806 | 3806 |
3807 // Set breakpoint in the script. | 3807 // Set breakpoint in the script. |
3808 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1); | 3808 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1); |
3809 break_point_hit_count = 0; | 3809 break_point_hit_count = 0; |
3810 | 3810 |
3811 v8::ScriptOrigin origin( | 3811 v8::ScriptOrigin origin( |
3812 v8::String::NewFromUtf8(env->GetIsolate(), script_name), | 3812 v8::String::NewFromUtf8(env->GetIsolate(), script_name), |
3813 v8::Integer::New(env->GetIsolate(), 0)); | 3813 v8::Integer::New(env->GetIsolate(), 0)); |
3814 v8::Handle<v8::Script> script = v8::Script::Compile( | 3814 v8::Handle<v8::Script> script = v8::Script::Compile( |
3815 v8::String::NewFromUtf8(env->GetIsolate(), src), &origin); | 3815 v8::String::NewFromUtf8(env->GetIsolate(), src), &origin); |
3816 v8::Local<v8::Value> r = script->Run(); | 3816 v8::Local<v8::Value> r = script->Run(); |
3817 | 3817 |
3818 CHECK(r->IsFunction()); | 3818 CHECK(r->IsFunction()); |
3819 CHECK_EQ(1, break_point_hit_count); | 3819 CHECK_EQ(1, break_point_hit_count); |
3820 | 3820 |
3821 // Get rid of the debug event listener. | 3821 // Get rid of the debug event listener. |
3822 v8::Debug::SetDebugEventListener2(NULL); | 3822 v8::Debug::SetDebugEventListener(NULL); |
3823 CheckDebuggerUnloaded(); | 3823 CheckDebuggerUnloaded(); |
3824 } | 3824 } |
3825 | 3825 |
3826 | 3826 |
3827 // Test break on exceptions. For each exception break combination the number | 3827 // Test break on exceptions. For each exception break combination the number |
3828 // of debug event exception callbacks and message callbacks are collected. The | 3828 // of debug event exception callbacks and message callbacks are collected. The |
3829 // number of debug event exception callbacks are used to check that the | 3829 // number of debug event exception callbacks are used to check that the |
3830 // debugger is called correctly and the number of message callbacks is used to | 3830 // debugger is called correctly and the number of message callbacks is used to |
3831 // check that uncaught exceptions are still returned even if there is a break | 3831 // check that uncaught exceptions are still returned even if there is a break |
3832 // for them. | 3832 // for them. |
3833 TEST(BreakOnException) { | 3833 TEST(BreakOnException) { |
3834 DebugLocalContext env; | 3834 DebugLocalContext env; |
3835 v8::HandleScope scope(env->GetIsolate()); | 3835 v8::HandleScope scope(env->GetIsolate()); |
3836 env.ExposeDebug(); | 3836 env.ExposeDebug(); |
3837 | 3837 |
3838 // Create functions for testing break on exception. | 3838 // Create functions for testing break on exception. |
3839 CompileFunction(&env, "function throws(){throw 1;}", "throws"); | 3839 CompileFunction(&env, "function throws(){throw 1;}", "throws"); |
3840 v8::Local<v8::Function> caught = | 3840 v8::Local<v8::Function> caught = |
3841 CompileFunction(&env, | 3841 CompileFunction(&env, |
3842 "function caught(){try {throws();} catch(e) {};}", | 3842 "function caught(){try {throws();} catch(e) {};}", |
3843 "caught"); | 3843 "caught"); |
3844 v8::Local<v8::Function> notCaught = | 3844 v8::Local<v8::Function> notCaught = |
3845 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); | 3845 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); |
3846 | 3846 |
3847 v8::V8::AddMessageListener(MessageCallbackCount); | 3847 v8::V8::AddMessageListener(MessageCallbackCount); |
3848 v8::Debug::SetDebugEventListener2(DebugEventCounter); | 3848 v8::Debug::SetDebugEventListener(DebugEventCounter); |
3849 | 3849 |
3850 // Initial state should be no break on exceptions. | 3850 // Initial state should be no break on exceptions. |
3851 DebugEventCounterClear(); | 3851 DebugEventCounterClear(); |
3852 MessageCallbackCountClear(); | 3852 MessageCallbackCountClear(); |
3853 caught->Call(env->Global(), 0, NULL); | 3853 caught->Call(env->Global(), 0, NULL); |
3854 CHECK_EQ(0, exception_hit_count); | 3854 CHECK_EQ(0, exception_hit_count); |
3855 CHECK_EQ(0, uncaught_exception_hit_count); | 3855 CHECK_EQ(0, uncaught_exception_hit_count); |
3856 CHECK_EQ(0, message_callback_count); | 3856 CHECK_EQ(0, message_callback_count); |
3857 notCaught->Call(env->Global(), 0, NULL); | 3857 notCaught->Call(env->Global(), 0, NULL); |
3858 CHECK_EQ(0, exception_hit_count); | 3858 CHECK_EQ(0, exception_hit_count); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3956 ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, false); | 3956 ChangeBreakOnExceptionFromJS(env->GetIsolate(), true, false); |
3957 caught->Call(env->Global(), 0, NULL); | 3957 caught->Call(env->Global(), 0, NULL); |
3958 CHECK_EQ(1, exception_hit_count); | 3958 CHECK_EQ(1, exception_hit_count); |
3959 CHECK_EQ(0, uncaught_exception_hit_count); | 3959 CHECK_EQ(0, uncaught_exception_hit_count); |
3960 CHECK_EQ(0, message_callback_count); | 3960 CHECK_EQ(0, message_callback_count); |
3961 notCaught->Call(env->Global(), 0, NULL); | 3961 notCaught->Call(env->Global(), 0, NULL); |
3962 CHECK_EQ(2, exception_hit_count); | 3962 CHECK_EQ(2, exception_hit_count); |
3963 CHECK_EQ(1, uncaught_exception_hit_count); | 3963 CHECK_EQ(1, uncaught_exception_hit_count); |
3964 CHECK_EQ(1, message_callback_count); | 3964 CHECK_EQ(1, message_callback_count); |
3965 | 3965 |
3966 v8::Debug::SetDebugEventListener2(NULL); | 3966 v8::Debug::SetDebugEventListener(NULL); |
3967 CheckDebuggerUnloaded(); | 3967 CheckDebuggerUnloaded(); |
3968 v8::V8::RemoveMessageListeners(MessageCallbackCount); | 3968 v8::V8::RemoveMessageListeners(MessageCallbackCount); |
3969 } | 3969 } |
3970 | 3970 |
3971 | 3971 |
3972 // Test break on exception from compiler errors. When compiling using | 3972 // Test break on exception from compiler errors. When compiling using |
3973 // v8::Script::Compile there is no JavaScript stack whereas when compiling using | 3973 // v8::Script::Compile there is no JavaScript stack whereas when compiling using |
3974 // eval there are JavaScript frames. | 3974 // eval there are JavaScript frames. |
3975 TEST(BreakOnCompileException) { | 3975 TEST(BreakOnCompileException) { |
3976 DebugLocalContext env; | 3976 DebugLocalContext env; |
3977 v8::HandleScope scope(env->GetIsolate()); | 3977 v8::HandleScope scope(env->GetIsolate()); |
3978 | 3978 |
3979 // For this test, we want to break on uncaught exceptions: | 3979 // For this test, we want to break on uncaught exceptions: |
3980 ChangeBreakOnException(false, true); | 3980 ChangeBreakOnException(false, true); |
3981 | 3981 |
3982 // Create a function for checking the function when hitting a break point. | 3982 // Create a function for checking the function when hitting a break point. |
3983 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); | 3983 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); |
3984 | 3984 |
3985 v8::V8::AddMessageListener(MessageCallbackCount); | 3985 v8::V8::AddMessageListener(MessageCallbackCount); |
3986 v8::Debug::SetDebugEventListener2(DebugEventCounter); | 3986 v8::Debug::SetDebugEventListener(DebugEventCounter); |
3987 | 3987 |
3988 DebugEventCounterClear(); | 3988 DebugEventCounterClear(); |
3989 MessageCallbackCountClear(); | 3989 MessageCallbackCountClear(); |
3990 | 3990 |
3991 // Check initial state. | 3991 // Check initial state. |
3992 CHECK_EQ(0, exception_hit_count); | 3992 CHECK_EQ(0, exception_hit_count); |
3993 CHECK_EQ(0, uncaught_exception_hit_count); | 3993 CHECK_EQ(0, uncaught_exception_hit_count); |
3994 CHECK_EQ(0, message_callback_count); | 3994 CHECK_EQ(0, message_callback_count); |
3995 CHECK_EQ(-1, last_js_stack_height); | 3995 CHECK_EQ(-1, last_js_stack_height); |
3996 | 3996 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4032 | 4032 |
4033 // For this test, we want to break on uncaught exceptions: | 4033 // For this test, we want to break on uncaught exceptions: |
4034 ChangeBreakOnException(false, true); | 4034 ChangeBreakOnException(false, true); |
4035 | 4035 |
4036 // Create a function for checking the function when hitting a break point. | 4036 // Create a function for checking the function when hitting a break point. |
4037 frame_function_name = CompileFunction(&env, | 4037 frame_function_name = CompileFunction(&env, |
4038 frame_function_name_source, | 4038 frame_function_name_source, |
4039 "frame_function_name"); | 4039 "frame_function_name"); |
4040 | 4040 |
4041 // Register a debug event listener which steps and counts. | 4041 // Register a debug event listener which steps and counts. |
4042 v8::Debug::SetDebugEventListener2(DebugEventStepSequence); | 4042 v8::Debug::SetDebugEventListener(DebugEventStepSequence); |
4043 | 4043 |
4044 // Create functions for testing stepping. | 4044 // Create functions for testing stepping. |
4045 const char* src = "function a() { n(); }; " | 4045 const char* src = "function a() { n(); }; " |
4046 "function b() { c(); }; " | 4046 "function b() { c(); }; " |
4047 "function c() { n(); }; " | 4047 "function c() { n(); }; " |
4048 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; " | 4048 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; " |
4049 "function e() { n(); }; " | 4049 "function e() { n(); }; " |
4050 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; " | 4050 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; " |
4051 "function g() { h(); }; " | 4051 "function g() { h(); }; " |
4052 "function h() { x = 1; throw 1; }; "; | 4052 "function h() { x = 1; throw 1; }; "; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4104 // Step through invocation of f + g + h now with break on caught exceptions. | 4104 // Step through invocation of f + g + h now with break on caught exceptions. |
4105 ChangeBreakOnException(true, true); | 4105 ChangeBreakOnException(true, true); |
4106 step_action = StepIn; | 4106 step_action = StepIn; |
4107 break_point_hit_count = 0; | 4107 break_point_hit_count = 0; |
4108 expected_step_sequence = "ffghhhff"; | 4108 expected_step_sequence = "ffghhhff"; |
4109 f->Call(env->Global(), 0, NULL); | 4109 f->Call(env->Global(), 0, NULL); |
4110 CHECK_EQ(StrLength(expected_step_sequence), | 4110 CHECK_EQ(StrLength(expected_step_sequence), |
4111 break_point_hit_count); | 4111 break_point_hit_count); |
4112 | 4112 |
4113 // Get rid of the debug event listener. | 4113 // Get rid of the debug event listener. |
4114 v8::Debug::SetDebugEventListener2(NULL); | 4114 v8::Debug::SetDebugEventListener(NULL); |
4115 CheckDebuggerUnloaded(); | 4115 CheckDebuggerUnloaded(); |
4116 } | 4116 } |
4117 | 4117 |
4118 | 4118 |
4119 TEST(DebugBreak) { | 4119 TEST(DebugBreak) { |
4120 i::FLAG_stress_compaction = false; | 4120 i::FLAG_stress_compaction = false; |
4121 #ifdef VERIFY_HEAP | 4121 #ifdef VERIFY_HEAP |
4122 i::FLAG_verify_heap = true; | 4122 i::FLAG_verify_heap = true; |
4123 #endif | 4123 #endif |
4124 DebugLocalContext env; | 4124 DebugLocalContext env; |
4125 v8::Isolate* isolate = env->GetIsolate(); | 4125 v8::Isolate* isolate = env->GetIsolate(); |
4126 v8::HandleScope scope(isolate); | 4126 v8::HandleScope scope(isolate); |
4127 | 4127 |
4128 // Register a debug event listener which sets the break flag and counts. | 4128 // Register a debug event listener which sets the break flag and counts. |
4129 v8::Debug::SetDebugEventListener2(DebugEventBreak); | 4129 v8::Debug::SetDebugEventListener(DebugEventBreak); |
4130 | 4130 |
4131 // Create a function for testing stepping. | 4131 // Create a function for testing stepping. |
4132 const char* src = "function f0() {}" | 4132 const char* src = "function f0() {}" |
4133 "function f1(x1) {}" | 4133 "function f1(x1) {}" |
4134 "function f2(x1,x2) {}" | 4134 "function f2(x1,x2) {}" |
4135 "function f3(x1,x2,x3) {}"; | 4135 "function f3(x1,x2,x3) {}"; |
4136 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); | 4136 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); |
4137 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1"); | 4137 v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1"); |
4138 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2"); | 4138 v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2"); |
4139 v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3"); | 4139 v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3"); |
(...skipping 19 matching lines...) Expand all Loading... |
4159 f0->Call(env->Global(), i, argv); | 4159 f0->Call(env->Global(), i, argv); |
4160 f1->Call(env->Global(), i, argv); | 4160 f1->Call(env->Global(), i, argv); |
4161 f2->Call(env->Global(), i, argv); | 4161 f2->Call(env->Global(), i, argv); |
4162 f3->Call(env->Global(), i, argv); | 4162 f3->Call(env->Global(), i, argv); |
4163 } | 4163 } |
4164 | 4164 |
4165 // One break for each function called. | 4165 // One break for each function called. |
4166 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); | 4166 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); |
4167 | 4167 |
4168 // Get rid of the debug event listener. | 4168 // Get rid of the debug event listener. |
4169 v8::Debug::SetDebugEventListener2(NULL); | 4169 v8::Debug::SetDebugEventListener(NULL); |
4170 CheckDebuggerUnloaded(); | 4170 CheckDebuggerUnloaded(); |
4171 } | 4171 } |
4172 | 4172 |
4173 | 4173 |
4174 // Test to ensure that JavaScript code keeps running while the debug break | 4174 // Test to ensure that JavaScript code keeps running while the debug break |
4175 // through the stack limit flag is set but breaks are disabled. | 4175 // through the stack limit flag is set but breaks are disabled. |
4176 TEST(DisableBreak) { | 4176 TEST(DisableBreak) { |
4177 DebugLocalContext env; | 4177 DebugLocalContext env; |
4178 v8::HandleScope scope(env->GetIsolate()); | 4178 v8::HandleScope scope(env->GetIsolate()); |
4179 | 4179 |
4180 // Register a debug event listener which sets the break flag and counts. | 4180 // Register a debug event listener which sets the break flag and counts. |
4181 v8::Debug::SetDebugEventListener2(DebugEventCounter); | 4181 v8::Debug::SetDebugEventListener(DebugEventCounter); |
4182 | 4182 |
4183 // Create a function for testing stepping. | 4183 // Create a function for testing stepping. |
4184 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; | 4184 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; |
4185 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 4185 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
4186 | 4186 |
4187 // Set the debug break flag. | 4187 // Set the debug break flag. |
4188 v8::Debug::DebugBreak(env->GetIsolate()); | 4188 v8::Debug::DebugBreak(env->GetIsolate()); |
4189 | 4189 |
4190 // Call all functions with different argument count. | 4190 // Call all functions with different argument count. |
4191 break_point_hit_count = 0; | 4191 break_point_hit_count = 0; |
4192 f->Call(env->Global(), 0, NULL); | 4192 f->Call(env->Global(), 0, NULL); |
4193 CHECK_EQ(1, break_point_hit_count); | 4193 CHECK_EQ(1, break_point_hit_count); |
4194 | 4194 |
4195 { | 4195 { |
4196 v8::Debug::DebugBreak(env->GetIsolate()); | 4196 v8::Debug::DebugBreak(env->GetIsolate()); |
4197 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); | 4197 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); |
4198 v8::internal::DisableBreak disable_break(isolate, true); | 4198 v8::internal::DisableBreak disable_break(isolate, true); |
4199 f->Call(env->Global(), 0, NULL); | 4199 f->Call(env->Global(), 0, NULL); |
4200 CHECK_EQ(1, break_point_hit_count); | 4200 CHECK_EQ(1, break_point_hit_count); |
4201 } | 4201 } |
4202 | 4202 |
4203 f->Call(env->Global(), 0, NULL); | 4203 f->Call(env->Global(), 0, NULL); |
4204 CHECK_EQ(2, break_point_hit_count); | 4204 CHECK_EQ(2, break_point_hit_count); |
4205 | 4205 |
4206 // Get rid of the debug event listener. | 4206 // Get rid of the debug event listener. |
4207 v8::Debug::SetDebugEventListener2(NULL); | 4207 v8::Debug::SetDebugEventListener(NULL); |
4208 CheckDebuggerUnloaded(); | 4208 CheckDebuggerUnloaded(); |
4209 } | 4209 } |
4210 | 4210 |
4211 static const char* kSimpleExtensionSource = | 4211 static const char* kSimpleExtensionSource = |
4212 "(function Foo() {" | 4212 "(function Foo() {" |
4213 " return 4;" | 4213 " return 4;" |
4214 "})() "; | 4214 "})() "; |
4215 | 4215 |
4216 // http://crbug.com/28933 | 4216 // http://crbug.com/28933 |
4217 // Test that debug break is disabled when bootstrapper is active. | 4217 // Test that debug break is disabled when bootstrapper is active. |
4218 TEST(NoBreakWhenBootstrapping) { | 4218 TEST(NoBreakWhenBootstrapping) { |
4219 v8::Isolate* isolate = CcTest::isolate(); | 4219 v8::Isolate* isolate = CcTest::isolate(); |
4220 v8::HandleScope scope(isolate); | 4220 v8::HandleScope scope(isolate); |
4221 | 4221 |
4222 // Register a debug event listener which sets the break flag and counts. | 4222 // Register a debug event listener which sets the break flag and counts. |
4223 v8::Debug::SetDebugEventListener2(DebugEventCounter); | 4223 v8::Debug::SetDebugEventListener(DebugEventCounter); |
4224 | 4224 |
4225 // Set the debug break flag. | 4225 // Set the debug break flag. |
4226 v8::Debug::DebugBreak(isolate); | 4226 v8::Debug::DebugBreak(isolate); |
4227 break_point_hit_count = 0; | 4227 break_point_hit_count = 0; |
4228 { | 4228 { |
4229 // Create a context with an extension to make sure that some JavaScript | 4229 // Create a context with an extension to make sure that some JavaScript |
4230 // code is executed during bootstrapping. | 4230 // code is executed during bootstrapping. |
4231 v8::RegisterExtension(new v8::Extension("simpletest", | 4231 v8::RegisterExtension(new v8::Extension("simpletest", |
4232 kSimpleExtensionSource)); | 4232 kSimpleExtensionSource)); |
4233 const char* extension_names[] = { "simpletest" }; | 4233 const char* extension_names[] = { "simpletest" }; |
4234 v8::ExtensionConfiguration extensions(1, extension_names); | 4234 v8::ExtensionConfiguration extensions(1, extension_names); |
4235 v8::HandleScope handle_scope(isolate); | 4235 v8::HandleScope handle_scope(isolate); |
4236 v8::Context::New(isolate, &extensions); | 4236 v8::Context::New(isolate, &extensions); |
4237 } | 4237 } |
4238 // Check that no DebugBreak events occured during the context creation. | 4238 // Check that no DebugBreak events occured during the context creation. |
4239 CHECK_EQ(0, break_point_hit_count); | 4239 CHECK_EQ(0, break_point_hit_count); |
4240 | 4240 |
4241 // Get rid of the debug event listener. | 4241 // Get rid of the debug event listener. |
4242 v8::Debug::SetDebugEventListener2(NULL); | 4242 v8::Debug::SetDebugEventListener(NULL); |
4243 CheckDebuggerUnloaded(); | 4243 CheckDebuggerUnloaded(); |
4244 } | 4244 } |
4245 | 4245 |
4246 | 4246 |
4247 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { | 4247 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) { |
4248 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); | 4248 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 3); |
4249 result->Set(v8::Integer::New(info.GetIsolate(), 0), | 4249 result->Set(v8::Integer::New(info.GetIsolate(), 0), |
4250 v8::String::NewFromUtf8(info.GetIsolate(), "a")); | 4250 v8::String::NewFromUtf8(info.GetIsolate(), "a")); |
4251 result->Set(v8::Integer::New(info.GetIsolate(), 1), | 4251 result->Set(v8::Integer::New(info.GetIsolate(), 1), |
4252 v8::String::NewFromUtf8(info.GetIsolate(), "b")); | 4252 v8::String::NewFromUtf8(info.GetIsolate(), "b")); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4954 } | 4954 } |
4955 | 4955 |
4956 | 4956 |
4957 // This thread runs the v8 engine. | 4957 // This thread runs the v8 engine. |
4958 TEST(MessageQueues) { | 4958 TEST(MessageQueues) { |
4959 MessageQueueDebuggerThread message_queue_debugger_thread; | 4959 MessageQueueDebuggerThread message_queue_debugger_thread; |
4960 | 4960 |
4961 // Create a V8 environment | 4961 // Create a V8 environment |
4962 DebugLocalContext env; | 4962 DebugLocalContext env; |
4963 v8::HandleScope scope(env->GetIsolate()); | 4963 v8::HandleScope scope(env->GetIsolate()); |
4964 v8::Debug::SetMessageHandler2(MessageHandler); | 4964 v8::Debug::SetMessageHandler(MessageHandler); |
4965 message_queue_debugger_thread.Start(); | 4965 message_queue_debugger_thread.Start(); |
4966 | 4966 |
4967 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; | 4967 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; |
4968 const char* source_2 = "e = 17;"; | 4968 const char* source_2 = "e = 17;"; |
4969 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; | 4969 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; |
4970 | 4970 |
4971 // See MessageQueueDebuggerThread::Run for interleaved sequence of | 4971 // See MessageQueueDebuggerThread::Run for interleaved sequence of |
4972 // API calls and events in the two threads. | 4972 // API calls and events in the two threads. |
4973 CompileRun(source_1); | 4973 CompileRun(source_1); |
4974 message_queue_barriers.barrier_1.Wait(); | 4974 message_queue_barriers.barrier_1.Wait(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5048 | 5048 |
5049 | 5049 |
5050 // Tests that all client data passed to the debugger are sent to the handler. | 5050 // Tests that all client data passed to the debugger are sent to the handler. |
5051 TEST(SendClientDataToHandler) { | 5051 TEST(SendClientDataToHandler) { |
5052 // Create a V8 environment | 5052 // Create a V8 environment |
5053 DebugLocalContext env; | 5053 DebugLocalContext env; |
5054 v8::Isolate* isolate = env->GetIsolate(); | 5054 v8::Isolate* isolate = env->GetIsolate(); |
5055 v8::HandleScope scope(isolate); | 5055 v8::HandleScope scope(isolate); |
5056 TestClientData::ResetCounters(); | 5056 TestClientData::ResetCounters(); |
5057 handled_client_data_instances_count = 0; | 5057 handled_client_data_instances_count = 0; |
5058 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData); | 5058 v8::Debug::SetMessageHandler(MessageHandlerCountingClientData); |
5059 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; | 5059 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; |
5060 const int kBufferSize = 1000; | 5060 const int kBufferSize = 1000; |
5061 uint16_t buffer[kBufferSize]; | 5061 uint16_t buffer[kBufferSize]; |
5062 const char* command_1 = | 5062 const char* command_1 = |
5063 "{\"seq\":117," | 5063 "{\"seq\":117," |
5064 "\"type\":\"request\"," | 5064 "\"type\":\"request\"," |
5065 "\"command\":\"evaluate\"," | 5065 "\"command\":\"evaluate\"," |
5066 "\"arguments\":{\"expression\":\"1+2\"}}"; | 5066 "\"arguments\":{\"expression\":\"1+2\"}}"; |
5067 const char* command_2 = | 5067 const char* command_2 = |
5068 "{\"seq\":118," | 5068 "{\"seq\":118," |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5155 " x = x + 1;\n" | 5155 " x = x + 1;\n" |
5156 " }\n" | 5156 " }\n" |
5157 "}\n" | 5157 "}\n" |
5158 "\n" | 5158 "\n" |
5159 "foo();\n"; | 5159 "foo();\n"; |
5160 | 5160 |
5161 v8::Isolate* isolate = CcTest::isolate(); | 5161 v8::Isolate* isolate = CcTest::isolate(); |
5162 v8::Isolate::Scope isolate_scope(isolate); | 5162 v8::Isolate::Scope isolate_scope(isolate); |
5163 DebugLocalContext env; | 5163 DebugLocalContext env; |
5164 v8::HandleScope scope(env->GetIsolate()); | 5164 v8::HandleScope scope(env->GetIsolate()); |
5165 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); | 5165 v8::Debug::SetMessageHandler(&ThreadedMessageHandler); |
5166 v8::Handle<v8::ObjectTemplate> global_template = | 5166 v8::Handle<v8::ObjectTemplate> global_template = |
5167 v8::ObjectTemplate::New(env->GetIsolate()); | 5167 v8::ObjectTemplate::New(env->GetIsolate()); |
5168 global_template->Set( | 5168 global_template->Set( |
5169 v8::String::NewFromUtf8(env->GetIsolate(), "ThreadedAtBarrier1"), | 5169 v8::String::NewFromUtf8(env->GetIsolate(), "ThreadedAtBarrier1"), |
5170 v8::FunctionTemplate::New(isolate, ThreadedAtBarrier1)); | 5170 v8::FunctionTemplate::New(isolate, ThreadedAtBarrier1)); |
5171 v8::Handle<v8::Context> context = v8::Context::New(isolate, | 5171 v8::Handle<v8::Context> context = v8::Context::New(isolate, |
5172 NULL, | 5172 NULL, |
5173 global_template); | 5173 global_template); |
5174 v8::Context::Scope context_scope(context); | 5174 v8::Context::Scope context_scope(context); |
5175 | 5175 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5274 " return x;\n" | 5274 " return x;\n" |
5275 "}\n" | 5275 "}\n" |
5276 "\n"; | 5276 "\n"; |
5277 const char* source_2 = "cat(17);\n" | 5277 const char* source_2 = "cat(17);\n" |
5278 "cat(19);\n"; | 5278 "cat(19);\n"; |
5279 | 5279 |
5280 v8::Isolate* isolate = CcTest::isolate(); | 5280 v8::Isolate* isolate = CcTest::isolate(); |
5281 v8::Isolate::Scope isolate_scope(isolate); | 5281 v8::Isolate::Scope isolate_scope(isolate); |
5282 DebugLocalContext env; | 5282 DebugLocalContext env; |
5283 v8::HandleScope scope(isolate); | 5283 v8::HandleScope scope(isolate); |
5284 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler); | 5284 v8::Debug::SetMessageHandler(&BreakpointsMessageHandler); |
5285 | 5285 |
5286 CompileRun(source_1); | 5286 CompileRun(source_1); |
5287 breakpoints_barriers->barrier_1.Wait(); | 5287 breakpoints_barriers->barrier_1.Wait(); |
5288 breakpoints_barriers->barrier_2.Wait(); | 5288 breakpoints_barriers->barrier_2.Wait(); |
5289 CompileRun(source_2); | 5289 CompileRun(source_2); |
5290 } | 5290 } |
5291 | 5291 |
5292 | 5292 |
5293 void BreakpointsDebuggerThread::Run() { | 5293 void BreakpointsDebuggerThread::Run() { |
5294 const int kBufSize = 1000; | 5294 const int kBufSize = 1000; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5431 TestRecursiveBreakpointsGeneric(true); | 5431 TestRecursiveBreakpointsGeneric(true); |
5432 } | 5432 } |
5433 | 5433 |
5434 | 5434 |
5435 static void DummyDebugEventListener( | 5435 static void DummyDebugEventListener( |
5436 const v8::Debug::EventDetails& event_details) { | 5436 const v8::Debug::EventDetails& event_details) { |
5437 } | 5437 } |
5438 | 5438 |
5439 | 5439 |
5440 TEST(SetDebugEventListenerOnUninitializedVM) { | 5440 TEST(SetDebugEventListenerOnUninitializedVM) { |
5441 v8::Debug::SetDebugEventListener2(DummyDebugEventListener); | 5441 v8::Debug::SetDebugEventListener(DummyDebugEventListener); |
5442 } | 5442 } |
5443 | 5443 |
5444 | 5444 |
5445 static void DummyMessageHandler(const v8::Debug::Message& message) { | 5445 static void DummyMessageHandler(const v8::Debug::Message& message) { |
5446 } | 5446 } |
5447 | 5447 |
5448 | 5448 |
5449 TEST(SetMessageHandlerOnUninitializedVM) { | 5449 TEST(SetMessageHandlerOnUninitializedVM) { |
5450 v8::Debug::SetMessageHandler2(DummyMessageHandler); | 5450 v8::Debug::SetMessageHandler(DummyMessageHandler); |
5451 } | 5451 } |
5452 | 5452 |
5453 | 5453 |
5454 // Source for a JavaScript function which returns the data parameter of a | 5454 // Source for a JavaScript function which returns the data parameter of a |
5455 // function called in the context of the debugger. If no data parameter is | 5455 // function called in the context of the debugger. If no data parameter is |
5456 // passed it throws an exception. | 5456 // passed it throws an exception. |
5457 static const char* debugger_call_with_data_source = | 5457 static const char* debugger_call_with_data_source = |
5458 "function debugger_call_with_data(exec_state, data) {" | 5458 "function debugger_call_with_data(exec_state, data) {" |
5459 " if (data) return data;" | 5459 " if (data) return data;" |
5460 " throw 'No data!'" | 5460 " throw 'No data!'" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5632 // Test that clearing the debug event listener actually clears all break points | 5632 // Test that clearing the debug event listener actually clears all break points |
5633 // and related information. | 5633 // and related information. |
5634 TEST(DebuggerUnload) { | 5634 TEST(DebuggerUnload) { |
5635 DebugLocalContext env; | 5635 DebugLocalContext env; |
5636 | 5636 |
5637 // Check debugger is unloaded before it is used. | 5637 // Check debugger is unloaded before it is used. |
5638 CheckDebuggerUnloaded(); | 5638 CheckDebuggerUnloaded(); |
5639 | 5639 |
5640 // Set a debug event listener. | 5640 // Set a debug event listener. |
5641 break_point_hit_count = 0; | 5641 break_point_hit_count = 0; |
5642 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 5642 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
5643 { | 5643 { |
5644 v8::HandleScope scope(env->GetIsolate()); | 5644 v8::HandleScope scope(env->GetIsolate()); |
5645 // Create a couple of functions for the test. | 5645 // Create a couple of functions for the test. |
5646 v8::Local<v8::Function> foo = | 5646 v8::Local<v8::Function> foo = |
5647 CompileFunction(&env, "function foo(){x=1}", "foo"); | 5647 CompileFunction(&env, "function foo(){x=1}", "foo"); |
5648 v8::Local<v8::Function> bar = | 5648 v8::Local<v8::Function> bar = |
5649 CompileFunction(&env, "function bar(){y=2}", "bar"); | 5649 CompileFunction(&env, "function bar(){y=2}", "bar"); |
5650 | 5650 |
5651 // Set some break points. | 5651 // Set some break points. |
5652 SetBreakPoint(foo, 0); | 5652 SetBreakPoint(foo, 0); |
5653 SetBreakPoint(foo, 4); | 5653 SetBreakPoint(foo, 4); |
5654 SetBreakPoint(bar, 0); | 5654 SetBreakPoint(bar, 0); |
5655 SetBreakPoint(bar, 4); | 5655 SetBreakPoint(bar, 4); |
5656 | 5656 |
5657 // Make sure that the break points are there. | 5657 // Make sure that the break points are there. |
5658 break_point_hit_count = 0; | 5658 break_point_hit_count = 0; |
5659 foo->Call(env->Global(), 0, NULL); | 5659 foo->Call(env->Global(), 0, NULL); |
5660 CHECK_EQ(2, break_point_hit_count); | 5660 CHECK_EQ(2, break_point_hit_count); |
5661 bar->Call(env->Global(), 0, NULL); | 5661 bar->Call(env->Global(), 0, NULL); |
5662 CHECK_EQ(4, break_point_hit_count); | 5662 CHECK_EQ(4, break_point_hit_count); |
5663 } | 5663 } |
5664 | 5664 |
5665 // Remove the debug event listener without clearing breakpoints. Do this | 5665 // Remove the debug event listener without clearing breakpoints. Do this |
5666 // outside a handle scope. | 5666 // outside a handle scope. |
5667 v8::Debug::SetDebugEventListener2(NULL); | 5667 v8::Debug::SetDebugEventListener(NULL); |
5668 CheckDebuggerUnloaded(true); | 5668 CheckDebuggerUnloaded(true); |
5669 | 5669 |
5670 // Now set a debug message handler. | 5670 // Now set a debug message handler. |
5671 break_point_hit_count = 0; | 5671 break_point_hit_count = 0; |
5672 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); | 5672 v8::Debug::SetMessageHandler(MessageHandlerBreakPointHitCount); |
5673 { | 5673 { |
5674 v8::HandleScope scope(env->GetIsolate()); | 5674 v8::HandleScope scope(env->GetIsolate()); |
5675 | 5675 |
5676 // Get the test functions again. | 5676 // Get the test functions again. |
5677 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( | 5677 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( |
5678 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")))); | 5678 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo")))); |
5679 | 5679 |
5680 foo->Call(env->Global(), 0, NULL); | 5680 foo->Call(env->Global(), 0, NULL); |
5681 CHECK_EQ(0, break_point_hit_count); | 5681 CHECK_EQ(0, break_point_hit_count); |
5682 | 5682 |
5683 // Set break points and run again. | 5683 // Set break points and run again. |
5684 SetBreakPoint(foo, 0); | 5684 SetBreakPoint(foo, 0); |
5685 SetBreakPoint(foo, 4); | 5685 SetBreakPoint(foo, 4); |
5686 foo->Call(env->Global(), 0, NULL); | 5686 foo->Call(env->Global(), 0, NULL); |
5687 CHECK_EQ(2, break_point_hit_count); | 5687 CHECK_EQ(2, break_point_hit_count); |
5688 } | 5688 } |
5689 | 5689 |
5690 // Remove the debug message handler without clearing breakpoints. Do this | 5690 // Remove the debug message handler without clearing breakpoints. Do this |
5691 // outside a handle scope. | 5691 // outside a handle scope. |
5692 v8::Debug::SetMessageHandler2(NULL); | 5692 v8::Debug::SetMessageHandler(NULL); |
5693 CheckDebuggerUnloaded(true); | 5693 CheckDebuggerUnloaded(true); |
5694 } | 5694 } |
5695 | 5695 |
5696 | 5696 |
5697 // Sends continue command to the debugger. | 5697 // Sends continue command to the debugger. |
5698 static void SendContinueCommand() { | 5698 static void SendContinueCommand() { |
5699 const int kBufferSize = 1000; | 5699 const int kBufferSize = 1000; |
5700 uint16_t buffer[kBufferSize]; | 5700 uint16_t buffer[kBufferSize]; |
5701 const char* command_continue = | 5701 const char* command_continue = |
5702 "{\"seq\":0," | 5702 "{\"seq\":0," |
(...skipping 22 matching lines...) Expand all Loading... |
5725 | 5725 |
5726 // Test clearing the debug message handler. | 5726 // Test clearing the debug message handler. |
5727 TEST(DebuggerClearMessageHandler) { | 5727 TEST(DebuggerClearMessageHandler) { |
5728 DebugLocalContext env; | 5728 DebugLocalContext env; |
5729 v8::HandleScope scope(env->GetIsolate()); | 5729 v8::HandleScope scope(env->GetIsolate()); |
5730 | 5730 |
5731 // Check debugger is unloaded before it is used. | 5731 // Check debugger is unloaded before it is used. |
5732 CheckDebuggerUnloaded(); | 5732 CheckDebuggerUnloaded(); |
5733 | 5733 |
5734 // Set a debug message handler. | 5734 // Set a debug message handler. |
5735 v8::Debug::SetMessageHandler2(MessageHandlerHitCount); | 5735 v8::Debug::SetMessageHandler(MessageHandlerHitCount); |
5736 | 5736 |
5737 // Run code to throw a unhandled exception. This should end up in the message | 5737 // Run code to throw a unhandled exception. This should end up in the message |
5738 // handler. | 5738 // handler. |
5739 CompileRun("throw 1"); | 5739 CompileRun("throw 1"); |
5740 | 5740 |
5741 // The message handler should be called. | 5741 // The message handler should be called. |
5742 CHECK_GT(message_handler_hit_count, 0); | 5742 CHECK_GT(message_handler_hit_count, 0); |
5743 | 5743 |
5744 // Clear debug message handler. | 5744 // Clear debug message handler. |
5745 message_handler_hit_count = 0; | 5745 message_handler_hit_count = 0; |
5746 v8::Debug::SetMessageHandler2(NULL); | 5746 v8::Debug::SetMessageHandler(NULL); |
5747 | 5747 |
5748 // Run code to throw a unhandled exception. This should end up in the message | 5748 // Run code to throw a unhandled exception. This should end up in the message |
5749 // handler. | 5749 // handler. |
5750 CompileRun("throw 1"); | 5750 CompileRun("throw 1"); |
5751 | 5751 |
5752 // The message handler should not be called more. | 5752 // The message handler should not be called more. |
5753 CHECK_EQ(0, message_handler_hit_count); | 5753 CHECK_EQ(0, message_handler_hit_count); |
5754 | 5754 |
5755 CheckDebuggerUnloaded(true); | 5755 CheckDebuggerUnloaded(true); |
5756 } | 5756 } |
5757 | 5757 |
5758 | 5758 |
5759 // Debugger message handler which clears the message handler while active. | 5759 // Debugger message handler which clears the message handler while active. |
5760 static void MessageHandlerClearingMessageHandler( | 5760 static void MessageHandlerClearingMessageHandler( |
5761 const v8::Debug::Message& message) { | 5761 const v8::Debug::Message& message) { |
5762 message_handler_hit_count++; | 5762 message_handler_hit_count++; |
5763 | 5763 |
5764 // Clear debug message handler. | 5764 // Clear debug message handler. |
5765 v8::Debug::SetMessageHandler2(NULL); | 5765 v8::Debug::SetMessageHandler(NULL); |
5766 } | 5766 } |
5767 | 5767 |
5768 | 5768 |
5769 // Test clearing the debug message handler while processing a debug event. | 5769 // Test clearing the debug message handler while processing a debug event. |
5770 TEST(DebuggerClearMessageHandlerWhileActive) { | 5770 TEST(DebuggerClearMessageHandlerWhileActive) { |
5771 DebugLocalContext env; | 5771 DebugLocalContext env; |
5772 v8::HandleScope scope(env->GetIsolate()); | 5772 v8::HandleScope scope(env->GetIsolate()); |
5773 | 5773 |
5774 // Check debugger is unloaded before it is used. | 5774 // Check debugger is unloaded before it is used. |
5775 CheckDebuggerUnloaded(); | 5775 CheckDebuggerUnloaded(); |
5776 | 5776 |
5777 // Set a debug message handler. | 5777 // Set a debug message handler. |
5778 v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler); | 5778 v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler); |
5779 | 5779 |
5780 // Run code to throw a unhandled exception. This should end up in the message | 5780 // Run code to throw a unhandled exception. This should end up in the message |
5781 // handler. | 5781 // handler. |
5782 CompileRun("throw 1"); | 5782 CompileRun("throw 1"); |
5783 | 5783 |
5784 // The message handler should be called. | 5784 // The message handler should be called. |
5785 CHECK_EQ(1, message_handler_hit_count); | 5785 CHECK_EQ(1, message_handler_hit_count); |
5786 | 5786 |
5787 CheckDebuggerUnloaded(true); | 5787 CheckDebuggerUnloaded(true); |
5788 } | 5788 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6080 DebugLocalContext env; | 6080 DebugLocalContext env; |
6081 v8::HandleScope scope(env->GetIsolate()); | 6081 v8::HandleScope scope(env->GetIsolate()); |
6082 env.ExposeDebug(); | 6082 env.ExposeDebug(); |
6083 | 6083 |
6084 // Create functions for retrieving script name and data for the function on | 6084 // Create functions for retrieving script name and data for the function on |
6085 // the top frame when hitting a break point. | 6085 // the top frame when hitting a break point. |
6086 frame_script_name = CompileFunction(&env, | 6086 frame_script_name = CompileFunction(&env, |
6087 frame_script_name_source, | 6087 frame_script_name_source, |
6088 "frame_script_name"); | 6088 "frame_script_name"); |
6089 | 6089 |
6090 v8::Debug::SetDebugEventListener2(DebugEventBreakPointHitCount); | 6090 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
6091 | 6091 |
6092 // Test function source. | 6092 // Test function source. |
6093 v8::Local<v8::String> script = v8::String::NewFromUtf8(env->GetIsolate(), | 6093 v8::Local<v8::String> script = v8::String::NewFromUtf8(env->GetIsolate(), |
6094 "function f() {\n" | 6094 "function f() {\n" |
6095 " debugger;\n" | 6095 " debugger;\n" |
6096 "}\n"); | 6096 "}\n"); |
6097 | 6097 |
6098 v8::ScriptOrigin origin1 = | 6098 v8::ScriptOrigin origin1 = |
6099 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); | 6099 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "name")); |
6100 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); | 6100 v8::Handle<v8::Script> script1 = v8::Script::Compile(script, &origin1); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6173 | 6173 |
6174 // Create two contexts. | 6174 // Create two contexts. |
6175 v8::Handle<v8::Context> context_1; | 6175 v8::Handle<v8::Context> context_1; |
6176 v8::Handle<v8::Context> context_2; | 6176 v8::Handle<v8::Context> context_2; |
6177 v8::Handle<v8::ObjectTemplate> global_template = | 6177 v8::Handle<v8::ObjectTemplate> global_template = |
6178 v8::Handle<v8::ObjectTemplate>(); | 6178 v8::Handle<v8::ObjectTemplate>(); |
6179 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); | 6179 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); |
6180 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); | 6180 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); |
6181 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); | 6181 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); |
6182 | 6182 |
6183 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); | 6183 v8::Debug::SetMessageHandler(ContextCheckMessageHandler); |
6184 | 6184 |
6185 // Default data value is undefined. | 6185 // Default data value is undefined. |
6186 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6186 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6187 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); | 6187 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); |
6188 | 6188 |
6189 // Set and check different data values. | 6189 // Set and check different data values. |
6190 v8::Handle<v8::String> data_1 = v8::String::NewFromUtf8(isolate, "1"); | 6190 v8::Handle<v8::String> data_1 = v8::String::NewFromUtf8(isolate, "1"); |
6191 v8::Handle<v8::String> data_2 = v8::String::NewFromUtf8(isolate, "2"); | 6191 v8::Handle<v8::String> data_2 = v8::String::NewFromUtf8(isolate, "2"); |
6192 context_1->SetEmbedderData(0, data_1); | 6192 context_1->SetEmbedderData(0, data_1); |
6193 context_2->SetEmbedderData(0, data_2); | 6193 context_2->SetEmbedderData(0, data_2); |
(...skipping 18 matching lines...) Expand all Loading... |
6212 v8::Context::Scope context_scope(context_2); | 6212 v8::Context::Scope context_scope(context_2); |
6213 expected_context = context_2; | 6213 expected_context = context_2; |
6214 expected_context_data = data_2; | 6214 expected_context_data = data_2; |
6215 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); | 6215 v8::Local<v8::Function> f = CompileFunction(isolate, source, "f"); |
6216 f->Call(context_2->Global(), 0, NULL); | 6216 f->Call(context_2->Global(), 0, NULL); |
6217 } | 6217 } |
6218 | 6218 |
6219 // Two times compile event and two times break event. | 6219 // Two times compile event and two times break event. |
6220 CHECK_GT(message_handler_hit_count, 4); | 6220 CHECK_GT(message_handler_hit_count, 4); |
6221 | 6221 |
6222 v8::Debug::SetMessageHandler2(NULL); | 6222 v8::Debug::SetMessageHandler(NULL); |
6223 CheckDebuggerUnloaded(); | 6223 CheckDebuggerUnloaded(); |
6224 } | 6224 } |
6225 | 6225 |
6226 | 6226 |
6227 // Debug message handler which issues a debug break when it hits a break event. | 6227 // Debug message handler which issues a debug break when it hits a break event. |
6228 static int message_handler_break_hit_count = 0; | 6228 static int message_handler_break_hit_count = 0; |
6229 static void DebugBreakMessageHandler(const v8::Debug::Message& message) { | 6229 static void DebugBreakMessageHandler(const v8::Debug::Message& message) { |
6230 // Schedule a debug break for break events. | 6230 // Schedule a debug break for break events. |
6231 if (message.IsEvent() && message.GetEvent() == v8::Break) { | 6231 if (message.IsEvent() && message.GetEvent() == v8::Break) { |
6232 message_handler_break_hit_count++; | 6232 message_handler_break_hit_count++; |
6233 if (message_handler_break_hit_count == 1) { | 6233 if (message_handler_break_hit_count == 1) { |
6234 v8::Debug::DebugBreak(message.GetIsolate()); | 6234 v8::Debug::DebugBreak(message.GetIsolate()); |
6235 } | 6235 } |
6236 } | 6236 } |
6237 | 6237 |
6238 // Issue a continue command if this event will not cause the VM to start | 6238 // Issue a continue command if this event will not cause the VM to start |
6239 // running. | 6239 // running. |
6240 if (!message.WillStartRunning()) { | 6240 if (!message.WillStartRunning()) { |
6241 SendContinueCommand(); | 6241 SendContinueCommand(); |
6242 } | 6242 } |
6243 } | 6243 } |
6244 | 6244 |
6245 | 6245 |
6246 // Test that a debug break can be scheduled while in a message handler. | 6246 // Test that a debug break can be scheduled while in a message handler. |
6247 TEST(DebugBreakInMessageHandler) { | 6247 TEST(DebugBreakInMessageHandler) { |
6248 DebugLocalContext env; | 6248 DebugLocalContext env; |
6249 v8::HandleScope scope(env->GetIsolate()); | 6249 v8::HandleScope scope(env->GetIsolate()); |
6250 | 6250 |
6251 v8::Debug::SetMessageHandler2(DebugBreakMessageHandler); | 6251 v8::Debug::SetMessageHandler(DebugBreakMessageHandler); |
6252 | 6252 |
6253 // Test functions. | 6253 // Test functions. |
6254 const char* script = "function f() { debugger; g(); } function g() { }"; | 6254 const char* script = "function f() { debugger; g(); } function g() { }"; |
6255 CompileRun(script); | 6255 CompileRun(script); |
6256 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 6256 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
6257 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6257 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6258 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 6258 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
6259 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 6259 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); |
6260 | 6260 |
6261 // Call f then g. The debugger statement in f will casue a break which will | 6261 // Call f then g. The debugger statement in f will casue a break which will |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6321 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" | 6321 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" |
6322 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; | 6322 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; |
6323 | 6323 |
6324 v8::Local<v8::Function> f = CompileFunction(env->GetIsolate(), script, "f"); | 6324 v8::Local<v8::Function> f = CompileFunction(env->GetIsolate(), script, "f"); |
6325 const int argc = 1; | 6325 const int argc = 1; |
6326 v8::Handle<v8::Value> argv[argc] = { | 6326 v8::Handle<v8::Value> argv[argc] = { |
6327 v8::String::NewFromUtf8(env->GetIsolate(), " /* xxx */ a=0;")}; | 6327 v8::String::NewFromUtf8(env->GetIsolate(), " /* xxx */ a=0;")}; |
6328 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); | 6328 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); |
6329 CHECK_EQ(12, result->Int32Value()); | 6329 CHECK_EQ(12, result->Int32Value()); |
6330 | 6330 |
6331 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak); | 6331 v8::Debug::SetDebugEventListener(DebugEventDebugBreak); |
6332 v8::Debug::DebugBreak(env->GetIsolate()); | 6332 v8::Debug::DebugBreak(env->GetIsolate()); |
6333 result = f->Call(env->Global(), argc, argv); | 6333 result = f->Call(env->Global(), argc, argv); |
6334 | 6334 |
6335 // Check that there was only one break event. Matching RegExp should not | 6335 // Check that there was only one break event. Matching RegExp should not |
6336 // cause Break events. | 6336 // cause Break events. |
6337 CHECK_EQ(1, break_point_hit_count); | 6337 CHECK_EQ(1, break_point_hit_count); |
6338 CHECK_EQ("f", last_function_hit); | 6338 CHECK_EQ("f", last_function_hit); |
6339 } | 6339 } |
6340 #endif // V8_INTERPRETED_REGEXP | 6340 #endif // V8_INTERPRETED_REGEXP |
6341 | 6341 |
6342 | 6342 |
6343 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6343 // Common part of EvalContextData and NestedBreakEventContextData tests. |
6344 static void ExecuteScriptForContextCheck( | 6344 static void ExecuteScriptForContextCheck( |
6345 v8::Debug::MessageHandler2 message_handler) { | 6345 v8::Debug::MessageHandler message_handler) { |
6346 // Create a context. | 6346 // Create a context. |
6347 v8::Handle<v8::Context> context_1; | 6347 v8::Handle<v8::Context> context_1; |
6348 v8::Handle<v8::ObjectTemplate> global_template = | 6348 v8::Handle<v8::ObjectTemplate> global_template = |
6349 v8::Handle<v8::ObjectTemplate>(); | 6349 v8::Handle<v8::ObjectTemplate>(); |
6350 context_1 = | 6350 context_1 = |
6351 v8::Context::New(CcTest::isolate(), NULL, global_template); | 6351 v8::Context::New(CcTest::isolate(), NULL, global_template); |
6352 | 6352 |
6353 v8::Debug::SetMessageHandler2(message_handler); | 6353 v8::Debug::SetMessageHandler(message_handler); |
6354 | 6354 |
6355 // Default data value is undefined. | 6355 // Default data value is undefined. |
6356 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6356 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6357 | 6357 |
6358 // Set and check a data value. | 6358 // Set and check a data value. |
6359 v8::Handle<v8::String> data_1 = | 6359 v8::Handle<v8::String> data_1 = |
6360 v8::String::NewFromUtf8(CcTest::isolate(), "1"); | 6360 v8::String::NewFromUtf8(CcTest::isolate(), "1"); |
6361 context_1->SetEmbedderData(0, data_1); | 6361 context_1->SetEmbedderData(0, data_1); |
6362 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6362 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6363 | 6363 |
6364 // Simple test function with eval that causes a break. | 6364 // Simple test function with eval that causes a break. |
6365 const char* source = "function f() { eval('debugger;'); }"; | 6365 const char* source = "function f() { eval('debugger;'); }"; |
6366 | 6366 |
6367 // Enter and run function in the context. | 6367 // Enter and run function in the context. |
6368 { | 6368 { |
6369 v8::Context::Scope context_scope(context_1); | 6369 v8::Context::Scope context_scope(context_1); |
6370 expected_context = context_1; | 6370 expected_context = context_1; |
6371 expected_context_data = data_1; | 6371 expected_context_data = data_1; |
6372 v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f"); | 6372 v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f"); |
6373 f->Call(context_1->Global(), 0, NULL); | 6373 f->Call(context_1->Global(), 0, NULL); |
6374 } | 6374 } |
6375 | 6375 |
6376 v8::Debug::SetMessageHandler2(NULL); | 6376 v8::Debug::SetMessageHandler(NULL); |
6377 } | 6377 } |
6378 | 6378 |
6379 | 6379 |
6380 // Test which creates a context and sets embedder data on it. Checks that this | 6380 // Test which creates a context and sets embedder data on it. Checks that this |
6381 // data is set correctly and that when the debug message handler is called for | 6381 // data is set correctly and that when the debug message handler is called for |
6382 // break event in an eval statement the expected context is the one returned by | 6382 // break event in an eval statement the expected context is the one returned by |
6383 // Message.GetEventContext. | 6383 // Message.GetEventContext. |
6384 TEST(EvalContextData) { | 6384 TEST(EvalContextData) { |
6385 v8::HandleScope scope(CcTest::isolate()); | 6385 v8::HandleScope scope(CcTest::isolate()); |
6386 | 6386 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6481 v8::HandleScope scope(env->GetIsolate()); | 6481 v8::HandleScope scope(env->GetIsolate()); |
6482 | 6482 |
6483 // Request the loaded scripts to initialize the debugger script cache. | 6483 // Request the loaded scripts to initialize the debugger script cache. |
6484 debug->GetLoadedScripts(); | 6484 debug->GetLoadedScripts(); |
6485 | 6485 |
6486 // Do garbage collection to ensure that only the script in this test will be | 6486 // Do garbage collection to ensure that only the script in this test will be |
6487 // collected afterwards. | 6487 // collected afterwards. |
6488 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6488 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6489 | 6489 |
6490 script_collected_count = 0; | 6490 script_collected_count = 0; |
6491 v8::Debug::SetDebugEventListener2(DebugEventScriptCollectedEvent); | 6491 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent); |
6492 { | 6492 { |
6493 v8::Script::Compile( | 6493 v8::Script::Compile( |
6494 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=1')"))->Run(); | 6494 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=1')"))->Run(); |
6495 v8::Script::Compile( | 6495 v8::Script::Compile( |
6496 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=2')"))->Run(); | 6496 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=2')"))->Run(); |
6497 } | 6497 } |
6498 | 6498 |
6499 // Do garbage collection to collect the script above which is no longer | 6499 // Do garbage collection to collect the script above which is no longer |
6500 // referenced. | 6500 // referenced. |
6501 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6501 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6502 | 6502 |
6503 CHECK_EQ(2, script_collected_count); | 6503 CHECK_EQ(2, script_collected_count); |
6504 | 6504 |
6505 v8::Debug::SetDebugEventListener2(NULL); | 6505 v8::Debug::SetDebugEventListener(NULL); |
6506 CheckDebuggerUnloaded(); | 6506 CheckDebuggerUnloaded(); |
6507 } | 6507 } |
6508 | 6508 |
6509 | 6509 |
6510 // Debug event listener which counts the script collected events. | 6510 // Debug event listener which counts the script collected events. |
6511 int script_collected_message_count = 0; | 6511 int script_collected_message_count = 0; |
6512 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { | 6512 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { |
6513 // Count the number of scripts collected. | 6513 // Count the number of scripts collected. |
6514 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { | 6514 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { |
6515 script_collected_message_count++; | 6515 script_collected_message_count++; |
(...skipping 28 matching lines...) Expand all Loading... |
6544 local_context->Enter(); | 6544 local_context->Enter(); |
6545 } | 6545 } |
6546 | 6546 |
6547 // Request the loaded scripts to initialize the debugger script cache. | 6547 // Request the loaded scripts to initialize the debugger script cache. |
6548 debug->GetLoadedScripts(); | 6548 debug->GetLoadedScripts(); |
6549 | 6549 |
6550 // Do garbage collection to ensure that only the script in this test will be | 6550 // Do garbage collection to ensure that only the script in this test will be |
6551 // collected afterwards. | 6551 // collected afterwards. |
6552 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6552 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6553 | 6553 |
6554 v8::Debug::SetMessageHandler2(ScriptCollectedMessageHandler); | 6554 v8::Debug::SetMessageHandler(ScriptCollectedMessageHandler); |
6555 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=1')"))->Run(); | 6555 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=1')"))->Run(); |
6556 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=2')"))->Run(); | 6556 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=2')"))->Run(); |
6557 | 6557 |
6558 // Leave context | 6558 // Leave context |
6559 { | 6559 { |
6560 v8::HandleScope scope(isolate); | 6560 v8::HandleScope scope(isolate); |
6561 v8::Local<v8::Context> local_context = | 6561 v8::Local<v8::Context> local_context = |
6562 v8::Local<v8::Context>::New(isolate, context); | 6562 v8::Local<v8::Context>::New(isolate, context); |
6563 local_context->Exit(); | 6563 local_context->Exit(); |
6564 } | 6564 } |
6565 context.Reset(); | 6565 context.Reset(); |
6566 | 6566 |
6567 // Do garbage collection to collect the script above which is no longer | 6567 // Do garbage collection to collect the script above which is no longer |
6568 // referenced. | 6568 // referenced. |
6569 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6569 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
6570 | 6570 |
6571 CHECK_EQ(2, script_collected_message_count); | 6571 CHECK_EQ(2, script_collected_message_count); |
6572 | 6572 |
6573 v8::Debug::SetMessageHandler2(NULL); | 6573 v8::Debug::SetMessageHandler(NULL); |
6574 } | 6574 } |
6575 | 6575 |
6576 | 6576 |
6577 // Debug event listener which counts the after compile events. | 6577 // Debug event listener which counts the after compile events. |
6578 int after_compile_message_count = 0; | 6578 int after_compile_message_count = 0; |
6579 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { | 6579 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { |
6580 // Count the number of scripts collected. | 6580 // Count the number of scripts collected. |
6581 if (message.IsEvent()) { | 6581 if (message.IsEvent()) { |
6582 if (message.GetEvent() == v8::AfterCompile) { | 6582 if (message.GetEvent() == v8::AfterCompile) { |
6583 after_compile_message_count++; | 6583 after_compile_message_count++; |
6584 } else if (message.GetEvent() == v8::Break) { | 6584 } else if (message.GetEvent() == v8::Break) { |
6585 SendContinueCommand(); | 6585 SendContinueCommand(); |
6586 } | 6586 } |
6587 } | 6587 } |
6588 } | 6588 } |
6589 | 6589 |
6590 | 6590 |
6591 // Tests that after compile event is sent as many times as there are scripts | 6591 // Tests that after compile event is sent as many times as there are scripts |
6592 // compiled. | 6592 // compiled. |
6593 TEST(AfterCompileMessageWhenMessageHandlerIsReset) { | 6593 TEST(AfterCompileMessageWhenMessageHandlerIsReset) { |
6594 DebugLocalContext env; | 6594 DebugLocalContext env; |
6595 v8::HandleScope scope(env->GetIsolate()); | 6595 v8::HandleScope scope(env->GetIsolate()); |
6596 after_compile_message_count = 0; | 6596 after_compile_message_count = 0; |
6597 const char* script = "var a=1"; | 6597 const char* script = "var a=1"; |
6598 | 6598 |
6599 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6599 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6600 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) | 6600 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) |
6601 ->Run(); | 6601 ->Run(); |
6602 v8::Debug::SetMessageHandler2(NULL); | 6602 v8::Debug::SetMessageHandler(NULL); |
6603 | 6603 |
6604 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6604 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6605 v8::Debug::DebugBreak(env->GetIsolate()); | 6605 v8::Debug::DebugBreak(env->GetIsolate()); |
6606 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) | 6606 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) |
6607 ->Run(); | 6607 ->Run(); |
6608 | 6608 |
6609 // Setting listener to NULL should cause debugger unload. | 6609 // Setting listener to NULL should cause debugger unload. |
6610 v8::Debug::SetMessageHandler2(NULL); | 6610 v8::Debug::SetMessageHandler(NULL); |
6611 CheckDebuggerUnloaded(); | 6611 CheckDebuggerUnloaded(); |
6612 | 6612 |
6613 // Compilation cache should be disabled when debugger is active. | 6613 // Compilation cache should be disabled when debugger is active. |
6614 CHECK_EQ(2, after_compile_message_count); | 6614 CHECK_EQ(2, after_compile_message_count); |
6615 } | 6615 } |
6616 | 6616 |
6617 | 6617 |
6618 // Tests that break event is sent when message handler is reset. | 6618 // Tests that break event is sent when message handler is reset. |
6619 TEST(BreakMessageWhenMessageHandlerIsReset) { | 6619 TEST(BreakMessageWhenMessageHandlerIsReset) { |
6620 DebugLocalContext env; | 6620 DebugLocalContext env; |
6621 v8::HandleScope scope(env->GetIsolate()); | 6621 v8::HandleScope scope(env->GetIsolate()); |
6622 after_compile_message_count = 0; | 6622 after_compile_message_count = 0; |
6623 const char* script = "function f() {};"; | 6623 const char* script = "function f() {};"; |
6624 | 6624 |
6625 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6625 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6626 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) | 6626 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) |
6627 ->Run(); | 6627 ->Run(); |
6628 v8::Debug::SetMessageHandler2(NULL); | 6628 v8::Debug::SetMessageHandler(NULL); |
6629 | 6629 |
6630 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6630 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6631 v8::Debug::DebugBreak(env->GetIsolate()); | 6631 v8::Debug::DebugBreak(env->GetIsolate()); |
6632 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 6632 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
6633 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6633 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6634 f->Call(env->Global(), 0, NULL); | 6634 f->Call(env->Global(), 0, NULL); |
6635 | 6635 |
6636 // Setting message handler to NULL should cause debugger unload. | 6636 // Setting message handler to NULL should cause debugger unload. |
6637 v8::Debug::SetMessageHandler2(NULL); | 6637 v8::Debug::SetMessageHandler(NULL); |
6638 CheckDebuggerUnloaded(); | 6638 CheckDebuggerUnloaded(); |
6639 | 6639 |
6640 // Compilation cache should be disabled when debugger is active. | 6640 // Compilation cache should be disabled when debugger is active. |
6641 CHECK_EQ(1, after_compile_message_count); | 6641 CHECK_EQ(1, after_compile_message_count); |
6642 } | 6642 } |
6643 | 6643 |
6644 | 6644 |
6645 static int exception_event_count = 0; | 6645 static int exception_event_count = 0; |
6646 static void ExceptionMessageHandler(const v8::Debug::Message& message) { | 6646 static void ExceptionMessageHandler(const v8::Debug::Message& message) { |
6647 if (message.IsEvent() && message.GetEvent() == v8::Exception) { | 6647 if (message.IsEvent() && message.GetEvent() == v8::Exception) { |
6648 exception_event_count++; | 6648 exception_event_count++; |
6649 SendContinueCommand(); | 6649 SendContinueCommand(); |
6650 } | 6650 } |
6651 } | 6651 } |
6652 | 6652 |
6653 | 6653 |
6654 // Tests that exception event is sent when message handler is reset. | 6654 // Tests that exception event is sent when message handler is reset. |
6655 TEST(ExceptionMessageWhenMessageHandlerIsReset) { | 6655 TEST(ExceptionMessageWhenMessageHandlerIsReset) { |
6656 DebugLocalContext env; | 6656 DebugLocalContext env; |
6657 v8::HandleScope scope(env->GetIsolate()); | 6657 v8::HandleScope scope(env->GetIsolate()); |
6658 | 6658 |
6659 // For this test, we want to break on uncaught exceptions: | 6659 // For this test, we want to break on uncaught exceptions: |
6660 ChangeBreakOnException(false, true); | 6660 ChangeBreakOnException(false, true); |
6661 | 6661 |
6662 exception_event_count = 0; | 6662 exception_event_count = 0; |
6663 const char* script = "function f() {throw new Error()};"; | 6663 const char* script = "function f() {throw new Error()};"; |
6664 | 6664 |
6665 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6665 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6666 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) | 6666 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script)) |
6667 ->Run(); | 6667 ->Run(); |
6668 v8::Debug::SetMessageHandler2(NULL); | 6668 v8::Debug::SetMessageHandler(NULL); |
6669 | 6669 |
6670 v8::Debug::SetMessageHandler2(ExceptionMessageHandler); | 6670 v8::Debug::SetMessageHandler(ExceptionMessageHandler); |
6671 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 6671 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
6672 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 6672 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
6673 f->Call(env->Global(), 0, NULL); | 6673 f->Call(env->Global(), 0, NULL); |
6674 | 6674 |
6675 // Setting message handler to NULL should cause debugger unload. | 6675 // Setting message handler to NULL should cause debugger unload. |
6676 v8::Debug::SetMessageHandler2(NULL); | 6676 v8::Debug::SetMessageHandler(NULL); |
6677 CheckDebuggerUnloaded(); | 6677 CheckDebuggerUnloaded(); |
6678 | 6678 |
6679 CHECK_EQ(1, exception_event_count); | 6679 CHECK_EQ(1, exception_event_count); |
6680 } | 6680 } |
6681 | 6681 |
6682 | 6682 |
6683 // Tests after compile event is sent when there are some provisional | 6683 // Tests after compile event is sent when there are some provisional |
6684 // breakpoints out of the scripts lines range. | 6684 // breakpoints out of the scripts lines range. |
6685 TEST(ProvisionalBreakpointOnLineOutOfRange) { | 6685 TEST(ProvisionalBreakpointOnLineOutOfRange) { |
6686 DebugLocalContext env; | 6686 DebugLocalContext env; |
6687 v8::HandleScope scope(env->GetIsolate()); | 6687 v8::HandleScope scope(env->GetIsolate()); |
6688 env.ExposeDebug(); | 6688 env.ExposeDebug(); |
6689 const char* script = "function f() {};"; | 6689 const char* script = "function f() {};"; |
6690 const char* resource_name = "test_resource"; | 6690 const char* resource_name = "test_resource"; |
6691 | 6691 |
6692 // Set a couple of provisional breakpoint on lines out of the script lines | 6692 // Set a couple of provisional breakpoint on lines out of the script lines |
6693 // range. | 6693 // range. |
6694 int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, | 6694 int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, |
6695 3, -1 /* no column */); | 6695 3, -1 /* no column */); |
6696 int sbp2 = | 6696 int sbp2 = |
6697 SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5); | 6697 SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5); |
6698 | 6698 |
6699 after_compile_message_count = 0; | 6699 after_compile_message_count = 0; |
6700 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); | 6700 v8::Debug::SetMessageHandler(AfterCompileMessageHandler); |
6701 | 6701 |
6702 v8::ScriptOrigin origin( | 6702 v8::ScriptOrigin origin( |
6703 v8::String::NewFromUtf8(env->GetIsolate(), resource_name), | 6703 v8::String::NewFromUtf8(env->GetIsolate(), resource_name), |
6704 v8::Integer::New(env->GetIsolate(), 10), | 6704 v8::Integer::New(env->GetIsolate(), 10), |
6705 v8::Integer::New(env->GetIsolate(), 1)); | 6705 v8::Integer::New(env->GetIsolate(), 1)); |
6706 // Compile a script whose first line number is greater than the breakpoints' | 6706 // Compile a script whose first line number is greater than the breakpoints' |
6707 // lines. | 6707 // lines. |
6708 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script), | 6708 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), script), |
6709 &origin)->Run(); | 6709 &origin)->Run(); |
6710 | 6710 |
6711 // If the script is compiled successfully there is exactly one after compile | 6711 // If the script is compiled successfully there is exactly one after compile |
6712 // event. In case of an exception in debugger code after compile event is not | 6712 // event. In case of an exception in debugger code after compile event is not |
6713 // sent. | 6713 // sent. |
6714 CHECK_EQ(1, after_compile_message_count); | 6714 CHECK_EQ(1, after_compile_message_count); |
6715 | 6715 |
6716 ClearBreakPointFromJS(env->GetIsolate(), sbp1); | 6716 ClearBreakPointFromJS(env->GetIsolate(), sbp1); |
6717 ClearBreakPointFromJS(env->GetIsolate(), sbp2); | 6717 ClearBreakPointFromJS(env->GetIsolate(), sbp2); |
6718 v8::Debug::SetMessageHandler2(NULL); | 6718 v8::Debug::SetMessageHandler(NULL); |
6719 } | 6719 } |
6720 | 6720 |
6721 | 6721 |
6722 static void BreakMessageHandler(const v8::Debug::Message& message) { | 6722 static void BreakMessageHandler(const v8::Debug::Message& message) { |
6723 i::Isolate* isolate = CcTest::i_isolate(); | 6723 i::Isolate* isolate = CcTest::i_isolate(); |
6724 if (message.IsEvent() && message.GetEvent() == v8::Break) { | 6724 if (message.IsEvent() && message.GetEvent() == v8::Break) { |
6725 // Count the number of breaks. | 6725 // Count the number of breaks. |
6726 break_point_hit_count++; | 6726 break_point_hit_count++; |
6727 | 6727 |
6728 i::HandleScope scope(isolate); | 6728 i::HandleScope scope(isolate); |
(...skipping 20 matching lines...) Expand all Loading... |
6749 } | 6749 } |
6750 | 6750 |
6751 | 6751 |
6752 // Test that if DebugBreak is forced it is ignored when code from | 6752 // Test that if DebugBreak is forced it is ignored when code from |
6753 // debug-delay.js is executed. | 6753 // debug-delay.js is executed. |
6754 TEST(NoDebugBreakInAfterCompileMessageHandler) { | 6754 TEST(NoDebugBreakInAfterCompileMessageHandler) { |
6755 DebugLocalContext env; | 6755 DebugLocalContext env; |
6756 v8::HandleScope scope(env->GetIsolate()); | 6756 v8::HandleScope scope(env->GetIsolate()); |
6757 | 6757 |
6758 // Register a debug event listener which sets the break flag and counts. | 6758 // Register a debug event listener which sets the break flag and counts. |
6759 v8::Debug::SetMessageHandler2(BreakMessageHandler); | 6759 v8::Debug::SetMessageHandler(BreakMessageHandler); |
6760 | 6760 |
6761 // Set the debug break flag. | 6761 // Set the debug break flag. |
6762 v8::Debug::DebugBreak(env->GetIsolate()); | 6762 v8::Debug::DebugBreak(env->GetIsolate()); |
6763 | 6763 |
6764 // Create a function for testing stepping. | 6764 // Create a function for testing stepping. |
6765 const char* src = "function f() { eval('var x = 10;'); } "; | 6765 const char* src = "function f() { eval('var x = 10;'); } "; |
6766 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); | 6766 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); |
6767 | 6767 |
6768 // There should be only one break event. | 6768 // There should be only one break event. |
6769 CHECK_EQ(1, break_point_hit_count); | 6769 CHECK_EQ(1, break_point_hit_count); |
6770 | 6770 |
6771 // Set the debug break flag again. | 6771 // Set the debug break flag again. |
6772 v8::Debug::DebugBreak(env->GetIsolate()); | 6772 v8::Debug::DebugBreak(env->GetIsolate()); |
6773 f->Call(env->Global(), 0, NULL); | 6773 f->Call(env->Global(), 0, NULL); |
6774 // There should be one more break event when the script is evaluated in 'f'. | 6774 // There should be one more break event when the script is evaluated in 'f'. |
6775 CHECK_EQ(2, break_point_hit_count); | 6775 CHECK_EQ(2, break_point_hit_count); |
6776 | 6776 |
6777 // Get rid of the debug message handler. | 6777 // Get rid of the debug message handler. |
6778 v8::Debug::SetMessageHandler2(NULL); | 6778 v8::Debug::SetMessageHandler(NULL); |
6779 CheckDebuggerUnloaded(); | 6779 CheckDebuggerUnloaded(); |
6780 } | 6780 } |
6781 | 6781 |
6782 | 6782 |
6783 static int counting_message_handler_counter; | 6783 static int counting_message_handler_counter; |
6784 | 6784 |
6785 static void CountingMessageHandler(const v8::Debug::Message& message) { | 6785 static void CountingMessageHandler(const v8::Debug::Message& message) { |
6786 counting_message_handler_counter++; | 6786 counting_message_handler_counter++; |
6787 } | 6787 } |
6788 | 6788 |
6789 | 6789 |
6790 // Test that debug messages get processed when ProcessDebugMessages is called. | 6790 // Test that debug messages get processed when ProcessDebugMessages is called. |
6791 TEST(ProcessDebugMessages) { | 6791 TEST(ProcessDebugMessages) { |
6792 DebugLocalContext env; | 6792 DebugLocalContext env; |
6793 v8::Isolate* isolate = env->GetIsolate(); | 6793 v8::Isolate* isolate = env->GetIsolate(); |
6794 v8::HandleScope scope(isolate); | 6794 v8::HandleScope scope(isolate); |
6795 | 6795 |
6796 counting_message_handler_counter = 0; | 6796 counting_message_handler_counter = 0; |
6797 | 6797 |
6798 v8::Debug::SetMessageHandler2(CountingMessageHandler); | 6798 v8::Debug::SetMessageHandler(CountingMessageHandler); |
6799 | 6799 |
6800 const int kBufferSize = 1000; | 6800 const int kBufferSize = 1000; |
6801 uint16_t buffer[kBufferSize]; | 6801 uint16_t buffer[kBufferSize]; |
6802 const char* scripts_command = | 6802 const char* scripts_command = |
6803 "{\"seq\":0," | 6803 "{\"seq\":0," |
6804 "\"type\":\"request\"," | 6804 "\"type\":\"request\"," |
6805 "\"command\":\"scripts\"}"; | 6805 "\"command\":\"scripts\"}"; |
6806 | 6806 |
6807 // Send scripts command. | 6807 // Send scripts command. |
6808 v8::Debug::SendCommand( | 6808 v8::Debug::SendCommand( |
6809 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); | 6809 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); |
6810 | 6810 |
6811 CHECK_EQ(0, counting_message_handler_counter); | 6811 CHECK_EQ(0, counting_message_handler_counter); |
6812 v8::Debug::ProcessDebugMessages(); | 6812 v8::Debug::ProcessDebugMessages(); |
6813 // At least one message should come | 6813 // At least one message should come |
6814 CHECK_GE(counting_message_handler_counter, 1); | 6814 CHECK_GE(counting_message_handler_counter, 1); |
6815 | 6815 |
6816 counting_message_handler_counter = 0; | 6816 counting_message_handler_counter = 0; |
6817 | 6817 |
6818 v8::Debug::SendCommand( | 6818 v8::Debug::SendCommand( |
6819 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); | 6819 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); |
6820 v8::Debug::SendCommand( | 6820 v8::Debug::SendCommand( |
6821 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); | 6821 isolate, buffer, AsciiToUtf16(scripts_command, buffer)); |
6822 CHECK_EQ(0, counting_message_handler_counter); | 6822 CHECK_EQ(0, counting_message_handler_counter); |
6823 v8::Debug::ProcessDebugMessages(); | 6823 v8::Debug::ProcessDebugMessages(); |
6824 // At least two messages should come | 6824 // At least two messages should come |
6825 CHECK_GE(counting_message_handler_counter, 2); | 6825 CHECK_GE(counting_message_handler_counter, 2); |
6826 | 6826 |
6827 // Get rid of the debug message handler. | 6827 // Get rid of the debug message handler. |
6828 v8::Debug::SetMessageHandler2(NULL); | 6828 v8::Debug::SetMessageHandler(NULL); |
6829 CheckDebuggerUnloaded(); | 6829 CheckDebuggerUnloaded(); |
6830 } | 6830 } |
6831 | 6831 |
6832 | 6832 |
6833 struct BacktraceData { | 6833 struct BacktraceData { |
6834 static int frame_counter; | 6834 static int frame_counter; |
6835 static void MessageHandler(const v8::Debug::Message& message) { | 6835 static void MessageHandler(const v8::Debug::Message& message) { |
6836 char print_buffer[1000]; | 6836 char print_buffer[1000]; |
6837 v8::String::Value json(message.GetJSON()); | 6837 v8::String::Value json(message.GetJSON()); |
6838 Utf16ToAscii(*json, json.length(), print_buffer, 1000); | 6838 Utf16ToAscii(*json, json.length(), print_buffer, 1000); |
6839 | 6839 |
6840 if (strstr(print_buffer, "backtrace") == NULL) { | 6840 if (strstr(print_buffer, "backtrace") == NULL) { |
6841 return; | 6841 return; |
6842 } | 6842 } |
6843 frame_counter = GetTotalFramesInt(print_buffer); | 6843 frame_counter = GetTotalFramesInt(print_buffer); |
6844 } | 6844 } |
6845 }; | 6845 }; |
6846 | 6846 |
6847 int BacktraceData::frame_counter; | 6847 int BacktraceData::frame_counter; |
6848 | 6848 |
6849 | 6849 |
6850 // Test that debug messages get processed when ProcessDebugMessages is called. | 6850 // Test that debug messages get processed when ProcessDebugMessages is called. |
6851 TEST(Backtrace) { | 6851 TEST(Backtrace) { |
6852 DebugLocalContext env; | 6852 DebugLocalContext env; |
6853 v8::Isolate* isolate = env->GetIsolate(); | 6853 v8::Isolate* isolate = env->GetIsolate(); |
6854 v8::HandleScope scope(isolate); | 6854 v8::HandleScope scope(isolate); |
6855 | 6855 |
6856 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler); | 6856 v8::Debug::SetMessageHandler(BacktraceData::MessageHandler); |
6857 | 6857 |
6858 const int kBufferSize = 1000; | 6858 const int kBufferSize = 1000; |
6859 uint16_t buffer[kBufferSize]; | 6859 uint16_t buffer[kBufferSize]; |
6860 const char* scripts_command = | 6860 const char* scripts_command = |
6861 "{\"seq\":0," | 6861 "{\"seq\":0," |
6862 "\"type\":\"request\"," | 6862 "\"type\":\"request\"," |
6863 "\"command\":\"backtrace\"}"; | 6863 "\"command\":\"backtrace\"}"; |
6864 | 6864 |
6865 // Check backtrace from ProcessDebugMessages. | 6865 // Check backtrace from ProcessDebugMessages. |
6866 BacktraceData::frame_counter = -10; | 6866 BacktraceData::frame_counter = -10; |
(...skipping 13 matching lines...) Expand all Loading... |
6880 BacktraceData::frame_counter = -10; | 6880 BacktraceData::frame_counter = -10; |
6881 v8::Debug::SendCommand( | 6881 v8::Debug::SendCommand( |
6882 isolate, | 6882 isolate, |
6883 buffer, | 6883 buffer, |
6884 AsciiToUtf16(scripts_command, buffer), | 6884 AsciiToUtf16(scripts_command, buffer), |
6885 NULL); | 6885 NULL); |
6886 script->Run(); | 6886 script->Run(); |
6887 CHECK_EQ(BacktraceData::frame_counter, 1); | 6887 CHECK_EQ(BacktraceData::frame_counter, 1); |
6888 | 6888 |
6889 // Get rid of the debug message handler. | 6889 // Get rid of the debug message handler. |
6890 v8::Debug::SetMessageHandler2(NULL); | 6890 v8::Debug::SetMessageHandler(NULL); |
6891 CheckDebuggerUnloaded(); | 6891 CheckDebuggerUnloaded(); |
6892 } | 6892 } |
6893 | 6893 |
6894 | 6894 |
6895 TEST(GetMirror) { | 6895 TEST(GetMirror) { |
6896 DebugLocalContext env; | 6896 DebugLocalContext env; |
6897 v8::Isolate* isolate = env->GetIsolate(); | 6897 v8::Isolate* isolate = env->GetIsolate(); |
6898 v8::HandleScope scope(isolate); | 6898 v8::HandleScope scope(isolate); |
6899 v8::Handle<v8::Value> obj = | 6899 v8::Handle<v8::Value> obj = |
6900 v8::Debug::GetMirror(v8::String::NewFromUtf8(isolate, "hodja")); | 6900 v8::Debug::GetMirror(v8::String::NewFromUtf8(isolate, "hodja")); |
(...skipping 19 matching lines...) Expand all Loading... |
6920 | 6920 |
6921 // Create a function for testing breaking in apply. | 6921 // Create a function for testing breaking in apply. |
6922 v8::Local<v8::Function> foo = CompileFunction( | 6922 v8::Local<v8::Function> foo = CompileFunction( |
6923 &env, | 6923 &env, |
6924 "function baz(x) { }" | 6924 "function baz(x) { }" |
6925 "function bar(x) { baz(); }" | 6925 "function bar(x) { baz(); }" |
6926 "function foo(){ bar.apply(this, [1]); }", | 6926 "function foo(){ bar.apply(this, [1]); }", |
6927 "foo"); | 6927 "foo"); |
6928 | 6928 |
6929 // Register a debug event listener which steps and counts. | 6929 // Register a debug event listener which steps and counts. |
6930 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); | 6930 v8::Debug::SetDebugEventListener(DebugEventBreakMax); |
6931 | 6931 |
6932 // Set the debug break flag before calling the code using function.apply. | 6932 // Set the debug break flag before calling the code using function.apply. |
6933 v8::Debug::DebugBreak(env->GetIsolate()); | 6933 v8::Debug::DebugBreak(env->GetIsolate()); |
6934 | 6934 |
6935 // Limit the number of debug breaks. This is a regression test for issue 493 | 6935 // Limit the number of debug breaks. This is a regression test for issue 493 |
6936 // where this test would enter an infinite loop. | 6936 // where this test would enter an infinite loop. |
6937 break_point_hit_count = 0; | 6937 break_point_hit_count = 0; |
6938 max_break_point_hit_count = 10000; // 10000 => infinite loop. | 6938 max_break_point_hit_count = 10000; // 10000 => infinite loop. |
6939 foo->Call(env->Global(), 0, NULL); | 6939 foo->Call(env->Global(), 0, NULL); |
6940 | 6940 |
6941 // When keeping the debug break several break will happen. | 6941 // When keeping the debug break several break will happen. |
6942 CHECK_GT(break_point_hit_count, 1); | 6942 CHECK_GT(break_point_hit_count, 1); |
6943 | 6943 |
6944 v8::Debug::SetDebugEventListener2(NULL); | 6944 v8::Debug::SetDebugEventListener(NULL); |
6945 CheckDebuggerUnloaded(); | 6945 CheckDebuggerUnloaded(); |
6946 } | 6946 } |
6947 | 6947 |
6948 | 6948 |
6949 v8::Handle<v8::Context> debugee_context; | 6949 v8::Handle<v8::Context> debugee_context; |
6950 v8::Handle<v8::Context> debugger_context; | 6950 v8::Handle<v8::Context> debugger_context; |
6951 | 6951 |
6952 | 6952 |
6953 // Property getter that checks that current and calling contexts | 6953 // Property getter that checks that current and calling contexts |
6954 // are both the debugee contexts. | 6954 // are both the debugee contexts. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7003 debugger_context = v8::Utils::ToLocal(debug->debug_context()); | 7003 debugger_context = v8::Utils::ToLocal(debug->debug_context()); |
7004 | 7004 |
7005 // Create object with 'a' property accessor. | 7005 // Create object with 'a' property accessor. |
7006 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate); | 7006 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(isolate); |
7007 named->SetAccessor(v8::String::NewFromUtf8(isolate, "a"), | 7007 named->SetAccessor(v8::String::NewFromUtf8(isolate, "a"), |
7008 NamedGetterWithCallingContextCheck); | 7008 NamedGetterWithCallingContextCheck); |
7009 env->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), | 7009 env->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), |
7010 named->NewInstance()); | 7010 named->NewInstance()); |
7011 | 7011 |
7012 // Register the debug event listener | 7012 // Register the debug event listener |
7013 v8::Debug::SetDebugEventListener2(DebugEventGetAtgumentPropertyValue); | 7013 v8::Debug::SetDebugEventListener(DebugEventGetAtgumentPropertyValue); |
7014 | 7014 |
7015 // Create a function that invokes debugger. | 7015 // Create a function that invokes debugger. |
7016 v8::Local<v8::Function> foo = CompileFunction( | 7016 v8::Local<v8::Function> foo = CompileFunction( |
7017 &env, | 7017 &env, |
7018 "function bar(x) { debugger; }" | 7018 "function bar(x) { debugger; }" |
7019 "function foo(){ bar(obj); }", | 7019 "function foo(){ bar(obj); }", |
7020 "foo"); | 7020 "foo"); |
7021 | 7021 |
7022 break_point_hit_count = 0; | 7022 break_point_hit_count = 0; |
7023 foo->Call(env->Global(), 0, NULL); | 7023 foo->Call(env->Global(), 0, NULL); |
7024 CHECK_EQ(1, break_point_hit_count); | 7024 CHECK_EQ(1, break_point_hit_count); |
7025 | 7025 |
7026 v8::Debug::SetDebugEventListener2(NULL); | 7026 v8::Debug::SetDebugEventListener(NULL); |
7027 debugee_context = v8::Handle<v8::Context>(); | 7027 debugee_context = v8::Handle<v8::Context>(); |
7028 debugger_context = v8::Handle<v8::Context>(); | 7028 debugger_context = v8::Handle<v8::Context>(); |
7029 CheckDebuggerUnloaded(); | 7029 CheckDebuggerUnloaded(); |
7030 } | 7030 } |
7031 | 7031 |
7032 | 7032 |
7033 TEST(DebugContextIsPreservedBetweenAccesses) { | 7033 TEST(DebugContextIsPreservedBetweenAccesses) { |
7034 v8::HandleScope scope(CcTest::isolate()); | 7034 v8::HandleScope scope(CcTest::isolate()); |
7035 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); | 7035 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); |
7036 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); | 7036 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); |
7037 CHECK_EQ(*context1, *context2); | 7037 CHECK_EQ(*context1, *context2); |
7038 } | 7038 } |
7039 | 7039 |
7040 | 7040 |
7041 static v8::Handle<v8::Value> expected_callback_data; | 7041 static v8::Handle<v8::Value> expected_callback_data; |
7042 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { | 7042 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { |
7043 CHECK(details.GetEventContext() == expected_context); | 7043 CHECK(details.GetEventContext() == expected_context); |
7044 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 7044 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
7045 } | 7045 } |
7046 | 7046 |
7047 | 7047 |
7048 // Check that event details contain context where debug event occured. | 7048 // Check that event details contain context where debug event occured. |
7049 TEST(DebugEventContext) { | 7049 TEST(DebugEventContext) { |
7050 v8::Isolate* isolate = CcTest::isolate(); | 7050 v8::Isolate* isolate = CcTest::isolate(); |
7051 v8::HandleScope scope(isolate); | 7051 v8::HandleScope scope(isolate); |
7052 expected_context = v8::Context::New(isolate); | 7052 expected_context = v8::Context::New(isolate); |
7053 expected_callback_data = v8::Int32::New(isolate, 2010); | 7053 expected_callback_data = v8::Int32::New(isolate, 2010); |
7054 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7054 v8::Debug::SetDebugEventListener(DebugEventContextChecker, |
7055 expected_callback_data); | 7055 expected_callback_data); |
7056 v8::Context::Scope context_scope(expected_context); | 7056 v8::Context::Scope context_scope(expected_context); |
7057 v8::Script::Compile( | 7057 v8::Script::Compile( |
7058 v8::String::NewFromUtf8(isolate, "(function(){debugger;})();"))->Run(); | 7058 v8::String::NewFromUtf8(isolate, "(function(){debugger;})();"))->Run(); |
7059 expected_context.Clear(); | 7059 expected_context.Clear(); |
7060 v8::Debug::SetDebugEventListener2(NULL); | 7060 v8::Debug::SetDebugEventListener(NULL); |
7061 expected_context_data = v8::Handle<v8::Value>(); | 7061 expected_context_data = v8::Handle<v8::Value>(); |
7062 CheckDebuggerUnloaded(); | 7062 CheckDebuggerUnloaded(); |
7063 } | 7063 } |
7064 | 7064 |
7065 | 7065 |
7066 static void* expected_break_data; | 7066 static void* expected_break_data; |
7067 static bool was_debug_break_called; | 7067 static bool was_debug_break_called; |
7068 static bool was_debug_event_called; | 7068 static bool was_debug_event_called; |
7069 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) { | 7069 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) { |
7070 if (details.GetEvent() == v8::BreakForCommand) { | 7070 if (details.GetEvent() == v8::BreakForCommand) { |
7071 CHECK_EQ(expected_break_data, details.GetClientData()); | 7071 CHECK_EQ(expected_break_data, details.GetClientData()); |
7072 was_debug_event_called = true; | 7072 was_debug_event_called = true; |
7073 } else if (details.GetEvent() == v8::Break) { | 7073 } else if (details.GetEvent() == v8::Break) { |
7074 was_debug_break_called = true; | 7074 was_debug_break_called = true; |
7075 } | 7075 } |
7076 } | 7076 } |
7077 | 7077 |
7078 | 7078 |
7079 // Check that event details contain context where debug event occured. | 7079 // Check that event details contain context where debug event occured. |
7080 TEST(DebugEventBreakData) { | 7080 TEST(DebugEventBreakData) { |
7081 DebugLocalContext env; | 7081 DebugLocalContext env; |
7082 v8::Isolate* isolate = env->GetIsolate(); | 7082 v8::Isolate* isolate = env->GetIsolate(); |
7083 v8::HandleScope scope(isolate); | 7083 v8::HandleScope scope(isolate); |
7084 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker); | 7084 v8::Debug::SetDebugEventListener(DebugEventBreakDataChecker); |
7085 | 7085 |
7086 TestClientData::constructor_call_counter = 0; | 7086 TestClientData::constructor_call_counter = 0; |
7087 TestClientData::destructor_call_counter = 0; | 7087 TestClientData::destructor_call_counter = 0; |
7088 | 7088 |
7089 expected_break_data = NULL; | 7089 expected_break_data = NULL; |
7090 was_debug_event_called = false; | 7090 was_debug_event_called = false; |
7091 was_debug_break_called = false; | 7091 was_debug_break_called = false; |
7092 v8::Debug::DebugBreakForCommand(NULL, isolate); | 7092 v8::Debug::DebugBreakForCommand(NULL, isolate); |
7093 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 7093 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
7094 "(function(x){return x;})(1);")) | 7094 "(function(x){return x;})(1);")) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7126 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 7126 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
7127 "(function(x){return x+3;})(1);")) | 7127 "(function(x){return x+3;})(1);")) |
7128 ->Run(); | 7128 ->Run(); |
7129 CHECK(was_debug_event_called); | 7129 CHECK(was_debug_event_called); |
7130 CHECK(was_debug_break_called); | 7130 CHECK(was_debug_break_called); |
7131 | 7131 |
7132 CHECK_EQ(2, TestClientData::constructor_call_counter); | 7132 CHECK_EQ(2, TestClientData::constructor_call_counter); |
7133 CHECK_EQ(TestClientData::constructor_call_counter, | 7133 CHECK_EQ(TestClientData::constructor_call_counter, |
7134 TestClientData::destructor_call_counter); | 7134 TestClientData::destructor_call_counter); |
7135 | 7135 |
7136 v8::Debug::SetDebugEventListener2(NULL); | 7136 v8::Debug::SetDebugEventListener(NULL); |
7137 CheckDebuggerUnloaded(); | 7137 CheckDebuggerUnloaded(); |
7138 } | 7138 } |
7139 | 7139 |
7140 static bool debug_event_break_deoptimize_done = false; | 7140 static bool debug_event_break_deoptimize_done = false; |
7141 | 7141 |
7142 static void DebugEventBreakDeoptimize( | 7142 static void DebugEventBreakDeoptimize( |
7143 const v8::Debug::EventDetails& event_details) { | 7143 const v8::Debug::EventDetails& event_details) { |
7144 v8::DebugEvent event = event_details.GetEvent(); | 7144 v8::DebugEvent event = event_details.GetEvent(); |
7145 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); | 7145 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
7146 if (event == v8::Break) { | 7146 if (event == v8::Break) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7180 frame_function_name = CompileFunction(&env, | 7180 frame_function_name = CompileFunction(&env, |
7181 frame_function_name_source, | 7181 frame_function_name_source, |
7182 "frame_function_name"); | 7182 "frame_function_name"); |
7183 | 7183 |
7184 | 7184 |
7185 // Set a debug event listener which will keep interrupting execution until | 7185 // Set a debug event listener which will keep interrupting execution until |
7186 // debug break. When inside function bar it will deoptimize all functions. | 7186 // debug break. When inside function bar it will deoptimize all functions. |
7187 // This tests lazy deoptimization bailout for the stack check, as the first | 7187 // This tests lazy deoptimization bailout for the stack check, as the first |
7188 // time in function bar when using debug break and no break points will be at | 7188 // time in function bar when using debug break and no break points will be at |
7189 // the initial stack check. | 7189 // the initial stack check. |
7190 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize); | 7190 v8::Debug::SetDebugEventListener(DebugEventBreakDeoptimize); |
7191 | 7191 |
7192 // Compile and run function bar which will optimize it for some flag settings. | 7192 // Compile and run function bar which will optimize it for some flag settings. |
7193 v8::Script::Compile(v8::String::NewFromUtf8( | 7193 v8::Script::Compile(v8::String::NewFromUtf8( |
7194 env->GetIsolate(), "function bar(){}; bar()"))->Run(); | 7194 env->GetIsolate(), "function bar(){}; bar()"))->Run(); |
7195 | 7195 |
7196 // Set debug break and call bar again. | 7196 // Set debug break and call bar again. |
7197 v8::Debug::DebugBreak(env->GetIsolate()); | 7197 v8::Debug::DebugBreak(env->GetIsolate()); |
7198 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar()")) | 7198 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), "bar()")) |
7199 ->Run(); | 7199 ->Run(); |
7200 | 7200 |
7201 CHECK(debug_event_break_deoptimize_done); | 7201 CHECK(debug_event_break_deoptimize_done); |
7202 | 7202 |
7203 v8::Debug::SetDebugEventListener2(NULL); | 7203 v8::Debug::SetDebugEventListener(NULL); |
7204 } | 7204 } |
7205 | 7205 |
7206 | 7206 |
7207 static void DebugEventBreakWithOptimizedStack( | 7207 static void DebugEventBreakWithOptimizedStack( |
7208 const v8::Debug::EventDetails& event_details) { | 7208 const v8::Debug::EventDetails& event_details) { |
7209 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); | 7209 v8::Isolate* isolate = event_details.GetEventContext()->GetIsolate(); |
7210 v8::DebugEvent event = event_details.GetEvent(); | 7210 v8::DebugEvent event = event_details.GetEvent(); |
7211 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); | 7211 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); |
7212 if (event == v8::Break) { | 7212 if (event == v8::Break) { |
7213 if (!frame_function_name.IsEmpty()) { | 7213 if (!frame_function_name.IsEmpty()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7248 // optimized frames. | 7248 // optimized frames. |
7249 result = frame_local_value->Call(exec_state, argc, argv); | 7249 result = frame_local_value->Call(exec_state, argc, argv); |
7250 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); | 7250 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); |
7251 } | 7251 } |
7252 } | 7252 } |
7253 } | 7253 } |
7254 } | 7254 } |
7255 | 7255 |
7256 | 7256 |
7257 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7257 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7258 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack); | 7258 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack); |
7259 v8::Debug::DebugBreak(args.GetIsolate()); | 7259 v8::Debug::DebugBreak(args.GetIsolate()); |
7260 } | 7260 } |
7261 | 7261 |
7262 | 7262 |
7263 TEST(DebugBreakStackInspection) { | 7263 TEST(DebugBreakStackInspection) { |
7264 DebugLocalContext env; | 7264 DebugLocalContext env; |
7265 v8::HandleScope scope(env->GetIsolate()); | 7265 v8::HandleScope scope(env->GetIsolate()); |
7266 | 7266 |
7267 frame_function_name = | 7267 frame_function_name = |
7268 CompileFunction(&env, frame_function_name_source, "frame_function_name"); | 7268 CompileFunction(&env, frame_function_name_source, "frame_function_name"); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7331 } | 7331 } |
7332 } | 7332 } |
7333 } | 7333 } |
7334 | 7334 |
7335 | 7335 |
7336 TEST(DebugBreakLoop) { | 7336 TEST(DebugBreakLoop) { |
7337 DebugLocalContext env; | 7337 DebugLocalContext env; |
7338 v8::HandleScope scope(env->GetIsolate()); | 7338 v8::HandleScope scope(env->GetIsolate()); |
7339 | 7339 |
7340 // Register a debug event listener which sets the break flag and counts. | 7340 // Register a debug event listener which sets the break flag and counts. |
7341 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); | 7341 v8::Debug::SetDebugEventListener(DebugEventBreakMax); |
7342 | 7342 |
7343 // Create a function for getting the frame count when hitting the break. | 7343 // Create a function for getting the frame count when hitting the break. |
7344 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); | 7344 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); |
7345 | 7345 |
7346 CompileRun("var a = 1;"); | 7346 CompileRun("var a = 1;"); |
7347 CompileRun("function g() { }"); | 7347 CompileRun("function g() { }"); |
7348 CompileRun("function h() { }"); | 7348 CompileRun("function h() { }"); |
7349 | 7349 |
7350 const char* loop_bodies[] = { | 7350 const char* loop_bodies[] = { |
7351 "", | 7351 "", |
(...skipping 13 matching lines...) Expand all Loading... |
7365 TestDebugBreakInLoop("while (true) {", loop_bodies, "}"); | 7365 TestDebugBreakInLoop("while (true) {", loop_bodies, "}"); |
7366 TestDebugBreakInLoop("while (a == 1) {", loop_bodies, "}"); | 7366 TestDebugBreakInLoop("while (a == 1) {", loop_bodies, "}"); |
7367 | 7367 |
7368 TestDebugBreakInLoop("do {", loop_bodies, "} while (true)"); | 7368 TestDebugBreakInLoop("do {", loop_bodies, "} while (true)"); |
7369 TestDebugBreakInLoop("do {", loop_bodies, "} while (a == 1)"); | 7369 TestDebugBreakInLoop("do {", loop_bodies, "} while (a == 1)"); |
7370 | 7370 |
7371 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); | 7371 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); |
7372 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); | 7372 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); |
7373 | 7373 |
7374 // Get rid of the debug event listener. | 7374 // Get rid of the debug event listener. |
7375 v8::Debug::SetDebugEventListener2(NULL); | 7375 v8::Debug::SetDebugEventListener(NULL); |
7376 CheckDebuggerUnloaded(); | 7376 CheckDebuggerUnloaded(); |
7377 } | 7377 } |
7378 | 7378 |
7379 | 7379 |
7380 v8::Local<v8::Script> inline_script; | 7380 v8::Local<v8::Script> inline_script; |
7381 | 7381 |
7382 static void DebugBreakInlineListener( | 7382 static void DebugBreakInlineListener( |
7383 const v8::Debug::EventDetails& event_details) { | 7383 const v8::Debug::EventDetails& event_details) { |
7384 v8::DebugEvent event = event_details.GetEvent(); | 7384 v8::DebugEvent event = event_details.GetEvent(); |
7385 if (event != v8::Break) return; | 7385 if (event != v8::Break) return; |
(...skipping 15 matching lines...) Expand all Loading... |
7401 CHECK_EQ(expected_frame_count, frame_count); | 7401 CHECK_EQ(expected_frame_count, frame_count); |
7402 | 7402 |
7403 for (int i = 0; i < frame_count; i++) { | 7403 for (int i = 0; i < frame_count; i++) { |
7404 // The 5. element in the returned array of GetFrameDetails contains the | 7404 // The 5. element in the returned array of GetFrameDetails contains the |
7405 // source position of that frame. | 7405 // source position of that frame. |
7406 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); | 7406 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); |
7407 v8::Local<v8::Value> result = CompileRun(script); | 7407 v8::Local<v8::Value> result = CompileRun(script); |
7408 CHECK_EQ(expected_line_number[i], | 7408 CHECK_EQ(expected_line_number[i], |
7409 i::Script::GetLineNumber(source_script, result->Int32Value())); | 7409 i::Script::GetLineNumber(source_script, result->Int32Value())); |
7410 } | 7410 } |
7411 v8::Debug::SetDebugEventListener2(NULL); | 7411 v8::Debug::SetDebugEventListener(NULL); |
7412 v8::V8::TerminateExecution(CcTest::isolate()); | 7412 v8::V8::TerminateExecution(CcTest::isolate()); |
7413 } | 7413 } |
7414 | 7414 |
7415 | 7415 |
7416 TEST(DebugBreakInline) { | 7416 TEST(DebugBreakInline) { |
7417 i::FLAG_allow_natives_syntax = true; | 7417 i::FLAG_allow_natives_syntax = true; |
7418 DebugLocalContext env; | 7418 DebugLocalContext env; |
7419 v8::HandleScope scope(env->GetIsolate()); | 7419 v8::HandleScope scope(env->GetIsolate()); |
7420 const char* source = | 7420 const char* source = |
7421 "function debug(b) { \n" | 7421 "function debug(b) { \n" |
7422 " if (b) debugger; \n" | 7422 " if (b) debugger; \n" |
7423 "} \n" | 7423 "} \n" |
7424 "function f(b) { \n" | 7424 "function f(b) { \n" |
7425 " debug(b) \n" | 7425 " debug(b) \n" |
7426 "}; \n" | 7426 "}; \n" |
7427 "function g(b) { \n" | 7427 "function g(b) { \n" |
7428 " f(b); \n" | 7428 " f(b); \n" |
7429 "}; \n" | 7429 "}; \n" |
7430 "g(false); \n" | 7430 "g(false); \n" |
7431 "g(false); \n" | 7431 "g(false); \n" |
7432 "%OptimizeFunctionOnNextCall(g); \n" | 7432 "%OptimizeFunctionOnNextCall(g); \n" |
7433 "g(true);"; | 7433 "g(true);"; |
7434 v8::Debug::SetDebugEventListener2(DebugBreakInlineListener); | 7434 v8::Debug::SetDebugEventListener(DebugBreakInlineListener); |
7435 inline_script = | 7435 inline_script = |
7436 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source)); | 7436 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), source)); |
7437 inline_script->Run(); | 7437 inline_script->Run(); |
7438 } | 7438 } |
7439 | 7439 |
7440 | 7440 |
7441 static void DebugEventStepNext( | 7441 static void DebugEventStepNext( |
7442 const v8::Debug::EventDetails& event_details) { | 7442 const v8::Debug::EventDetails& event_details) { |
7443 v8::DebugEvent event = event_details.GetEvent(); | 7443 v8::DebugEvent event = event_details.GetEvent(); |
7444 if (event == v8::Break) { | 7444 if (event == v8::Break) { |
(...skipping 13 matching lines...) Expand all Loading... |
7458 // Bug description: | 7458 // Bug description: |
7459 // When doing StepNext through the first script, the debugger is not reset | 7459 // When doing StepNext through the first script, the debugger is not reset |
7460 // after exiting through exception. A flawed implementation enabling the | 7460 // after exiting through exception. A flawed implementation enabling the |
7461 // debugger to step into Array.prototype.forEach breaks inside the callback | 7461 // debugger to step into Array.prototype.forEach breaks inside the callback |
7462 // for forEach in the second script under the assumption that we are in a | 7462 // for forEach in the second script under the assumption that we are in a |
7463 // recursive call. In an attempt to step out, we crawl the stack using the | 7463 // recursive call. In an attempt to step out, we crawl the stack using the |
7464 // recorded frame pointer from the first script and fail when not finding it | 7464 // recorded frame pointer from the first script and fail when not finding it |
7465 // on the stack. | 7465 // on the stack. |
7466 DebugLocalContext env; | 7466 DebugLocalContext env; |
7467 v8::HandleScope scope(env->GetIsolate()); | 7467 v8::HandleScope scope(env->GetIsolate()); |
7468 v8::Debug::SetDebugEventListener2(DebugEventStepNext); | 7468 v8::Debug::SetDebugEventListener(DebugEventStepNext); |
7469 | 7469 |
7470 // We step through the first script. It exits through an exception. We run | 7470 // We step through the first script. It exits through an exception. We run |
7471 // this inside a new frame to record a different FP than the second script | 7471 // this inside a new frame to record a different FP than the second script |
7472 // would expect. | 7472 // would expect. |
7473 const char* script_1 = "debugger; throw new Error();"; | 7473 const char* script_1 = "debugger; throw new Error();"; |
7474 RunScriptInANewCFrame(script_1); | 7474 RunScriptInANewCFrame(script_1); |
7475 | 7475 |
7476 // The second script uses forEach. | 7476 // The second script uses forEach. |
7477 const char* script_2 = "[0].forEach(function() { });"; | 7477 const char* script_2 = "[0].forEach(function() { });"; |
7478 CompileRun(script_2); | 7478 CompileRun(script_2); |
7479 | 7479 |
7480 v8::Debug::SetDebugEventListener2(NULL); | 7480 v8::Debug::SetDebugEventListener(NULL); |
7481 } | 7481 } |
7482 | 7482 |
7483 | 7483 |
7484 // Import from test-heap.cc | 7484 // Import from test-heap.cc |
7485 int CountNativeContexts(); | 7485 int CountNativeContexts(); |
7486 | 7486 |
7487 | 7487 |
7488 static void NopListener(const v8::Debug::EventDetails& event_details) { | 7488 static void NopListener(const v8::Debug::EventDetails& event_details) { |
7489 } | 7489 } |
7490 | 7490 |
7491 | 7491 |
7492 TEST(DebuggerCreatesContextIffActive) { | 7492 TEST(DebuggerCreatesContextIffActive) { |
7493 DebugLocalContext env; | 7493 DebugLocalContext env; |
7494 v8::HandleScope scope(env->GetIsolate()); | 7494 v8::HandleScope scope(env->GetIsolate()); |
7495 CHECK_EQ(1, CountNativeContexts()); | 7495 CHECK_EQ(1, CountNativeContexts()); |
7496 | 7496 |
7497 v8::Debug::SetDebugEventListener2(NULL); | 7497 v8::Debug::SetDebugEventListener(NULL); |
7498 CompileRun("debugger;"); | 7498 CompileRun("debugger;"); |
7499 CHECK_EQ(1, CountNativeContexts()); | 7499 CHECK_EQ(1, CountNativeContexts()); |
7500 | 7500 |
7501 v8::Debug::SetDebugEventListener2(NopListener); | 7501 v8::Debug::SetDebugEventListener(NopListener); |
7502 CompileRun("debugger;"); | 7502 CompileRun("debugger;"); |
7503 CHECK_EQ(2, CountNativeContexts()); | 7503 CHECK_EQ(2, CountNativeContexts()); |
7504 | 7504 |
7505 v8::Debug::SetDebugEventListener2(NULL); | 7505 v8::Debug::SetDebugEventListener(NULL); |
7506 } | 7506 } |
7507 | 7507 |
7508 | 7508 |
7509 TEST(LiveEditEnabled) { | 7509 TEST(LiveEditEnabled) { |
7510 v8::internal::FLAG_allow_natives_syntax = true; | 7510 v8::internal::FLAG_allow_natives_syntax = true; |
7511 LocalContext env; | 7511 LocalContext env; |
7512 v8::HandleScope scope(env->GetIsolate()); | 7512 v8::HandleScope scope(env->GetIsolate()); |
7513 v8::Debug::SetLiveEditEnabled(true, env->GetIsolate()); | 7513 v8::Debug::SetLiveEditEnabled(true, env->GetIsolate()); |
7514 CompileRun("%LiveEditCompareStrings('', '')"); | 7514 CompileRun("%LiveEditCompareStrings('', '')"); |
7515 } | 7515 } |
7516 | 7516 |
7517 | 7517 |
7518 TEST(LiveEditDisabled) { | 7518 TEST(LiveEditDisabled) { |
7519 v8::internal::FLAG_allow_natives_syntax = true; | 7519 v8::internal::FLAG_allow_natives_syntax = true; |
7520 LocalContext env; | 7520 LocalContext env; |
7521 v8::HandleScope scope(env->GetIsolate()); | 7521 v8::HandleScope scope(env->GetIsolate()); |
7522 v8::Debug::SetLiveEditEnabled(false, env->GetIsolate()); | 7522 v8::Debug::SetLiveEditEnabled(false, env->GetIsolate()); |
7523 CompileRun("%LiveEditCompareStrings('', '')"); | 7523 CompileRun("%LiveEditCompareStrings('', '')"); |
7524 } | 7524 } |
7525 | 7525 |
7526 | 7526 |
7527 TEST(PrecompiledFunction) { | 7527 TEST(PrecompiledFunction) { |
7528 // Regression test for crbug.com/346207. If we have preparse data, parsing the | 7528 // Regression test for crbug.com/346207. If we have preparse data, parsing the |
7529 // function in the presence of the debugger (and breakpoints) should still | 7529 // function in the presence of the debugger (and breakpoints) should still |
7530 // succeed. The bug was that preparsing was done lazily and parsing was done | 7530 // succeed. The bug was that preparsing was done lazily and parsing was done |
7531 // eagerly, so, the symbol streams didn't match. | 7531 // eagerly, so, the symbol streams didn't match. |
7532 DebugLocalContext env; | 7532 DebugLocalContext env; |
7533 v8::HandleScope scope(env->GetIsolate()); | 7533 v8::HandleScope scope(env->GetIsolate()); |
7534 env.ExposeDebug(); | 7534 env.ExposeDebug(); |
7535 v8::Debug::SetDebugEventListener2(DebugBreakInlineListener); | 7535 v8::Debug::SetDebugEventListener(DebugBreakInlineListener); |
7536 | 7536 |
7537 v8::Local<v8::Function> break_here = | 7537 v8::Local<v8::Function> break_here = |
7538 CompileFunction(&env, "function break_here(){}", "break_here"); | 7538 CompileFunction(&env, "function break_here(){}", "break_here"); |
7539 SetBreakPoint(break_here, 0); | 7539 SetBreakPoint(break_here, 0); |
7540 | 7540 |
7541 const char* source = | 7541 const char* source = |
7542 "var a = b = c = 1; \n" | 7542 "var a = b = c = 1; \n" |
7543 "function this_is_lazy() { \n" | 7543 "function this_is_lazy() { \n" |
7544 // This symbol won't appear in the preparse data. | 7544 // This symbol won't appear in the preparse data. |
7545 " var a; \n" | 7545 " var a; \n" |
7546 "} \n" | 7546 "} \n" |
7547 "function bar() { \n" | 7547 "function bar() { \n" |
7548 " return \"bar\"; \n" | 7548 " return \"bar\"; \n" |
7549 "}; \n" | 7549 "}; \n" |
7550 "a = b = c = 2; \n" | 7550 "a = b = c = 2; \n" |
7551 "bar(); \n"; | 7551 "bar(); \n"; |
7552 v8::Local<v8::Value> result = PreCompileCompileRun(source); | 7552 v8::Local<v8::Value> result = PreCompileCompileRun(source); |
7553 CHECK(result->IsString()); | 7553 CHECK(result->IsString()); |
7554 v8::String::Utf8Value utf8(result); | 7554 v8::String::Utf8Value utf8(result); |
7555 CHECK_EQ("bar", *utf8); | 7555 CHECK_EQ("bar", *utf8); |
7556 | 7556 |
7557 v8::Debug::SetDebugEventListener2(NULL); | 7557 v8::Debug::SetDebugEventListener(NULL); |
7558 CheckDebuggerUnloaded(); | 7558 CheckDebuggerUnloaded(); |
7559 } | 7559 } |
7560 | 7560 |
7561 | 7561 |
7562 static void DebugBreakStackTraceListener( | 7562 static void DebugBreakStackTraceListener( |
7563 const v8::Debug::EventDetails& event_details) { | 7563 const v8::Debug::EventDetails& event_details) { |
7564 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); | 7564 v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10); |
7565 } | 7565 } |
7566 | 7566 |
7567 | 7567 |
7568 static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7568 static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7569 v8::Debug::DebugBreak(args.GetIsolate()); | 7569 v8::Debug::DebugBreak(args.GetIsolate()); |
7570 } | 7570 } |
7571 | 7571 |
7572 | 7572 |
7573 TEST(DebugBreakStackTrace) { | 7573 TEST(DebugBreakStackTrace) { |
7574 DebugLocalContext env; | 7574 DebugLocalContext env; |
7575 v8::HandleScope scope(env->GetIsolate()); | 7575 v8::HandleScope scope(env->GetIsolate()); |
7576 v8::Debug::SetDebugEventListener2(DebugBreakStackTraceListener); | 7576 v8::Debug::SetDebugEventListener(DebugBreakStackTraceListener); |
7577 v8::Handle<v8::FunctionTemplate> add_debug_break_template = | 7577 v8::Handle<v8::FunctionTemplate> add_debug_break_template = |
7578 v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak); | 7578 v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak); |
7579 v8::Handle<v8::Function> add_debug_break = | 7579 v8::Handle<v8::Function> add_debug_break = |
7580 add_debug_break_template->GetFunction(); | 7580 add_debug_break_template->GetFunction(); |
7581 env->Global()->Set(v8_str("add_debug_break"), add_debug_break); | 7581 env->Global()->Set(v8_str("add_debug_break"), add_debug_break); |
7582 | 7582 |
7583 CompileRun("(function loop() {" | 7583 CompileRun("(function loop() {" |
7584 " for (var j = 0; j < 1000; j++) {" | 7584 " for (var j = 0; j < 1000; j++) {" |
7585 " for (var i = 0; i < 1000; i++) {" | 7585 " for (var i = 0; i < 1000; i++) {" |
7586 " if (i == 999) add_debug_break();" | 7586 " if (i == 999) add_debug_break();" |
7587 " }" | 7587 " }" |
7588 " }" | 7588 " }" |
7589 "})()"); | 7589 "})()"); |
7590 } | 7590 } |
OLD | NEW |