OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 203 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
204 OS::SNPrintF(buffer, | 204 OS::SNPrintF(buffer, |
205 "debug.Debug.setBreakPoint(%s,%d,%d)", | 205 "debug.Debug.setBreakPoint(%s,%d,%d)", |
206 function_name, line, position); | 206 function_name, line, position); |
207 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 207 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
208 v8::Handle<v8::String> str = v8::String::New(buffer.start()); | 208 v8::Handle<v8::String> str = v8::String::New(buffer.start()); |
209 return v8::Script::Compile(str)->Run()->Int32Value(); | 209 return v8::Script::Compile(str)->Run()->Int32Value(); |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 // Set a break point in a script using the global Debug object. | 213 // Set a break point in a script identified by id using the global Debug object. |
214 static int SetScriptBreakPointFromJS(const char* script_data, | 214 static int SetScriptBreakPointByIdFromJS(int script_id, int line, int column) { |
215 int line, int column) { | |
216 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 215 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
217 if (column >= 0) { | 216 if (column >= 0) { |
218 // Column specified set script break point on precise location. | 217 // Column specified set script break point on precise location. |
219 OS::SNPrintF(buffer, | 218 OS::SNPrintF(buffer, |
220 "debug.Debug.setScriptBreakPoint(\"%s\",%d,%d)", | 219 "debug.Debug.setScriptBreakPointById(%d,%d,%d)", |
221 script_data, line, column); | 220 script_id, line, column); |
222 } else { | 221 } else { |
223 // Column not specified set script break point on line. | 222 // Column not specified set script break point on line. |
224 OS::SNPrintF(buffer, | 223 OS::SNPrintF(buffer, |
225 "debug.Debug.setScriptBreakPoint(\"%s\",%d)", | 224 "debug.Debug.setScriptBreakPointById(%d,%d)", |
226 script_data, line); | 225 script_id, line); |
227 } | 226 } |
228 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 227 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
229 { | 228 { |
230 v8::TryCatch try_catch; | 229 v8::TryCatch try_catch; |
231 v8::Handle<v8::String> str = v8::String::New(buffer.start()); | 230 v8::Handle<v8::String> str = v8::String::New(buffer.start()); |
232 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); | 231 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
233 ASSERT(!try_catch.HasCaught()); | 232 ASSERT(!try_catch.HasCaught()); |
234 return value->Int32Value(); | 233 return value->Int32Value(); |
235 } | 234 } |
236 } | 235 } |
237 | 236 |
238 | 237 |
| 238 // Set a break point in a script identified by name using the global Debug |
| 239 // object. |
| 240 static int SetScriptBreakPointByNameFromJS(const char* script_name, |
| 241 int line, int column) { |
| 242 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
| 243 if (column >= 0) { |
| 244 // Column specified set script break point on precise location. |
| 245 OS::SNPrintF(buffer, |
| 246 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)", |
| 247 script_name, line, column); |
| 248 } else { |
| 249 // Column not specified set script break point on line. |
| 250 OS::SNPrintF(buffer, |
| 251 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)", |
| 252 script_name, line); |
| 253 } |
| 254 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
| 255 { |
| 256 v8::TryCatch try_catch; |
| 257 v8::Handle<v8::String> str = v8::String::New(buffer.start()); |
| 258 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
| 259 ASSERT(!try_catch.HasCaught()); |
| 260 return value->Int32Value(); |
| 261 } |
| 262 } |
| 263 |
| 264 |
239 // Clear a break point. | 265 // Clear a break point. |
240 static void ClearBreakPoint(int break_point) { | 266 static void ClearBreakPoint(int break_point) { |
241 Debug::ClearBreakPoint( | 267 Debug::ClearBreakPoint( |
242 Handle<Object>(v8::internal::Smi::FromInt(break_point))); | 268 Handle<Object>(v8::internal::Smi::FromInt(break_point))); |
243 } | 269 } |
244 | 270 |
245 | 271 |
246 // Clear a break point using the global Debug object. | 272 // Clear a break point using the global Debug object. |
247 static void ClearBreakPointFromJS(int break_point_number) { | 273 static void ClearBreakPointFromJS(int break_point_number) { |
248 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 274 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 | 1185 |
1160 v8::Debug::SetDebugEventListener(NULL); | 1186 v8::Debug::SetDebugEventListener(NULL); |
1161 CheckDebuggerUnloaded(); | 1187 CheckDebuggerUnloaded(); |
1162 | 1188 |
1163 // Make sure that the break point numbers are consecutive. | 1189 // Make sure that the break point numbers are consecutive. |
1164 CHECK_EQ(1, bp1); | 1190 CHECK_EQ(1, bp1); |
1165 CHECK_EQ(2, bp2); | 1191 CHECK_EQ(2, bp2); |
1166 } | 1192 } |
1167 | 1193 |
1168 | 1194 |
1169 // Test that break points can be set using the global Debug object. | 1195 // Test that break points on scripts identified by name can be set using the |
1170 TEST(ScriptBreakPointThroughJavaScript) { | 1196 // global Debug object. |
| 1197 TEST(ScriptBreakPointByNameThroughJavaScript) { |
1171 break_point_hit_count = 0; | 1198 break_point_hit_count = 0; |
1172 v8::HandleScope scope; | 1199 v8::HandleScope scope; |
1173 DebugLocalContext env; | 1200 DebugLocalContext env; |
1174 env.ExposeDebug(); | 1201 env.ExposeDebug(); |
1175 | 1202 |
1176 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1203 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
1177 v8::Undefined()); | 1204 v8::Undefined()); |
1178 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run(); | |
1179 | 1205 |
1180 v8::Local<v8::String> script = v8::String::New( | 1206 v8::Local<v8::String> script = v8::String::New( |
1181 "function f() {\n" | 1207 "function f() {\n" |
1182 " function h() {\n" | 1208 " function h() {\n" |
1183 " a = 0; // line 2\n" | 1209 " a = 0; // line 2\n" |
1184 " }\n" | 1210 " }\n" |
1185 " b = 1; // line 4\n" | 1211 " b = 1; // line 4\n" |
1186 " return h();\n" | 1212 " return h();\n" |
1187 "}\n" | 1213 "}\n" |
1188 "\n" | 1214 "\n" |
(...skipping 17 matching lines...) Expand all Loading... |
1206 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); | 1232 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); |
1207 | 1233 |
1208 // Call f and g without break points. | 1234 // Call f and g without break points. |
1209 break_point_hit_count = 0; | 1235 break_point_hit_count = 0; |
1210 f->Call(env->Global(), 0, NULL); | 1236 f->Call(env->Global(), 0, NULL); |
1211 CHECK_EQ(0, break_point_hit_count); | 1237 CHECK_EQ(0, break_point_hit_count); |
1212 g->Call(env->Global(), 0, NULL); | 1238 g->Call(env->Global(), 0, NULL); |
1213 CHECK_EQ(0, break_point_hit_count); | 1239 CHECK_EQ(0, break_point_hit_count); |
1214 | 1240 |
1215 // Call f and g with break point on line 12. | 1241 // Call f and g with break point on line 12. |
1216 int sbp1 = SetScriptBreakPointFromJS("test", 12, 0); | 1242 int sbp1 = SetScriptBreakPointByNameFromJS("test", 12, 0); |
1217 break_point_hit_count = 0; | 1243 break_point_hit_count = 0; |
1218 f->Call(env->Global(), 0, NULL); | 1244 f->Call(env->Global(), 0, NULL); |
1219 CHECK_EQ(0, break_point_hit_count); | 1245 CHECK_EQ(0, break_point_hit_count); |
1220 g->Call(env->Global(), 0, NULL); | 1246 g->Call(env->Global(), 0, NULL); |
1221 CHECK_EQ(1, break_point_hit_count); | 1247 CHECK_EQ(1, break_point_hit_count); |
1222 | 1248 |
1223 // Remove the break point again. | 1249 // Remove the break point again. |
1224 break_point_hit_count = 0; | 1250 break_point_hit_count = 0; |
1225 ClearBreakPointFromJS(sbp1); | 1251 ClearBreakPointFromJS(sbp1); |
1226 f->Call(env->Global(), 0, NULL); | 1252 f->Call(env->Global(), 0, NULL); |
1227 CHECK_EQ(0, break_point_hit_count); | 1253 CHECK_EQ(0, break_point_hit_count); |
1228 g->Call(env->Global(), 0, NULL); | 1254 g->Call(env->Global(), 0, NULL); |
1229 CHECK_EQ(0, break_point_hit_count); | 1255 CHECK_EQ(0, break_point_hit_count); |
1230 | 1256 |
1231 // Call f and g with break point on line 2. | 1257 // Call f and g with break point on line 2. |
1232 int sbp2 = SetScriptBreakPointFromJS("test", 2, 0); | 1258 int sbp2 = SetScriptBreakPointByNameFromJS("test", 2, 0); |
1233 break_point_hit_count = 0; | 1259 break_point_hit_count = 0; |
1234 f->Call(env->Global(), 0, NULL); | 1260 f->Call(env->Global(), 0, NULL); |
1235 CHECK_EQ(1, break_point_hit_count); | 1261 CHECK_EQ(1, break_point_hit_count); |
1236 g->Call(env->Global(), 0, NULL); | 1262 g->Call(env->Global(), 0, NULL); |
1237 CHECK_EQ(2, break_point_hit_count); | 1263 CHECK_EQ(2, break_point_hit_count); |
1238 | 1264 |
1239 // Call f and g with break point on line 2, 4, 12, 14 and 15. | 1265 // Call f and g with break point on line 2, 4, 12, 14 and 15. |
1240 int sbp3 = SetScriptBreakPointFromJS("test", 4, 0); | 1266 int sbp3 = SetScriptBreakPointByNameFromJS("test", 4, 0); |
1241 int sbp4 = SetScriptBreakPointFromJS("test", 12, 0); | 1267 int sbp4 = SetScriptBreakPointByNameFromJS("test", 12, 0); |
1242 int sbp5 = SetScriptBreakPointFromJS("test", 14, 0); | 1268 int sbp5 = SetScriptBreakPointByNameFromJS("test", 14, 0); |
1243 int sbp6 = SetScriptBreakPointFromJS("test", 15, 0); | 1269 int sbp6 = SetScriptBreakPointByNameFromJS("test", 15, 0); |
1244 break_point_hit_count = 0; | 1270 break_point_hit_count = 0; |
1245 f->Call(env->Global(), 0, NULL); | 1271 f->Call(env->Global(), 0, NULL); |
1246 CHECK_EQ(2, break_point_hit_count); | 1272 CHECK_EQ(2, break_point_hit_count); |
1247 g->Call(env->Global(), 0, NULL); | 1273 g->Call(env->Global(), 0, NULL); |
1248 CHECK_EQ(7, break_point_hit_count); | 1274 CHECK_EQ(7, break_point_hit_count); |
1249 | 1275 |
1250 // Remove the all the break points again. | 1276 // Remove all the break points again. |
1251 break_point_hit_count = 0; | 1277 break_point_hit_count = 0; |
1252 ClearBreakPointFromJS(sbp2); | 1278 ClearBreakPointFromJS(sbp2); |
1253 ClearBreakPointFromJS(sbp3); | 1279 ClearBreakPointFromJS(sbp3); |
1254 ClearBreakPointFromJS(sbp4); | 1280 ClearBreakPointFromJS(sbp4); |
1255 ClearBreakPointFromJS(sbp5); | 1281 ClearBreakPointFromJS(sbp5); |
1256 ClearBreakPointFromJS(sbp6); | 1282 ClearBreakPointFromJS(sbp6); |
1257 f->Call(env->Global(), 0, NULL); | 1283 f->Call(env->Global(), 0, NULL); |
1258 CHECK_EQ(0, break_point_hit_count); | 1284 CHECK_EQ(0, break_point_hit_count); |
1259 g->Call(env->Global(), 0, NULL); | 1285 g->Call(env->Global(), 0, NULL); |
1260 CHECK_EQ(0, break_point_hit_count); | 1286 CHECK_EQ(0, break_point_hit_count); |
1261 | 1287 |
1262 // Now set a function break point | |
1263 int bp7 = SetBreakPointFromJS("g", 0, 0); | |
1264 g->Call(env->Global(), 0, NULL); | |
1265 CHECK_EQ(1, break_point_hit_count); | |
1266 | |
1267 // Reload the script and get g again checking that the break point survives. | |
1268 // This tests that the function break point was converted to a script break | |
1269 // point. | |
1270 v8::Script::Compile(script, &origin)->Run(); | |
1271 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); | |
1272 g->Call(env->Global(), 0, NULL); | |
1273 CHECK_EQ(2, break_point_hit_count); | |
1274 | |
1275 v8::Debug::SetDebugEventListener(NULL); | 1288 v8::Debug::SetDebugEventListener(NULL); |
1276 CheckDebuggerUnloaded(); | 1289 CheckDebuggerUnloaded(); |
1277 | 1290 |
| 1291 // Make sure that the break point numbers are consecutive. |
| 1292 CHECK_EQ(1, sbp1); |
| 1293 CHECK_EQ(2, sbp2); |
| 1294 CHECK_EQ(3, sbp3); |
| 1295 CHECK_EQ(4, sbp4); |
| 1296 CHECK_EQ(5, sbp5); |
| 1297 CHECK_EQ(6, sbp6); |
| 1298 } |
| 1299 |
| 1300 |
| 1301 TEST(ScriptBreakPointByIdThroughJavaScript) { |
| 1302 break_point_hit_count = 0; |
| 1303 v8::HandleScope scope; |
| 1304 DebugLocalContext env; |
| 1305 env.ExposeDebug(); |
| 1306 |
| 1307 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 1308 v8::Undefined()); |
| 1309 |
| 1310 v8::Local<v8::String> source = v8::String::New( |
| 1311 "function f() {\n" |
| 1312 " function h() {\n" |
| 1313 " a = 0; // line 2\n" |
| 1314 " }\n" |
| 1315 " b = 1; // line 4\n" |
| 1316 " return h();\n" |
| 1317 "}\n" |
| 1318 "\n" |
| 1319 "function g() {\n" |
| 1320 " function h() {\n" |
| 1321 " a = 0;\n" |
| 1322 " }\n" |
| 1323 " b = 2; // line 12\n" |
| 1324 " h();\n" |
| 1325 " b = 3; // line 14\n" |
| 1326 " f(); // line 15\n" |
| 1327 "}"); |
| 1328 |
| 1329 // Compile the script and get the two functions. |
| 1330 v8::ScriptOrigin origin = |
| 1331 v8::ScriptOrigin(v8::String::New("test")); |
| 1332 v8::Local<v8::Script> script = v8::Script::Compile(source, &origin); |
| 1333 script->Run(); |
| 1334 v8::Local<v8::Function> f = |
| 1335 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 1336 v8::Local<v8::Function> g = |
| 1337 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); |
| 1338 |
| 1339 // Get the script id knowing that internally it is a 32 integer. |
| 1340 uint32_t script_id = script->Id()->Uint32Value(); |
| 1341 |
| 1342 // Call f and g without break points. |
| 1343 break_point_hit_count = 0; |
| 1344 f->Call(env->Global(), 0, NULL); |
| 1345 CHECK_EQ(0, break_point_hit_count); |
| 1346 g->Call(env->Global(), 0, NULL); |
| 1347 CHECK_EQ(0, break_point_hit_count); |
| 1348 |
| 1349 // Call f and g with break point on line 12. |
| 1350 int sbp1 = SetScriptBreakPointByIdFromJS(script_id, 12, 0); |
| 1351 break_point_hit_count = 0; |
| 1352 f->Call(env->Global(), 0, NULL); |
| 1353 CHECK_EQ(0, break_point_hit_count); |
| 1354 g->Call(env->Global(), 0, NULL); |
| 1355 CHECK_EQ(1, break_point_hit_count); |
| 1356 |
| 1357 // Remove the break point again. |
| 1358 break_point_hit_count = 0; |
| 1359 ClearBreakPointFromJS(sbp1); |
| 1360 f->Call(env->Global(), 0, NULL); |
| 1361 CHECK_EQ(0, break_point_hit_count); |
| 1362 g->Call(env->Global(), 0, NULL); |
| 1363 CHECK_EQ(0, break_point_hit_count); |
| 1364 |
| 1365 // Call f and g with break point on line 2. |
| 1366 int sbp2 = SetScriptBreakPointByIdFromJS(script_id, 2, 0); |
| 1367 break_point_hit_count = 0; |
| 1368 f->Call(env->Global(), 0, NULL); |
| 1369 CHECK_EQ(1, break_point_hit_count); |
| 1370 g->Call(env->Global(), 0, NULL); |
| 1371 CHECK_EQ(2, break_point_hit_count); |
| 1372 |
| 1373 // Call f and g with break point on line 2, 4, 12, 14 and 15. |
| 1374 int sbp3 = SetScriptBreakPointByIdFromJS(script_id, 4, 0); |
| 1375 int sbp4 = SetScriptBreakPointByIdFromJS(script_id, 12, 0); |
| 1376 int sbp5 = SetScriptBreakPointByIdFromJS(script_id, 14, 0); |
| 1377 int sbp6 = SetScriptBreakPointByIdFromJS(script_id, 15, 0); |
| 1378 break_point_hit_count = 0; |
| 1379 f->Call(env->Global(), 0, NULL); |
| 1380 CHECK_EQ(2, break_point_hit_count); |
| 1381 g->Call(env->Global(), 0, NULL); |
| 1382 CHECK_EQ(7, break_point_hit_count); |
| 1383 |
| 1384 // Remove all the break points again. |
| 1385 break_point_hit_count = 0; |
| 1386 ClearBreakPointFromJS(sbp2); |
| 1387 ClearBreakPointFromJS(sbp3); |
| 1388 ClearBreakPointFromJS(sbp4); |
| 1389 ClearBreakPointFromJS(sbp5); |
| 1390 ClearBreakPointFromJS(sbp6); |
| 1391 f->Call(env->Global(), 0, NULL); |
| 1392 CHECK_EQ(0, break_point_hit_count); |
| 1393 g->Call(env->Global(), 0, NULL); |
| 1394 CHECK_EQ(0, break_point_hit_count); |
| 1395 |
| 1396 v8::Debug::SetDebugEventListener(NULL); |
| 1397 CheckDebuggerUnloaded(); |
| 1398 |
1278 // Make sure that the break point numbers are consecutive. | 1399 // Make sure that the break point numbers are consecutive. |
1279 CHECK_EQ(1, sbp1); | 1400 CHECK_EQ(1, sbp1); |
1280 CHECK_EQ(2, sbp2); | 1401 CHECK_EQ(2, sbp2); |
1281 CHECK_EQ(3, sbp3); | 1402 CHECK_EQ(3, sbp3); |
1282 CHECK_EQ(4, sbp4); | 1403 CHECK_EQ(4, sbp4); |
1283 CHECK_EQ(5, sbp5); | 1404 CHECK_EQ(5, sbp5); |
1284 CHECK_EQ(6, sbp6); | 1405 CHECK_EQ(6, sbp6); |
1285 CHECK_EQ(7, bp7); | |
1286 } | 1406 } |
1287 | 1407 |
1288 | 1408 |
1289 // Test conditional script break points. | 1409 // Test conditional script break points. |
1290 TEST(EnableDisableScriptBreakPoint) { | 1410 TEST(EnableDisableScriptBreakPoint) { |
1291 break_point_hit_count = 0; | 1411 break_point_hit_count = 0; |
1292 v8::HandleScope scope; | 1412 v8::HandleScope scope; |
1293 DebugLocalContext env; | 1413 DebugLocalContext env; |
1294 env.ExposeDebug(); | 1414 env.ExposeDebug(); |
1295 | 1415 |
1296 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1416 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
1297 v8::Undefined()); | 1417 v8::Undefined()); |
1298 | 1418 |
1299 v8::Local<v8::String> script = v8::String::New( | 1419 v8::Local<v8::String> script = v8::String::New( |
1300 "function f() {\n" | 1420 "function f() {\n" |
1301 " a = 0; // line 1\n" | 1421 " a = 0; // line 1\n" |
1302 "};"); | 1422 "};"); |
1303 | 1423 |
1304 // Compile the script and get function f. | 1424 // Compile the script and get function f. |
1305 v8::ScriptOrigin origin = | 1425 v8::ScriptOrigin origin = |
1306 v8::ScriptOrigin(v8::String::New("test")); | 1426 v8::ScriptOrigin(v8::String::New("test")); |
1307 v8::Script::Compile(script, &origin)->Run(); | 1427 v8::Script::Compile(script, &origin)->Run(); |
1308 v8::Local<v8::Function> f = | 1428 v8::Local<v8::Function> f = |
1309 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1429 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1310 | 1430 |
1311 // Set script break point on line 1 (in function f). | 1431 // Set script break point on line 1 (in function f). |
1312 int sbp = SetScriptBreakPointFromJS("test", 1, 0); | 1432 int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); |
1313 | 1433 |
1314 // Call f while enabeling and disabling the script break point. | 1434 // Call f while enabeling and disabling the script break point. |
1315 break_point_hit_count = 0; | 1435 break_point_hit_count = 0; |
1316 f->Call(env->Global(), 0, NULL); | 1436 f->Call(env->Global(), 0, NULL); |
1317 CHECK_EQ(1, break_point_hit_count); | 1437 CHECK_EQ(1, break_point_hit_count); |
1318 | 1438 |
1319 DisableScriptBreakPointFromJS(sbp); | 1439 DisableScriptBreakPointFromJS(sbp); |
1320 f->Call(env->Global(), 0, NULL); | 1440 f->Call(env->Global(), 0, NULL); |
1321 CHECK_EQ(1, break_point_hit_count); | 1441 CHECK_EQ(1, break_point_hit_count); |
1322 | 1442 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 "};"); | 1483 "};"); |
1364 | 1484 |
1365 // Compile the script and get function f. | 1485 // Compile the script and get function f. |
1366 v8::ScriptOrigin origin = | 1486 v8::ScriptOrigin origin = |
1367 v8::ScriptOrigin(v8::String::New("test")); | 1487 v8::ScriptOrigin(v8::String::New("test")); |
1368 v8::Script::Compile(script, &origin)->Run(); | 1488 v8::Script::Compile(script, &origin)->Run(); |
1369 v8::Local<v8::Function> f = | 1489 v8::Local<v8::Function> f = |
1370 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1490 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1371 | 1491 |
1372 // Set script break point on line 5 (in function g). | 1492 // Set script break point on line 5 (in function g). |
1373 int sbp1 = SetScriptBreakPointFromJS("test", 5, 0); | 1493 int sbp1 = SetScriptBreakPointByNameFromJS("test", 5, 0); |
1374 | 1494 |
1375 // Call f with different conditions on the script break point. | 1495 // Call f with different conditions on the script break point. |
1376 break_point_hit_count = 0; | 1496 break_point_hit_count = 0; |
1377 ChangeScriptBreakPointConditionFromJS(sbp1, "false"); | 1497 ChangeScriptBreakPointConditionFromJS(sbp1, "false"); |
1378 f->Call(env->Global(), 0, NULL); | 1498 f->Call(env->Global(), 0, NULL); |
1379 CHECK_EQ(0, break_point_hit_count); | 1499 CHECK_EQ(0, break_point_hit_count); |
1380 | 1500 |
1381 ChangeScriptBreakPointConditionFromJS(sbp1, "true"); | 1501 ChangeScriptBreakPointConditionFromJS(sbp1, "true"); |
1382 break_point_hit_count = 0; | 1502 break_point_hit_count = 0; |
1383 f->Call(env->Global(), 0, NULL); | 1503 f->Call(env->Global(), 0, NULL); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 "};"); | 1541 "};"); |
1422 | 1542 |
1423 // Compile the script and get function f. | 1543 // Compile the script and get function f. |
1424 v8::ScriptOrigin origin = | 1544 v8::ScriptOrigin origin = |
1425 v8::ScriptOrigin(v8::String::New("test")); | 1545 v8::ScriptOrigin(v8::String::New("test")); |
1426 v8::Script::Compile(script, &origin)->Run(); | 1546 v8::Script::Compile(script, &origin)->Run(); |
1427 v8::Local<v8::Function> f = | 1547 v8::Local<v8::Function> f = |
1428 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1548 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1429 | 1549 |
1430 // Set script break point on line 1 (in function f). | 1550 // Set script break point on line 1 (in function f). |
1431 int sbp = SetScriptBreakPointFromJS("test", 1, 0); | 1551 int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); |
1432 | 1552 |
1433 // Call f with different ignores on the script break point. | 1553 // Call f with different ignores on the script break point. |
1434 break_point_hit_count = 0; | 1554 break_point_hit_count = 0; |
1435 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 1); | 1555 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 1); |
1436 f->Call(env->Global(), 0, NULL); | 1556 f->Call(env->Global(), 0, NULL); |
1437 CHECK_EQ(0, break_point_hit_count); | 1557 CHECK_EQ(0, break_point_hit_count); |
1438 f->Call(env->Global(), 0, NULL); | 1558 f->Call(env->Global(), 0, NULL); |
1439 CHECK_EQ(1, break_point_hit_count); | 1559 CHECK_EQ(1, break_point_hit_count); |
1440 | 1560 |
1441 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 5); | 1561 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 5); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 " a = 0; // line 2\n" | 1597 " a = 0; // line 2\n" |
1478 " }\n" | 1598 " }\n" |
1479 " b = 1; // line 4\n" | 1599 " b = 1; // line 4\n" |
1480 " return h();\n" | 1600 " return h();\n" |
1481 "}"); | 1601 "}"); |
1482 | 1602 |
1483 v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8::String::New("1")); | 1603 v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8::String::New("1")); |
1484 v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8::String::New("2")); | 1604 v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8::String::New("2")); |
1485 | 1605 |
1486 // Set a script break point before the script is loaded. | 1606 // Set a script break point before the script is loaded. |
1487 SetScriptBreakPointFromJS("1", 2, 0); | 1607 SetScriptBreakPointByNameFromJS("1", 2, 0); |
1488 | 1608 |
1489 // Compile the script and get the function. | 1609 // Compile the script and get the function. |
1490 v8::Script::Compile(script, &origin_1)->Run(); | 1610 v8::Script::Compile(script, &origin_1)->Run(); |
1491 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1611 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1492 | 1612 |
1493 // Call f and check that the script break point is active. | 1613 // Call f and check that the script break point is active. |
1494 break_point_hit_count = 0; | 1614 break_point_hit_count = 0; |
1495 f->Call(env->Global(), 0, NULL); | 1615 f->Call(env->Global(), 0, NULL); |
1496 CHECK_EQ(1, break_point_hit_count); | 1616 CHECK_EQ(1, break_point_hit_count); |
1497 | 1617 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 v8::Local<v8::Function> g; | 1658 v8::Local<v8::Function> g; |
1539 v8::Local<v8::String> script_g = v8::String::New( | 1659 v8::Local<v8::String> script_g = v8::String::New( |
1540 "function g() {\n" | 1660 "function g() {\n" |
1541 " b = 0; // line 1\n" | 1661 " b = 0; // line 1\n" |
1542 "}"); | 1662 "}"); |
1543 | 1663 |
1544 v8::ScriptOrigin origin = | 1664 v8::ScriptOrigin origin = |
1545 v8::ScriptOrigin(v8::String::New("test")); | 1665 v8::ScriptOrigin(v8::String::New("test")); |
1546 | 1666 |
1547 // Set a script break point before the scripts are loaded. | 1667 // Set a script break point before the scripts are loaded. |
1548 int sbp = SetScriptBreakPointFromJS("test", 1, 0); | 1668 int sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); |
1549 | 1669 |
1550 // Compile the scripts with same script data and get the functions. | 1670 // Compile the scripts with same script data and get the functions. |
1551 v8::Script::Compile(script_f, &origin)->Run(); | 1671 v8::Script::Compile(script_f, &origin)->Run(); |
1552 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1672 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1553 v8::Script::Compile(script_g, &origin)->Run(); | 1673 v8::Script::Compile(script_g, &origin)->Run(); |
1554 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); | 1674 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); |
1555 | 1675 |
1556 // Call f and g and check that the script break point is active. | 1676 // Call f and g and check that the script break point is active. |
1557 break_point_hit_count = 0; | 1677 break_point_hit_count = 0; |
1558 f->Call(env->Global(), 0, NULL); | 1678 f->Call(env->Global(), 0, NULL); |
1559 CHECK_EQ(1, break_point_hit_count); | 1679 CHECK_EQ(1, break_point_hit_count); |
1560 g->Call(env->Global(), 0, NULL); | 1680 g->Call(env->Global(), 0, NULL); |
1561 CHECK_EQ(2, break_point_hit_count); | 1681 CHECK_EQ(2, break_point_hit_count); |
1562 | 1682 |
1563 // Clear the script break point. | 1683 // Clear the script break point. |
1564 ClearBreakPointFromJS(sbp); | 1684 ClearBreakPointFromJS(sbp); |
1565 | 1685 |
1566 // Call f and g and check that the script break point is no longer active. | 1686 // Call f and g and check that the script break point is no longer active. |
1567 break_point_hit_count = 0; | 1687 break_point_hit_count = 0; |
1568 f->Call(env->Global(), 0, NULL); | 1688 f->Call(env->Global(), 0, NULL); |
1569 CHECK_EQ(0, break_point_hit_count); | 1689 CHECK_EQ(0, break_point_hit_count); |
1570 g->Call(env->Global(), 0, NULL); | 1690 g->Call(env->Global(), 0, NULL); |
1571 CHECK_EQ(0, break_point_hit_count); | 1691 CHECK_EQ(0, break_point_hit_count); |
1572 | 1692 |
1573 // Set script break point with the scripts loaded. | 1693 // Set script break point with the scripts loaded. |
1574 sbp = SetScriptBreakPointFromJS("test", 1, 0); | 1694 sbp = SetScriptBreakPointByNameFromJS("test", 1, 0); |
1575 | 1695 |
1576 // Call f and g and check that the script break point is active. | 1696 // Call f and g and check that the script break point is active. |
1577 break_point_hit_count = 0; | 1697 break_point_hit_count = 0; |
1578 f->Call(env->Global(), 0, NULL); | 1698 f->Call(env->Global(), 0, NULL); |
1579 CHECK_EQ(1, break_point_hit_count); | 1699 CHECK_EQ(1, break_point_hit_count); |
1580 g->Call(env->Global(), 0, NULL); | 1700 g->Call(env->Global(), 0, NULL); |
1581 CHECK_EQ(2, break_point_hit_count); | 1701 CHECK_EQ(2, break_point_hit_count); |
1582 | 1702 |
1583 v8::Debug::SetDebugEventListener(NULL); | 1703 v8::Debug::SetDebugEventListener(NULL); |
1584 CheckDebuggerUnloaded(); | 1704 CheckDebuggerUnloaded(); |
(...skipping 15 matching lines...) Expand all Loading... |
1600 "function f() {\n" | 1720 "function f() {\n" |
1601 " a = 0; // line 8 as this script has line offset 7\n" | 1721 " a = 0; // line 8 as this script has line offset 7\n" |
1602 " b = 0; // line 9 as this script has line offset 7\n" | 1722 " b = 0; // line 9 as this script has line offset 7\n" |
1603 "}"); | 1723 "}"); |
1604 | 1724 |
1605 // Create script origin both name and line offset. | 1725 // Create script origin both name and line offset. |
1606 v8::ScriptOrigin origin(v8::String::New("test.html"), | 1726 v8::ScriptOrigin origin(v8::String::New("test.html"), |
1607 v8::Integer::New(7)); | 1727 v8::Integer::New(7)); |
1608 | 1728 |
1609 // Set two script break points before the script is loaded. | 1729 // Set two script break points before the script is loaded. |
1610 int sbp1 = SetScriptBreakPointFromJS("test.html", 8, 0); | 1730 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 8, 0); |
1611 int sbp2 = SetScriptBreakPointFromJS("test.html", 9, 0); | 1731 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 9, 0); |
1612 | 1732 |
1613 // Compile the script and get the function. | 1733 // Compile the script and get the function. |
1614 v8::Script::Compile(script, &origin)->Run(); | 1734 v8::Script::Compile(script, &origin)->Run(); |
1615 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1735 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1616 | 1736 |
1617 // Call f and check that the script break point is active. | 1737 // Call f and check that the script break point is active. |
1618 break_point_hit_count = 0; | 1738 break_point_hit_count = 0; |
1619 f->Call(env->Global(), 0, NULL); | 1739 f->Call(env->Global(), 0, NULL); |
1620 CHECK_EQ(2, break_point_hit_count); | 1740 CHECK_EQ(2, break_point_hit_count); |
1621 | 1741 |
1622 // Clear the script break points. | 1742 // Clear the script break points. |
1623 ClearBreakPointFromJS(sbp1); | 1743 ClearBreakPointFromJS(sbp1); |
1624 ClearBreakPointFromJS(sbp2); | 1744 ClearBreakPointFromJS(sbp2); |
1625 | 1745 |
1626 // Call f and check that no script break points are active. | 1746 // Call f and check that no script break points are active. |
1627 break_point_hit_count = 0; | 1747 break_point_hit_count = 0; |
1628 f->Call(env->Global(), 0, NULL); | 1748 f->Call(env->Global(), 0, NULL); |
1629 CHECK_EQ(0, break_point_hit_count); | 1749 CHECK_EQ(0, break_point_hit_count); |
1630 | 1750 |
1631 // Set a script break point with the script loaded. | 1751 // Set a script break point with the script loaded. |
1632 sbp1 = SetScriptBreakPointFromJS("test.html", 9, 0); | 1752 sbp1 = SetScriptBreakPointByNameFromJS("test.html", 9, 0); |
1633 | 1753 |
1634 // Call f and check that the script break point is active. | 1754 // Call f and check that the script break point is active. |
1635 break_point_hit_count = 0; | 1755 break_point_hit_count = 0; |
1636 f->Call(env->Global(), 0, NULL); | 1756 f->Call(env->Global(), 0, NULL); |
1637 CHECK_EQ(1, break_point_hit_count); | 1757 CHECK_EQ(1, break_point_hit_count); |
1638 | 1758 |
1639 v8::Debug::SetDebugEventListener(NULL); | 1759 v8::Debug::SetDebugEventListener(NULL); |
1640 CheckDebuggerUnloaded(); | 1760 CheckDebuggerUnloaded(); |
1641 } | 1761 } |
1642 | 1762 |
(...skipping 23 matching lines...) Expand all Loading... |
1666 " /* xx */ function g() { // line 5\n" | 1786 " /* xx */ function g() { // line 5\n" |
1667 " function h() { // line 6\n" | 1787 " function h() { // line 6\n" |
1668 " a = 3; // line 7\n" | 1788 " a = 3; // line 7\n" |
1669 " }\n" | 1789 " }\n" |
1670 " h(); // line 9\n" | 1790 " h(); // line 9\n" |
1671 " a = 4; // line 10\n" | 1791 " a = 4; // line 10\n" |
1672 " }\n" | 1792 " }\n" |
1673 " a=5; // line 12"); | 1793 " a=5; // line 12"); |
1674 | 1794 |
1675 // Set a couple script break point before the script is loaded. | 1795 // Set a couple script break point before the script is loaded. |
1676 int sbp1 = SetScriptBreakPointFromJS("test.html", 0, -1); | 1796 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 0, -1); |
1677 int sbp2 = SetScriptBreakPointFromJS("test.html", 1, -1); | 1797 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 1, -1); |
1678 int sbp3 = SetScriptBreakPointFromJS("test.html", 5, -1); | 1798 int sbp3 = SetScriptBreakPointByNameFromJS("test.html", 5, -1); |
1679 | 1799 |
1680 // Compile the script and get the function. | 1800 // Compile the script and get the function. |
1681 break_point_hit_count = 0; | 1801 break_point_hit_count = 0; |
1682 v8::ScriptOrigin origin(v8::String::New("test.html"), v8::Integer::New(0)); | 1802 v8::ScriptOrigin origin(v8::String::New("test.html"), v8::Integer::New(0)); |
1683 v8::Script::Compile(script, &origin)->Run(); | 1803 v8::Script::Compile(script, &origin)->Run(); |
1684 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1804 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
1685 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); | 1805 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); |
1686 | 1806 |
1687 // Chesk that a break point was hit when the script was run. | 1807 // Chesk that a break point was hit when the script was run. |
1688 CHECK_EQ(1, break_point_hit_count); | 1808 CHECK_EQ(1, break_point_hit_count); |
1689 CHECK_EQ(0, strlen(last_function_hit)); | 1809 CHECK_EQ(0, strlen(last_function_hit)); |
1690 | 1810 |
1691 // Call f and check that the script break point. | 1811 // Call f and check that the script break point. |
1692 f->Call(env->Global(), 0, NULL); | 1812 f->Call(env->Global(), 0, NULL); |
1693 CHECK_EQ(2, break_point_hit_count); | 1813 CHECK_EQ(2, break_point_hit_count); |
1694 CHECK_EQ("f", last_function_hit); | 1814 CHECK_EQ("f", last_function_hit); |
1695 | 1815 |
1696 // Call g and check that the script break point. | 1816 // Call g and check that the script break point. |
1697 g->Call(env->Global(), 0, NULL); | 1817 g->Call(env->Global(), 0, NULL); |
1698 CHECK_EQ(3, break_point_hit_count); | 1818 CHECK_EQ(3, break_point_hit_count); |
1699 CHECK_EQ("g", last_function_hit); | 1819 CHECK_EQ("g", last_function_hit); |
1700 | 1820 |
1701 // Clear the script break point on g and set one on h. | 1821 // Clear the script break point on g and set one on h. |
1702 ClearBreakPointFromJS(sbp3); | 1822 ClearBreakPointFromJS(sbp3); |
1703 int sbp4 = SetScriptBreakPointFromJS("test.html", 6, -1); | 1823 int sbp4 = SetScriptBreakPointByNameFromJS("test.html", 6, -1); |
1704 | 1824 |
1705 // Call g and check that the script break point in h is hit. | 1825 // Call g and check that the script break point in h is hit. |
1706 g->Call(env->Global(), 0, NULL); | 1826 g->Call(env->Global(), 0, NULL); |
1707 CHECK_EQ(4, break_point_hit_count); | 1827 CHECK_EQ(4, break_point_hit_count); |
1708 CHECK_EQ("h", last_function_hit); | 1828 CHECK_EQ("h", last_function_hit); |
1709 | 1829 |
1710 // Clear break points in f and h. Set a new one in the script between | 1830 // Clear break points in f and h. Set a new one in the script between |
1711 // functions f and g and test that there is no break points in f and g any | 1831 // functions f and g and test that there is no break points in f and g any |
1712 // more. | 1832 // more. |
1713 ClearBreakPointFromJS(sbp2); | 1833 ClearBreakPointFromJS(sbp2); |
1714 ClearBreakPointFromJS(sbp4); | 1834 ClearBreakPointFromJS(sbp4); |
1715 int sbp5 = SetScriptBreakPointFromJS("test.html", 4, -1); | 1835 int sbp5 = SetScriptBreakPointByNameFromJS("test.html", 4, -1); |
1716 break_point_hit_count = 0; | 1836 break_point_hit_count = 0; |
1717 f->Call(env->Global(), 0, NULL); | 1837 f->Call(env->Global(), 0, NULL); |
1718 g->Call(env->Global(), 0, NULL); | 1838 g->Call(env->Global(), 0, NULL); |
1719 CHECK_EQ(0, break_point_hit_count); | 1839 CHECK_EQ(0, break_point_hit_count); |
1720 | 1840 |
1721 // Reload the script which should hit two break points. | 1841 // Reload the script which should hit two break points. |
1722 break_point_hit_count = 0; | 1842 break_point_hit_count = 0; |
1723 v8::Script::Compile(script, &origin)->Run(); | 1843 v8::Script::Compile(script, &origin)->Run(); |
1724 CHECK_EQ(2, break_point_hit_count); | 1844 CHECK_EQ(2, break_point_hit_count); |
1725 CHECK_EQ(0, strlen(last_function_hit)); | 1845 CHECK_EQ(0, strlen(last_function_hit)); |
1726 | 1846 |
1727 // Set a break point in the code after the last function decleration. | 1847 // Set a break point in the code after the last function decleration. |
1728 int sbp6 = SetScriptBreakPointFromJS("test.html", 12, -1); | 1848 int sbp6 = SetScriptBreakPointByNameFromJS("test.html", 12, -1); |
1729 | 1849 |
1730 // Reload the script which should hit three break points. | 1850 // Reload the script which should hit three break points. |
1731 break_point_hit_count = 0; | 1851 break_point_hit_count = 0; |
1732 v8::Script::Compile(script, &origin)->Run(); | 1852 v8::Script::Compile(script, &origin)->Run(); |
1733 CHECK_EQ(3, break_point_hit_count); | 1853 CHECK_EQ(3, break_point_hit_count); |
1734 CHECK_EQ(0, strlen(last_function_hit)); | 1854 CHECK_EQ(0, strlen(last_function_hit)); |
1735 | 1855 |
1736 // Clear the last break points, and reload the script which should not hit any | 1856 // Clear the last break points, and reload the script which should not hit any |
1737 // break points. | 1857 // break points. |
1738 ClearBreakPointFromJS(sbp1); | 1858 ClearBreakPointFromJS(sbp1); |
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3688 | 3808 |
3689 // Fill a host dispatch and a continue command on the command queue before | 3809 // Fill a host dispatch and a continue command on the command queue before |
3690 // generating a debug break. | 3810 // generating a debug break. |
3691 v8::Debug::SendHostDispatch(NULL); | 3811 v8::Debug::SendHostDispatch(NULL); |
3692 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 3812 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
3693 CompileRun("debugger"); | 3813 CompileRun("debugger"); |
3694 | 3814 |
3695 // The host dispatch callback should be called. | 3815 // The host dispatch callback should be called. |
3696 CHECK_EQ(1, host_dispatch_hit_count); | 3816 CHECK_EQ(1, host_dispatch_hit_count); |
3697 } | 3817 } |
OLD | NEW |