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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 1037
1038 1038
1039 // --- T h e A c t u a l T e s t s 1039 // --- T h e A c t u a l T e s t s
1040 1040
1041 1041
1042 // Test that the debug break function is the expected one for different kinds 1042 // Test that the debug break function is the expected one for different kinds
1043 // of break locations. 1043 // of break locations.
1044 TEST(DebugStub) { 1044 TEST(DebugStub) {
1045 using ::v8::internal::Builtins; 1045 using ::v8::internal::Builtins;
1046 using ::v8::internal::Isolate; 1046 using ::v8::internal::Isolate;
1047 v8::HandleScope scope;
1048 DebugLocalContext env; 1047 DebugLocalContext env;
1048 v8::HandleScope scope(env->GetIsolate());
1049 1049
1050 CheckDebugBreakFunction(&env, 1050 CheckDebugBreakFunction(&env,
1051 "function f1(){}", "f1", 1051 "function f1(){}", "f1",
1052 0, 1052 0,
1053 v8::internal::RelocInfo::JS_RETURN, 1053 v8::internal::RelocInfo::JS_RETURN,
1054 NULL); 1054 NULL);
1055 CheckDebugBreakFunction(&env, 1055 CheckDebugBreakFunction(&env,
1056 "function f2(){x=1;}", "f2", 1056 "function f2(){x=1;}", "f2",
1057 0, 1057 0,
1058 v8::internal::RelocInfo::CODE_TARGET_CONTEXT, 1058 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 "function f4_4(){x(1,2,3,4);}", "f4_4", 1110 "function f4_4(){x(1,2,3,4);}", "f4_4",
1111 0, 1111 0,
1112 v8::internal::RelocInfo::CODE_TARGET_CONTEXT, 1112 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1113 *debug_break_4); 1113 *debug_break_4);
1114 } 1114 }
1115 1115
1116 1116
1117 // Test that the debug info in the VM is in sync with the functions being 1117 // Test that the debug info in the VM is in sync with the functions being
1118 // debugged. 1118 // debugged.
1119 TEST(DebugInfo) { 1119 TEST(DebugInfo) {
1120 v8::HandleScope scope;
1121 DebugLocalContext env; 1120 DebugLocalContext env;
1121 v8::HandleScope scope(env->GetIsolate());
1122 // Create a couple of functions for the test. 1122 // Create a couple of functions for the test.
1123 v8::Local<v8::Function> foo = 1123 v8::Local<v8::Function> foo =
1124 CompileFunction(&env, "function foo(){}", "foo"); 1124 CompileFunction(&env, "function foo(){}", "foo");
1125 v8::Local<v8::Function> bar = 1125 v8::Local<v8::Function> bar =
1126 CompileFunction(&env, "function bar(){}", "bar"); 1126 CompileFunction(&env, "function bar(){}", "bar");
1127 // Initially no functions are debugged. 1127 // Initially no functions are debugged.
1128 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); 1128 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1129 CHECK(!HasDebugInfo(foo)); 1129 CHECK(!HasDebugInfo(foo));
1130 CHECK(!HasDebugInfo(bar)); 1130 CHECK(!HasDebugInfo(bar));
1131 // One function (foo) is debugged. 1131 // One function (foo) is debugged.
(...skipping 15 matching lines...) Expand all
1147 ClearBreakPoint(bp2); 1147 ClearBreakPoint(bp2);
1148 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); 1148 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1149 CHECK(!HasDebugInfo(foo)); 1149 CHECK(!HasDebugInfo(foo));
1150 CHECK(!HasDebugInfo(bar)); 1150 CHECK(!HasDebugInfo(bar));
1151 } 1151 }
1152 1152
1153 1153
1154 // Test that a break point can be set at an IC store location. 1154 // Test that a break point can be set at an IC store location.
1155 TEST(BreakPointICStore) { 1155 TEST(BreakPointICStore) {
1156 break_point_hit_count = 0; 1156 break_point_hit_count = 0;
1157 v8::HandleScope scope;
1158 DebugLocalContext env; 1157 DebugLocalContext env;
1158 v8::HandleScope scope(env->GetIsolate());
1159 1159
1160 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1160 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1161 v8::Undefined()); 1161 v8::Undefined());
1162 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run(); 1162 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run();
1163 v8::Local<v8::Function> foo = 1163 v8::Local<v8::Function> foo =
1164 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 1164 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1165 1165
1166 // Run without breakpoints. 1166 // Run without breakpoints.
1167 foo->Call(env->Global(), 0, NULL); 1167 foo->Call(env->Global(), 0, NULL);
1168 CHECK_EQ(0, break_point_hit_count); 1168 CHECK_EQ(0, break_point_hit_count);
(...skipping 11 matching lines...) Expand all
1180 CHECK_EQ(2, break_point_hit_count); 1180 CHECK_EQ(2, break_point_hit_count);
1181 1181
1182 v8::Debug::SetDebugEventListener(NULL); 1182 v8::Debug::SetDebugEventListener(NULL);
1183 CheckDebuggerUnloaded(); 1183 CheckDebuggerUnloaded();
1184 } 1184 }
1185 1185
1186 1186
1187 // Test that a break point can be set at an IC load location. 1187 // Test that a break point can be set at an IC load location.
1188 TEST(BreakPointICLoad) { 1188 TEST(BreakPointICLoad) {
1189 break_point_hit_count = 0; 1189 break_point_hit_count = 0;
1190 v8::HandleScope scope;
1191 DebugLocalContext env; 1190 DebugLocalContext env;
1191 v8::HandleScope scope(env->GetIsolate());
1192 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1192 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1193 v8::Undefined()); 1193 v8::Undefined());
1194 v8::Script::Compile(v8::String::New("bar=1"))->Run(); 1194 v8::Script::Compile(v8::String::New("bar=1"))->Run();
1195 v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run(); 1195 v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run();
1196 v8::Local<v8::Function> foo = 1196 v8::Local<v8::Function> foo =
1197 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 1197 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1198 1198
1199 // Run without breakpoints. 1199 // Run without breakpoints.
1200 foo->Call(env->Global(), 0, NULL); 1200 foo->Call(env->Global(), 0, NULL);
1201 CHECK_EQ(0, break_point_hit_count); 1201 CHECK_EQ(0, break_point_hit_count);
(...skipping 11 matching lines...) Expand all
1213 CHECK_EQ(2, break_point_hit_count); 1213 CHECK_EQ(2, break_point_hit_count);
1214 1214
1215 v8::Debug::SetDebugEventListener(NULL); 1215 v8::Debug::SetDebugEventListener(NULL);
1216 CheckDebuggerUnloaded(); 1216 CheckDebuggerUnloaded();
1217 } 1217 }
1218 1218
1219 1219
1220 // Test that a break point can be set at an IC call location. 1220 // Test that a break point can be set at an IC call location.
1221 TEST(BreakPointICCall) { 1221 TEST(BreakPointICCall) {
1222 break_point_hit_count = 0; 1222 break_point_hit_count = 0;
1223 v8::HandleScope scope;
1224 DebugLocalContext env; 1223 DebugLocalContext env;
1224 v8::HandleScope scope(env->GetIsolate());
1225 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1225 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1226 v8::Undefined()); 1226 v8::Undefined());
1227 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); 1227 v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
1228 v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run(); 1228 v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run();
1229 v8::Local<v8::Function> foo = 1229 v8::Local<v8::Function> foo =
1230 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 1230 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1231 1231
1232 // Run without breakpoints. 1232 // Run without breakpoints.
1233 foo->Call(env->Global(), 0, NULL); 1233 foo->Call(env->Global(), 0, NULL);
1234 CHECK_EQ(0, break_point_hit_count); 1234 CHECK_EQ(0, break_point_hit_count);
(...skipping 11 matching lines...) Expand all
1246 CHECK_EQ(2, break_point_hit_count); 1246 CHECK_EQ(2, break_point_hit_count);
1247 1247
1248 v8::Debug::SetDebugEventListener(NULL); 1248 v8::Debug::SetDebugEventListener(NULL);
1249 CheckDebuggerUnloaded(); 1249 CheckDebuggerUnloaded();
1250 } 1250 }
1251 1251
1252 1252
1253 // Test that a break point can be set at an IC call location and survive a GC. 1253 // Test that a break point can be set at an IC call location and survive a GC.
1254 TEST(BreakPointICCallWithGC) { 1254 TEST(BreakPointICCallWithGC) {
1255 break_point_hit_count = 0; 1255 break_point_hit_count = 0;
1256 v8::HandleScope scope;
1257 DebugLocalContext env; 1256 DebugLocalContext env;
1257 v8::HandleScope scope(env->GetIsolate());
1258 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, 1258 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1259 v8::Undefined()); 1259 v8::Undefined());
1260 v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run(); 1260 v8::Script::Compile(v8::String::New("function bar(){return 1;}"))->Run();
1261 v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run(); 1261 v8::Script::Compile(v8::String::New("function foo(){return bar();}"))->Run();
1262 v8::Local<v8::Function> foo = 1262 v8::Local<v8::Function> foo =
1263 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 1263 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1264 1264
1265 // Run without breakpoints. 1265 // Run without breakpoints.
1266 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); 1266 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value());
1267 CHECK_EQ(0, break_point_hit_count); 1267 CHECK_EQ(0, break_point_hit_count);
(...skipping 11 matching lines...) Expand all
1279 CHECK_EQ(2, break_point_hit_count); 1279 CHECK_EQ(2, break_point_hit_count);
1280 1280
1281 v8::Debug::SetDebugEventListener(NULL); 1281 v8::Debug::SetDebugEventListener(NULL);
1282 CheckDebuggerUnloaded(); 1282 CheckDebuggerUnloaded();
1283 } 1283 }
1284 1284
1285 1285
1286 // Test that a break point can be set at an IC call location and survive a GC. 1286 // Test that a break point can be set at an IC call location and survive a GC.
1287 TEST(BreakPointConstructCallWithGC) { 1287 TEST(BreakPointConstructCallWithGC) {
1288 break_point_hit_count = 0; 1288 break_point_hit_count = 0;
1289 v8::HandleScope scope;
1290 DebugLocalContext env; 1289 DebugLocalContext env;
1290 v8::HandleScope scope(env->GetIsolate());
1291 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, 1291 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1292 v8::Undefined()); 1292 v8::Undefined());
1293 v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run(); 1293 v8::Script::Compile(v8::String::New("function bar(){ this.x = 1;}"))->Run();
1294 v8::Script::Compile(v8::String::New( 1294 v8::Script::Compile(v8::String::New(
1295 "function foo(){return new bar(1).x;}"))->Run(); 1295 "function foo(){return new bar(1).x;}"))->Run();
1296 v8::Local<v8::Function> foo = 1296 v8::Local<v8::Function> foo =
1297 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 1297 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
1298 1298
1299 // Run without breakpoints. 1299 // Run without breakpoints.
1300 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value()); 1300 CHECK_EQ(1, foo->Call(env->Global(), 0, NULL)->Int32Value());
(...skipping 12 matching lines...) Expand all
1313 CHECK_EQ(2, break_point_hit_count); 1313 CHECK_EQ(2, break_point_hit_count);
1314 1314
1315 v8::Debug::SetDebugEventListener(NULL); 1315 v8::Debug::SetDebugEventListener(NULL);
1316 CheckDebuggerUnloaded(); 1316 CheckDebuggerUnloaded();
1317 } 1317 }
1318 1318
1319 1319
1320 // Test that a break point can be set at a return store location. 1320 // Test that a break point can be set at a return store location.
1321 TEST(BreakPointReturn) { 1321 TEST(BreakPointReturn) {
1322 break_point_hit_count = 0; 1322 break_point_hit_count = 0;
1323 v8::HandleScope scope;
1324 DebugLocalContext env; 1323 DebugLocalContext env;
1324 v8::HandleScope scope(env->GetIsolate());
1325 1325
1326 // Create a functions for checking the source line and column when hitting 1326 // Create a functions for checking the source line and column when hitting
1327 // a break point. 1327 // a break point.
1328 frame_source_line = CompileFunction(&env, 1328 frame_source_line = CompileFunction(&env,
1329 frame_source_line_source, 1329 frame_source_line_source,
1330 "frame_source_line"); 1330 "frame_source_line");
1331 frame_source_column = CompileFunction(&env, 1331 frame_source_column = CompileFunction(&env,
1332 frame_source_column_source, 1332 frame_source_column_source,
1333 "frame_source_column"); 1333 "frame_source_column");
1334 1334
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 break_point_hit_count = 0; 1371 break_point_hit_count = 0;
1372 for (int i = 0; i < call_count; i++) { 1372 for (int i = 0; i < call_count; i++) {
1373 f->Call(recv, 0, NULL); 1373 f->Call(recv, 0, NULL);
1374 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count); 1374 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count);
1375 } 1375 }
1376 } 1376 }
1377 1377
1378 // Test GC during break point processing. 1378 // Test GC during break point processing.
1379 TEST(GCDuringBreakPointProcessing) { 1379 TEST(GCDuringBreakPointProcessing) {
1380 break_point_hit_count = 0; 1380 break_point_hit_count = 0;
1381 v8::HandleScope scope;
1382 DebugLocalContext env; 1381 DebugLocalContext env;
1382 v8::HandleScope scope(env->GetIsolate());
1383 1383
1384 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage, 1384 v8::Debug::SetDebugEventListener(DebugEventBreakPointCollectGarbage,
1385 v8::Undefined()); 1385 v8::Undefined());
1386 v8::Local<v8::Function> foo; 1386 v8::Local<v8::Function> foo;
1387 1387
1388 // Test IC store break point with garbage collection. 1388 // Test IC store break point with garbage collection.
1389 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); 1389 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
1390 SetBreakPoint(foo, 0); 1390 SetBreakPoint(foo, 0);
1391 CallWithBreakPoints(env->Global(), foo, 1, 10); 1391 CallWithBreakPoints(env->Global(), foo, 1, 10);
1392 1392
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 1435 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1436 f->Call(recv, 0, NULL); 1436 f->Call(recv, 0, NULL);
1437 CHECK_EQ(3 + i * 3, break_point_hit_count); 1437 CHECK_EQ(3 + i * 3, break_point_hit_count);
1438 } 1438 }
1439 } 1439 }
1440 1440
1441 1441
1442 // Test that a break point can be set at a return store location. 1442 // Test that a break point can be set at a return store location.
1443 TEST(BreakPointSurviveGC) { 1443 TEST(BreakPointSurviveGC) {
1444 break_point_hit_count = 0; 1444 break_point_hit_count = 0;
1445 v8::HandleScope scope;
1446 DebugLocalContext env; 1445 DebugLocalContext env;
1446 v8::HandleScope scope(env->GetIsolate());
1447 1447
1448 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1448 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1449 v8::Undefined()); 1449 v8::Undefined());
1450 v8::Local<v8::Function> foo; 1450 v8::Local<v8::Function> foo;
1451 1451
1452 // Test IC store break point with garbage collection. 1452 // Test IC store break point with garbage collection.
1453 { 1453 {
1454 CompileFunction(&env, "function foo(){}", "foo"); 1454 CompileFunction(&env, "function foo(){}", "foo");
1455 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); 1455 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
1456 SetBreakPoint(foo, 0); 1456 SetBreakPoint(foo, 0);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 1493
1494 1494
1495 v8::Debug::SetDebugEventListener(NULL); 1495 v8::Debug::SetDebugEventListener(NULL);
1496 CheckDebuggerUnloaded(); 1496 CheckDebuggerUnloaded();
1497 } 1497 }
1498 1498
1499 1499
1500 // Test that break points can be set using the global Debug object. 1500 // Test that break points can be set using the global Debug object.
1501 TEST(BreakPointThroughJavaScript) { 1501 TEST(BreakPointThroughJavaScript) {
1502 break_point_hit_count = 0; 1502 break_point_hit_count = 0;
1503 v8::HandleScope scope;
1504 DebugLocalContext env; 1503 DebugLocalContext env;
1504 v8::HandleScope scope(env->GetIsolate());
1505 env.ExposeDebug(); 1505 env.ExposeDebug();
1506 1506
1507 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1507 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1508 v8::Undefined()); 1508 v8::Undefined());
1509 v8::Script::Compile(v8::String::New("function bar(){}"))->Run(); 1509 v8::Script::Compile(v8::String::New("function bar(){}"))->Run();
1510 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run(); 1510 v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run();
1511 // 012345678901234567890 1511 // 012345678901234567890
1512 // 1 2 1512 // 1 2
1513 // Break points are set at position 3 and 9 1513 // Break points are set at position 3 and 9
1514 v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()")); 1514 v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()"));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 // Make sure that the break point numbers are consecutive. 1549 // Make sure that the break point numbers are consecutive.
1550 CHECK_EQ(1, bp1); 1550 CHECK_EQ(1, bp1);
1551 CHECK_EQ(2, bp2); 1551 CHECK_EQ(2, bp2);
1552 } 1552 }
1553 1553
1554 1554
1555 // Test that break points on scripts identified by name can be set using the 1555 // Test that break points on scripts identified by name can be set using the
1556 // global Debug object. 1556 // global Debug object.
1557 TEST(ScriptBreakPointByNameThroughJavaScript) { 1557 TEST(ScriptBreakPointByNameThroughJavaScript) {
1558 break_point_hit_count = 0; 1558 break_point_hit_count = 0;
1559 v8::HandleScope scope;
1560 DebugLocalContext env; 1559 DebugLocalContext env;
1560 v8::HandleScope scope(env->GetIsolate());
1561 env.ExposeDebug(); 1561 env.ExposeDebug();
1562 1562
1563 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1563 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1564 v8::Undefined()); 1564 v8::Undefined());
1565 1565
1566 v8::Local<v8::String> script = v8::String::New( 1566 v8::Local<v8::String> script = v8::String::New(
1567 "function f() {\n" 1567 "function f() {\n"
1568 " function h() {\n" 1568 " function h() {\n"
1569 " a = 0; // line 2\n" 1569 " a = 0; // line 2\n"
1570 " }\n" 1570 " }\n"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 CHECK_EQ(2, sbp2); 1653 CHECK_EQ(2, sbp2);
1654 CHECK_EQ(3, sbp3); 1654 CHECK_EQ(3, sbp3);
1655 CHECK_EQ(4, sbp4); 1655 CHECK_EQ(4, sbp4);
1656 CHECK_EQ(5, sbp5); 1656 CHECK_EQ(5, sbp5);
1657 CHECK_EQ(6, sbp6); 1657 CHECK_EQ(6, sbp6);
1658 } 1658 }
1659 1659
1660 1660
1661 TEST(ScriptBreakPointByIdThroughJavaScript) { 1661 TEST(ScriptBreakPointByIdThroughJavaScript) {
1662 break_point_hit_count = 0; 1662 break_point_hit_count = 0;
1663 v8::HandleScope scope;
1664 DebugLocalContext env; 1663 DebugLocalContext env;
1664 v8::HandleScope scope(env->GetIsolate());
1665 env.ExposeDebug(); 1665 env.ExposeDebug();
1666 1666
1667 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1667 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1668 v8::Undefined()); 1668 v8::Undefined());
1669 1669
1670 v8::Local<v8::String> source = v8::String::New( 1670 v8::Local<v8::String> source = v8::String::New(
1671 "function f() {\n" 1671 "function f() {\n"
1672 " function h() {\n" 1672 " function h() {\n"
1673 " a = 0; // line 2\n" 1673 " a = 0; // line 2\n"
1674 " }\n" 1674 " }\n"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 CHECK_EQ(3, sbp3); 1762 CHECK_EQ(3, sbp3);
1763 CHECK_EQ(4, sbp4); 1763 CHECK_EQ(4, sbp4);
1764 CHECK_EQ(5, sbp5); 1764 CHECK_EQ(5, sbp5);
1765 CHECK_EQ(6, sbp6); 1765 CHECK_EQ(6, sbp6);
1766 } 1766 }
1767 1767
1768 1768
1769 // Test conditional script break points. 1769 // Test conditional script break points.
1770 TEST(EnableDisableScriptBreakPoint) { 1770 TEST(EnableDisableScriptBreakPoint) {
1771 break_point_hit_count = 0; 1771 break_point_hit_count = 0;
1772 v8::HandleScope scope;
1773 DebugLocalContext env; 1772 DebugLocalContext env;
1773 v8::HandleScope scope(env->GetIsolate());
1774 env.ExposeDebug(); 1774 env.ExposeDebug();
1775 1775
1776 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1776 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1777 v8::Undefined()); 1777 v8::Undefined());
1778 1778
1779 v8::Local<v8::String> script = v8::String::New( 1779 v8::Local<v8::String> script = v8::String::New(
1780 "function f() {\n" 1780 "function f() {\n"
1781 " a = 0; // line 1\n" 1781 " a = 0; // line 1\n"
1782 "};"); 1782 "};");
1783 1783
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 CHECK_EQ(3, break_point_hit_count); 1819 CHECK_EQ(3, break_point_hit_count);
1820 1820
1821 v8::Debug::SetDebugEventListener(NULL); 1821 v8::Debug::SetDebugEventListener(NULL);
1822 CheckDebuggerUnloaded(); 1822 CheckDebuggerUnloaded();
1823 } 1823 }
1824 1824
1825 1825
1826 // Test conditional script break points. 1826 // Test conditional script break points.
1827 TEST(ConditionalScriptBreakPoint) { 1827 TEST(ConditionalScriptBreakPoint) {
1828 break_point_hit_count = 0; 1828 break_point_hit_count = 0;
1829 v8::HandleScope scope;
1830 DebugLocalContext env; 1829 DebugLocalContext env;
1830 v8::HandleScope scope(env->GetIsolate());
1831 env.ExposeDebug(); 1831 env.ExposeDebug();
1832 1832
1833 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1833 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1834 v8::Undefined()); 1834 v8::Undefined());
1835 1835
1836 v8::Local<v8::String> script = v8::String::New( 1836 v8::Local<v8::String> script = v8::String::New(
1837 "count = 0;\n" 1837 "count = 0;\n"
1838 "function f() {\n" 1838 "function f() {\n"
1839 " g(count++); // line 2\n" 1839 " g(count++); // line 2\n"
1840 "};\n" 1840 "};\n"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 CHECK_EQ(5, break_point_hit_count); 1881 CHECK_EQ(5, break_point_hit_count);
1882 1882
1883 v8::Debug::SetDebugEventListener(NULL); 1883 v8::Debug::SetDebugEventListener(NULL);
1884 CheckDebuggerUnloaded(); 1884 CheckDebuggerUnloaded();
1885 } 1885 }
1886 1886
1887 1887
1888 // Test ignore count on script break points. 1888 // Test ignore count on script break points.
1889 TEST(ScriptBreakPointIgnoreCount) { 1889 TEST(ScriptBreakPointIgnoreCount) {
1890 break_point_hit_count = 0; 1890 break_point_hit_count = 0;
1891 v8::HandleScope scope;
1892 DebugLocalContext env; 1891 DebugLocalContext env;
1892 v8::HandleScope scope(env->GetIsolate());
1893 env.ExposeDebug(); 1893 env.ExposeDebug();
1894 1894
1895 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1895 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1896 v8::Undefined()); 1896 v8::Undefined());
1897 1897
1898 v8::Local<v8::String> script = v8::String::New( 1898 v8::Local<v8::String> script = v8::String::New(
1899 "function f() {\n" 1899 "function f() {\n"
1900 " a = 0; // line 1\n" 1900 " a = 0; // line 1\n"
1901 "};"); 1901 "};");
1902 1902
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 CHECK_EQ(5, break_point_hit_count); 1936 CHECK_EQ(5, break_point_hit_count);
1937 1937
1938 v8::Debug::SetDebugEventListener(NULL); 1938 v8::Debug::SetDebugEventListener(NULL);
1939 CheckDebuggerUnloaded(); 1939 CheckDebuggerUnloaded();
1940 } 1940 }
1941 1941
1942 1942
1943 // Test that script break points survive when a script is reloaded. 1943 // Test that script break points survive when a script is reloaded.
1944 TEST(ScriptBreakPointReload) { 1944 TEST(ScriptBreakPointReload) {
1945 break_point_hit_count = 0; 1945 break_point_hit_count = 0;
1946 v8::HandleScope scope;
1947 DebugLocalContext env; 1946 DebugLocalContext env;
1947 v8::HandleScope scope(env->GetIsolate());
1948 env.ExposeDebug(); 1948 env.ExposeDebug();
1949 1949
1950 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 1950 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
1951 v8::Undefined()); 1951 v8::Undefined());
1952 1952
1953 v8::Local<v8::Function> f; 1953 v8::Local<v8::Function> f;
1954 v8::Local<v8::String> script = v8::String::New( 1954 v8::Local<v8::String> script = v8::String::New(
1955 "function f() {\n" 1955 "function f() {\n"
1956 " function h() {\n" 1956 " function h() {\n"
1957 " a = 0; // line 2\n" 1957 " a = 0; // line 2\n"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 CHECK_EQ(1, break_point_hit_count); 1995 CHECK_EQ(1, break_point_hit_count);
1996 1996
1997 v8::Debug::SetDebugEventListener(NULL); 1997 v8::Debug::SetDebugEventListener(NULL);
1998 CheckDebuggerUnloaded(); 1998 CheckDebuggerUnloaded();
1999 } 1999 }
2000 2000
2001 2001
2002 // Test when several scripts has the same script data 2002 // Test when several scripts has the same script data
2003 TEST(ScriptBreakPointMultiple) { 2003 TEST(ScriptBreakPointMultiple) {
2004 break_point_hit_count = 0; 2004 break_point_hit_count = 0;
2005 v8::HandleScope scope;
2006 DebugLocalContext env; 2005 DebugLocalContext env;
2006 v8::HandleScope scope(env->GetIsolate());
2007 env.ExposeDebug(); 2007 env.ExposeDebug();
2008 2008
2009 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2009 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2010 v8::Undefined()); 2010 v8::Undefined());
2011 2011
2012 v8::Local<v8::Function> f; 2012 v8::Local<v8::Function> f;
2013 v8::Local<v8::String> script_f = v8::String::New( 2013 v8::Local<v8::String> script_f = v8::String::New(
2014 "function f() {\n" 2014 "function f() {\n"
2015 " a = 0; // line 1\n" 2015 " a = 0; // line 1\n"
2016 "}"); 2016 "}");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 CHECK_EQ(2, break_point_hit_count); 2061 CHECK_EQ(2, break_point_hit_count);
2062 2062
2063 v8::Debug::SetDebugEventListener(NULL); 2063 v8::Debug::SetDebugEventListener(NULL);
2064 CheckDebuggerUnloaded(); 2064 CheckDebuggerUnloaded();
2065 } 2065 }
2066 2066
2067 2067
2068 // Test the script origin which has both name and line offset. 2068 // Test the script origin which has both name and line offset.
2069 TEST(ScriptBreakPointLineOffset) { 2069 TEST(ScriptBreakPointLineOffset) {
2070 break_point_hit_count = 0; 2070 break_point_hit_count = 0;
2071 v8::HandleScope scope;
2072 DebugLocalContext env; 2071 DebugLocalContext env;
2072 v8::HandleScope scope(env->GetIsolate());
2073 env.ExposeDebug(); 2073 env.ExposeDebug();
2074 2074
2075 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2075 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2076 v8::Undefined()); 2076 v8::Undefined());
2077 2077
2078 v8::Local<v8::Function> f; 2078 v8::Local<v8::Function> f;
2079 v8::Local<v8::String> script = v8::String::New( 2079 v8::Local<v8::String> script = v8::String::New(
2080 "function f() {\n" 2080 "function f() {\n"
2081 " a = 0; // line 8 as this script has line offset 7\n" 2081 " a = 0; // line 8 as this script has line offset 7\n"
2082 " b = 0; // line 9 as this script has line offset 7\n" 2082 " b = 0; // line 9 as this script has line offset 7\n"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 f->Call(env->Global(), 0, NULL); 2116 f->Call(env->Global(), 0, NULL);
2117 CHECK_EQ(1, break_point_hit_count); 2117 CHECK_EQ(1, break_point_hit_count);
2118 2118
2119 v8::Debug::SetDebugEventListener(NULL); 2119 v8::Debug::SetDebugEventListener(NULL);
2120 CheckDebuggerUnloaded(); 2120 CheckDebuggerUnloaded();
2121 } 2121 }
2122 2122
2123 2123
2124 // Test script break points set on lines. 2124 // Test script break points set on lines.
2125 TEST(ScriptBreakPointLine) { 2125 TEST(ScriptBreakPointLine) {
2126 v8::HandleScope scope;
2127 DebugLocalContext env; 2126 DebugLocalContext env;
2127 v8::HandleScope scope(env->GetIsolate());
2128 env.ExposeDebug(); 2128 env.ExposeDebug();
2129 2129
2130 // Create a function for checking the function when hitting a break point. 2130 // Create a function for checking the function when hitting a break point.
2131 frame_function_name = CompileFunction(&env, 2131 frame_function_name = CompileFunction(&env,
2132 frame_function_name_source, 2132 frame_function_name_source,
2133 "frame_function_name"); 2133 "frame_function_name");
2134 2134
2135 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2135 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2136 v8::Undefined()); 2136 v8::Undefined());
2137 2137
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 v8::Script::Compile(script, &origin)->Run(); 2222 v8::Script::Compile(script, &origin)->Run();
2223 CHECK_EQ(0, break_point_hit_count); 2223 CHECK_EQ(0, break_point_hit_count);
2224 2224
2225 v8::Debug::SetDebugEventListener(NULL); 2225 v8::Debug::SetDebugEventListener(NULL);
2226 CheckDebuggerUnloaded(); 2226 CheckDebuggerUnloaded();
2227 } 2227 }
2228 2228
2229 2229
2230 // Test top level script break points set on lines. 2230 // Test top level script break points set on lines.
2231 TEST(ScriptBreakPointLineTopLevel) { 2231 TEST(ScriptBreakPointLineTopLevel) {
2232 v8::HandleScope scope;
2233 DebugLocalContext env; 2232 DebugLocalContext env;
2233 v8::HandleScope scope(env->GetIsolate());
2234 env.ExposeDebug(); 2234 env.ExposeDebug();
2235 2235
2236 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2236 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2237 v8::Undefined()); 2237 v8::Undefined());
2238 2238
2239 v8::Local<v8::String> script = v8::String::New( 2239 v8::Local<v8::String> script = v8::String::New(
2240 "function f() {\n" 2240 "function f() {\n"
2241 " a = 1; // line 1\n" 2241 " a = 1; // line 1\n"
2242 "}\n" 2242 "}\n"
2243 "a = 2; // line 3\n"); 2243 "a = 2; // line 3\n");
2244 v8::Local<v8::Function> f; 2244 v8::Local<v8::Function> f;
2245 { 2245 {
2246 v8::HandleScope scope; 2246 v8::HandleScope scope(env->GetIsolate());
2247 v8::Script::Compile(script, v8::String::New("test.html"))->Run(); 2247 v8::Script::Compile(script, v8::String::New("test.html"))->Run();
2248 } 2248 }
2249 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 2249 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
2250 2250
2251 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 2251 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2252 2252
2253 SetScriptBreakPointByNameFromJS("test.html", 3, -1); 2253 SetScriptBreakPointByNameFromJS("test.html", 3, -1);
2254 2254
2255 // Call f and check that there was no break points. 2255 // Call f and check that there was no break points.
2256 break_point_hit_count = 0; 2256 break_point_hit_count = 0;
(...skipping 11 matching lines...) Expand all
2268 CHECK_EQ(0, break_point_hit_count); 2268 CHECK_EQ(0, break_point_hit_count);
2269 2269
2270 v8::Debug::SetDebugEventListener(NULL); 2270 v8::Debug::SetDebugEventListener(NULL);
2271 CheckDebuggerUnloaded(); 2271 CheckDebuggerUnloaded();
2272 } 2272 }
2273 2273
2274 2274
2275 // Test that it is possible to add and remove break points in a top level 2275 // Test that it is possible to add and remove break points in a top level
2276 // function which has no references but has not been collected yet. 2276 // function which has no references but has not been collected yet.
2277 TEST(ScriptBreakPointTopLevelCrash) { 2277 TEST(ScriptBreakPointTopLevelCrash) {
2278 v8::HandleScope scope;
2279 DebugLocalContext env; 2278 DebugLocalContext env;
2279 v8::HandleScope scope(env->GetIsolate());
2280 env.ExposeDebug(); 2280 env.ExposeDebug();
2281 2281
2282 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2282 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2283 v8::Undefined()); 2283 v8::Undefined());
2284 2284
2285 v8::Local<v8::String> script_source = v8::String::New( 2285 v8::Local<v8::String> script_source = v8::String::New(
2286 "function f() {\n" 2286 "function f() {\n"
2287 " return 0;\n" 2287 " return 0;\n"
2288 "}\n" 2288 "}\n"
2289 "f()"); 2289 "f()");
2290 2290
2291 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); 2291 int sbp1 = SetScriptBreakPointByNameFromJS("test.html", 3, -1);
2292 { 2292 {
2293 v8::HandleScope scope; 2293 v8::HandleScope scope(env->GetIsolate());
2294 break_point_hit_count = 0; 2294 break_point_hit_count = 0;
2295 v8::Script::Compile(script_source, v8::String::New("test.html"))->Run(); 2295 v8::Script::Compile(script_source, v8::String::New("test.html"))->Run();
2296 CHECK_EQ(1, break_point_hit_count); 2296 CHECK_EQ(1, break_point_hit_count);
2297 } 2297 }
2298 2298
2299 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 3, -1); 2299 int sbp2 = SetScriptBreakPointByNameFromJS("test.html", 3, -1);
2300 ClearBreakPointFromJS(sbp1); 2300 ClearBreakPointFromJS(sbp1);
2301 ClearBreakPointFromJS(sbp2); 2301 ClearBreakPointFromJS(sbp2);
2302 2302
2303 v8::Debug::SetDebugEventListener(NULL); 2303 v8::Debug::SetDebugEventListener(NULL);
2304 CheckDebuggerUnloaded(); 2304 CheckDebuggerUnloaded();
2305 } 2305 }
2306 2306
2307 2307
2308 // Test that it is possible to remove the last break point for a function 2308 // Test that it is possible to remove the last break point for a function
2309 // inside the break handling of that break point. 2309 // inside the break handling of that break point.
2310 TEST(RemoveBreakPointInBreak) { 2310 TEST(RemoveBreakPointInBreak) {
2311 v8::HandleScope scope;
2312 DebugLocalContext env; 2311 DebugLocalContext env;
2312 v8::HandleScope scope(env->GetIsolate());
2313 2313
2314 v8::Local<v8::Function> foo = 2314 v8::Local<v8::Function> foo =
2315 CompileFunction(&env, "function foo(){a=1;}", "foo"); 2315 CompileFunction(&env, "function foo(){a=1;}", "foo");
2316 debug_event_remove_break_point = SetBreakPoint(foo, 0); 2316 debug_event_remove_break_point = SetBreakPoint(foo, 0);
2317 2317
2318 // Register the debug event listener pasing the function 2318 // Register the debug event listener pasing the function
2319 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); 2319 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo);
2320 2320
2321 break_point_hit_count = 0; 2321 break_point_hit_count = 0;
2322 foo->Call(env->Global(), 0, NULL); 2322 foo->Call(env->Global(), 0, NULL);
2323 CHECK_EQ(1, break_point_hit_count); 2323 CHECK_EQ(1, break_point_hit_count);
2324 2324
2325 break_point_hit_count = 0; 2325 break_point_hit_count = 0;
2326 foo->Call(env->Global(), 0, NULL); 2326 foo->Call(env->Global(), 0, NULL);
2327 CHECK_EQ(0, break_point_hit_count); 2327 CHECK_EQ(0, break_point_hit_count);
2328 2328
2329 v8::Debug::SetDebugEventListener(NULL); 2329 v8::Debug::SetDebugEventListener(NULL);
2330 CheckDebuggerUnloaded(); 2330 CheckDebuggerUnloaded();
2331 } 2331 }
2332 2332
2333 2333
2334 // Test that the debugger statement causes a break. 2334 // Test that the debugger statement causes a break.
2335 TEST(DebuggerStatement) { 2335 TEST(DebuggerStatement) {
2336 break_point_hit_count = 0; 2336 break_point_hit_count = 0;
2337 v8::HandleScope scope;
2338 DebugLocalContext env; 2337 DebugLocalContext env;
2338 v8::HandleScope scope(env->GetIsolate());
2339 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2339 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2340 v8::Undefined()); 2340 v8::Undefined());
2341 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run(); 2341 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run();
2342 v8::Script::Compile(v8::String::New( 2342 v8::Script::Compile(v8::String::New(
2343 "function foo(){debugger;debugger;}"))->Run(); 2343 "function foo(){debugger;debugger;}"))->Run();
2344 v8::Local<v8::Function> foo = 2344 v8::Local<v8::Function> foo =
2345 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 2345 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
2346 v8::Local<v8::Function> bar = 2346 v8::Local<v8::Function> bar =
2347 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar"))); 2347 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar")));
2348 2348
2349 // Run function with debugger statement 2349 // Run function with debugger statement
2350 bar->Call(env->Global(), 0, NULL); 2350 bar->Call(env->Global(), 0, NULL);
2351 CHECK_EQ(1, break_point_hit_count); 2351 CHECK_EQ(1, break_point_hit_count);
2352 2352
2353 // Run function with two debugger statement 2353 // Run function with two debugger statement
2354 foo->Call(env->Global(), 0, NULL); 2354 foo->Call(env->Global(), 0, NULL);
2355 CHECK_EQ(3, break_point_hit_count); 2355 CHECK_EQ(3, break_point_hit_count);
2356 2356
2357 v8::Debug::SetDebugEventListener(NULL); 2357 v8::Debug::SetDebugEventListener(NULL);
2358 CheckDebuggerUnloaded(); 2358 CheckDebuggerUnloaded();
2359 } 2359 }
2360 2360
2361 2361
2362 // Test setting a breakpoint on the debugger statement. 2362 // Test setting a breakpoint on the debugger statement.
2363 TEST(DebuggerStatementBreakpoint) { 2363 TEST(DebuggerStatementBreakpoint) {
2364 break_point_hit_count = 0; 2364 break_point_hit_count = 0;
2365 v8::HandleScope scope;
2366 DebugLocalContext env; 2365 DebugLocalContext env;
2366 v8::HandleScope scope(env->GetIsolate());
2367 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 2367 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
2368 v8::Undefined()); 2368 v8::Undefined());
2369 v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run(); 2369 v8::Script::Compile(v8::String::New("function foo(){debugger;}"))->Run();
2370 v8::Local<v8::Function> foo = 2370 v8::Local<v8::Function> foo =
2371 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); 2371 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
2372 2372
2373 // The debugger statement triggers breakpint hit 2373 // The debugger statement triggers breakpint hit
2374 foo->Call(env->Global(), 0, NULL); 2374 foo->Call(env->Global(), 0, NULL);
2375 CHECK_EQ(1, break_point_hit_count); 2375 CHECK_EQ(1, break_point_hit_count);
2376 2376
2377 int bp = SetBreakPoint(foo, 0); 2377 int bp = SetBreakPoint(foo, 0);
2378 2378
2379 // Set breakpoint does not duplicate hits 2379 // Set breakpoint does not duplicate hits
2380 foo->Call(env->Global(), 0, NULL); 2380 foo->Call(env->Global(), 0, NULL);
2381 CHECK_EQ(2, break_point_hit_count); 2381 CHECK_EQ(2, break_point_hit_count);
2382 2382
2383 ClearBreakPoint(bp); 2383 ClearBreakPoint(bp);
2384 v8::Debug::SetDebugEventListener(NULL); 2384 v8::Debug::SetDebugEventListener(NULL);
2385 CheckDebuggerUnloaded(); 2385 CheckDebuggerUnloaded();
2386 } 2386 }
2387 2387
2388 2388
2389 // Test that the evaluation of expressions when a break point is hit generates 2389 // Test that the evaluation of expressions when a break point is hit generates
2390 // the correct results. 2390 // the correct results.
2391 TEST(DebugEvaluate) { 2391 TEST(DebugEvaluate) {
2392 v8::HandleScope scope;
2393 DebugLocalContext env; 2392 DebugLocalContext env;
2393 v8::HandleScope scope(env->GetIsolate());
2394 env.ExposeDebug(); 2394 env.ExposeDebug();
2395 2395
2396 // Create a function for checking the evaluation when hitting a break point. 2396 // Create a function for checking the evaluation when hitting a break point.
2397 evaluate_check_function = CompileFunction(&env, 2397 evaluate_check_function = CompileFunction(&env,
2398 evaluate_check_source, 2398 evaluate_check_source,
2399 "evaluate_check"); 2399 "evaluate_check");
2400 // Register the debug event listener 2400 // Register the debug event listener
2401 v8::Debug::SetDebugEventListener(DebugEventEvaluate); 2401 v8::Debug::SetDebugEventListener(DebugEventEvaluate);
2402 2402
2403 // Different expected vaules of x and a when in a break point (u = undefined, 2403 // Different expected vaules of x and a when in a break point (u = undefined,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 2504
2505 2505
2506 int debugEventCount = 0; 2506 int debugEventCount = 0;
2507 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) { 2507 static void CheckDebugEvent(const v8::Debug::EventDetails& eventDetails) {
2508 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount; 2508 if (eventDetails.GetEvent() == v8::Break) ++debugEventCount;
2509 } 2509 }
2510 2510
2511 // Test that the conditional breakpoints work event if code generation from 2511 // Test that the conditional breakpoints work event if code generation from
2512 // strings is prohibited in the debugee context. 2512 // strings is prohibited in the debugee context.
2513 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) { 2513 TEST(ConditionalBreakpointWithCodeGenerationDisallowed) {
2514 v8::HandleScope scope;
2515 DebugLocalContext env; 2514 DebugLocalContext env;
2515 v8::HandleScope scope(env->GetIsolate());
2516 env.ExposeDebug(); 2516 env.ExposeDebug();
2517 2517
2518 v8::Debug::SetDebugEventListener2(CheckDebugEvent); 2518 v8::Debug::SetDebugEventListener2(CheckDebugEvent);
2519 2519
2520 v8::Local<v8::Function> foo = CompileFunction(&env, 2520 v8::Local<v8::Function> foo = CompileFunction(&env,
2521 "function foo(x) {\n" 2521 "function foo(x) {\n"
2522 " var s = 'String value2';\n" 2522 " var s = 'String value2';\n"
2523 " return s + x;\n" 2523 " return s + x;\n"
2524 "}", 2524 "}",
2525 "foo"); 2525 "foo");
(...skipping 10 matching lines...) Expand all
2536 CheckDebuggerUnloaded(); 2536 CheckDebuggerUnloaded();
2537 } 2537 }
2538 2538
2539 2539
2540 bool checkedDebugEvals = true; 2540 bool checkedDebugEvals = true;
2541 v8::Handle<v8::Function> checkGlobalEvalFunction; 2541 v8::Handle<v8::Function> checkGlobalEvalFunction;
2542 v8::Handle<v8::Function> checkFrameEvalFunction; 2542 v8::Handle<v8::Function> checkFrameEvalFunction;
2543 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) { 2543 static void CheckDebugEval(const v8::Debug::EventDetails& eventDetails) {
2544 if (eventDetails.GetEvent() == v8::Break) { 2544 if (eventDetails.GetEvent() == v8::Break) {
2545 ++debugEventCount; 2545 ++debugEventCount;
2546 v8::HandleScope handleScope; 2546 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
2547 2547
2548 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() }; 2548 v8::Handle<v8::Value> args[] = { eventDetails.GetExecutionState() };
2549 CHECK(checkGlobalEvalFunction->Call( 2549 CHECK(checkGlobalEvalFunction->Call(
2550 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); 2550 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
2551 CHECK(checkFrameEvalFunction->Call( 2551 CHECK(checkFrameEvalFunction->Call(
2552 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue()); 2552 eventDetails.GetEventContext()->Global(), 1, args)->IsTrue());
2553 } 2553 }
2554 } 2554 }
2555 2555
2556 // Test that the evaluation of expressions when a break point is hit generates 2556 // Test that the evaluation of expressions when a break point is hit generates
2557 // the correct results in case code generation from strings is disallowed in the 2557 // the correct results in case code generation from strings is disallowed in the
2558 // debugee context. 2558 // debugee context.
2559 TEST(DebugEvaluateWithCodeGenerationDisallowed) { 2559 TEST(DebugEvaluateWithCodeGenerationDisallowed) {
2560 v8::HandleScope scope;
2561 DebugLocalContext env; 2560 DebugLocalContext env;
2561 v8::HandleScope scope(env->GetIsolate());
2562 env.ExposeDebug(); 2562 env.ExposeDebug();
2563 2563
2564 v8::Debug::SetDebugEventListener2(CheckDebugEval); 2564 v8::Debug::SetDebugEventListener2(CheckDebugEval);
2565 2565
2566 v8::Local<v8::Function> foo = CompileFunction(&env, 2566 v8::Local<v8::Function> foo = CompileFunction(&env,
2567 "var global = 'Global';\n" 2567 "var global = 'Global';\n"
2568 "function foo(x) {\n" 2568 "function foo(x) {\n"
2569 " var local = 'Local';\n" 2569 " var local = 'Local';\n"
2570 " debugger;\n" 2570 " debugger;\n"
2571 " return local + x;\n" 2571 " return local + x;\n"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 if (res) { 2692 if (res) {
2693 process_debug_messages_data.next(); 2693 process_debug_messages_data.next();
2694 } 2694 }
2695 } 2695 }
2696 2696
2697 // Test that the evaluation of expressions works even from ProcessDebugMessages 2697 // Test that the evaluation of expressions works even from ProcessDebugMessages
2698 // i.e. with empty stack. 2698 // i.e. with empty stack.
2699 TEST(DebugEvaluateWithoutStack) { 2699 TEST(DebugEvaluateWithoutStack) {
2700 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler); 2700 v8::Debug::SetMessageHandler(DebugProcessDebugMessagesHandler);
2701 2701
2702 v8::HandleScope scope;
2703 DebugLocalContext env; 2702 DebugLocalContext env;
2703 v8::HandleScope scope(env->GetIsolate());
2704 2704
2705 const char* source = 2705 const char* source =
2706 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }"; 2706 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }";
2707 2707
2708 v8::Script::Compile(v8::String::New(source))->Run(); 2708 v8::Script::Compile(v8::String::New(source))->Run();
2709 2709
2710 v8::Debug::ProcessDebugMessages(); 2710 v8::Debug::ProcessDebugMessages();
2711 2711
2712 const int kBufferSize = 1000; 2712 const int kBufferSize = 1000;
2713 uint16_t buffer[kBufferSize]; 2713 uint16_t buffer[kBufferSize];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); 2752 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0);
2753 2753
2754 v8::Debug::SetMessageHandler(NULL); 2754 v8::Debug::SetMessageHandler(NULL);
2755 v8::Debug::SetDebugEventListener(NULL); 2755 v8::Debug::SetDebugEventListener(NULL);
2756 CheckDebuggerUnloaded(); 2756 CheckDebuggerUnloaded();
2757 } 2757 }
2758 2758
2759 2759
2760 // Simple test of the stepping mechanism using only store ICs. 2760 // Simple test of the stepping mechanism using only store ICs.
2761 TEST(DebugStepLinear) { 2761 TEST(DebugStepLinear) {
2762 v8::HandleScope scope;
2763 DebugLocalContext env; 2762 DebugLocalContext env;
2763 v8::HandleScope scope(env->GetIsolate());
2764 2764
2765 // Create a function for testing stepping. 2765 // Create a function for testing stepping.
2766 v8::Local<v8::Function> foo = CompileFunction(&env, 2766 v8::Local<v8::Function> foo = CompileFunction(&env,
2767 "function foo(){a=1;b=1;c=1;}", 2767 "function foo(){a=1;b=1;c=1;}",
2768 "foo"); 2768 "foo");
2769 2769
2770 // Run foo to allow it to get optimized. 2770 // Run foo to allow it to get optimized.
2771 CompileRun("a=0; b=0; c=0; foo();"); 2771 CompileRun("a=0; b=0; c=0; foo();");
2772 2772
2773 SetBreakPoint(foo, 3); 2773 SetBreakPoint(foo, 3);
(...skipping 21 matching lines...) Expand all
2795 // Without stepping only active break points are hit. 2795 // Without stepping only active break points are hit.
2796 CHECK_EQ(1, break_point_hit_count); 2796 CHECK_EQ(1, break_point_hit_count);
2797 2797
2798 v8::Debug::SetDebugEventListener(NULL); 2798 v8::Debug::SetDebugEventListener(NULL);
2799 CheckDebuggerUnloaded(); 2799 CheckDebuggerUnloaded();
2800 } 2800 }
2801 2801
2802 2802
2803 // Test of the stepping mechanism for keyed load in a loop. 2803 // Test of the stepping mechanism for keyed load in a loop.
2804 TEST(DebugStepKeyedLoadLoop) { 2804 TEST(DebugStepKeyedLoadLoop) {
2805 v8::HandleScope scope;
2806 DebugLocalContext env; 2805 DebugLocalContext env;
2806 v8::HandleScope scope(env->GetIsolate());
2807 2807
2808 // Register a debug event listener which steps and counts. 2808 // Register a debug event listener which steps and counts.
2809 v8::Debug::SetDebugEventListener(DebugEventStep); 2809 v8::Debug::SetDebugEventListener(DebugEventStep);
2810 2810
2811 // Create a function for testing stepping of keyed load. The statement 'y=1' 2811 // Create a function for testing stepping of keyed load. The statement 'y=1'
2812 // is there to have more than one breakable statement in the loop, TODO(315). 2812 // is there to have more than one breakable statement in the loop, TODO(315).
2813 v8::Local<v8::Function> foo = CompileFunction( 2813 v8::Local<v8::Function> foo = CompileFunction(
2814 &env, 2814 &env,
2815 "function foo(a) {\n" 2815 "function foo(a) {\n"
2816 " var x;\n" 2816 " var x;\n"
(...skipping 26 matching lines...) Expand all
2843 // With stepping all break locations are hit. 2843 // With stepping all break locations are hit.
2844 CHECK_EQ(34, break_point_hit_count); 2844 CHECK_EQ(34, break_point_hit_count);
2845 2845
2846 v8::Debug::SetDebugEventListener(NULL); 2846 v8::Debug::SetDebugEventListener(NULL);
2847 CheckDebuggerUnloaded(); 2847 CheckDebuggerUnloaded();
2848 } 2848 }
2849 2849
2850 2850
2851 // Test of the stepping mechanism for keyed store in a loop. 2851 // Test of the stepping mechanism for keyed store in a loop.
2852 TEST(DebugStepKeyedStoreLoop) { 2852 TEST(DebugStepKeyedStoreLoop) {
2853 v8::HandleScope scope;
2854 DebugLocalContext env; 2853 DebugLocalContext env;
2854 v8::HandleScope scope(env->GetIsolate());
2855 2855
2856 // Register a debug event listener which steps and counts. 2856 // Register a debug event listener which steps and counts.
2857 v8::Debug::SetDebugEventListener(DebugEventStep); 2857 v8::Debug::SetDebugEventListener(DebugEventStep);
2858 2858
2859 // Create a function for testing stepping of keyed store. The statement 'y=1' 2859 // Create a function for testing stepping of keyed store. The statement 'y=1'
2860 // is there to have more than one breakable statement in the loop, TODO(315). 2860 // is there to have more than one breakable statement in the loop, TODO(315).
2861 v8::Local<v8::Function> foo = CompileFunction( 2861 v8::Local<v8::Function> foo = CompileFunction(
2862 &env, 2862 &env,
2863 "function foo(a) {\n" 2863 "function foo(a) {\n"
2864 " var len = a.length;\n" 2864 " var len = a.length;\n"
(...skipping 25 matching lines...) Expand all
2890 // With stepping all break locations are hit. 2890 // With stepping all break locations are hit.
2891 CHECK_EQ(33, break_point_hit_count); 2891 CHECK_EQ(33, break_point_hit_count);
2892 2892
2893 v8::Debug::SetDebugEventListener(NULL); 2893 v8::Debug::SetDebugEventListener(NULL);
2894 CheckDebuggerUnloaded(); 2894 CheckDebuggerUnloaded();
2895 } 2895 }
2896 2896
2897 2897
2898 // Test of the stepping mechanism for named load in a loop. 2898 // Test of the stepping mechanism for named load in a loop.
2899 TEST(DebugStepNamedLoadLoop) { 2899 TEST(DebugStepNamedLoadLoop) {
2900 v8::HandleScope scope;
2901 DebugLocalContext env; 2900 DebugLocalContext env;
2901 v8::HandleScope scope(env->GetIsolate());
2902 2902
2903 // Register a debug event listener which steps and counts. 2903 // Register a debug event listener which steps and counts.
2904 v8::Debug::SetDebugEventListener(DebugEventStep); 2904 v8::Debug::SetDebugEventListener(DebugEventStep);
2905 2905
2906 // Create a function for testing stepping of named load. 2906 // Create a function for testing stepping of named load.
2907 v8::Local<v8::Function> foo = CompileFunction( 2907 v8::Local<v8::Function> foo = CompileFunction(
2908 &env, 2908 &env,
2909 "function foo() {\n" 2909 "function foo() {\n"
2910 " var a = [];\n" 2910 " var a = [];\n"
2911 " var s = \"\";\n" 2911 " var s = \"\";\n"
(...skipping 21 matching lines...) Expand all
2933 2933
2934 // With stepping all break locations are hit. 2934 // With stepping all break locations are hit.
2935 CHECK_EQ(54, break_point_hit_count); 2935 CHECK_EQ(54, break_point_hit_count);
2936 2936
2937 v8::Debug::SetDebugEventListener(NULL); 2937 v8::Debug::SetDebugEventListener(NULL);
2938 CheckDebuggerUnloaded(); 2938 CheckDebuggerUnloaded();
2939 } 2939 }
2940 2940
2941 2941
2942 static void DoDebugStepNamedStoreLoop(int expected) { 2942 static void DoDebugStepNamedStoreLoop(int expected) {
2943 v8::HandleScope scope;
2944 DebugLocalContext env; 2943 DebugLocalContext env;
2944 v8::HandleScope scope(env->GetIsolate());
2945 2945
2946 // Register a debug event listener which steps and counts. 2946 // Register a debug event listener which steps and counts.
2947 v8::Debug::SetDebugEventListener(DebugEventStep); 2947 v8::Debug::SetDebugEventListener(DebugEventStep);
2948 2948
2949 // Create a function for testing stepping of named store. 2949 // Create a function for testing stepping of named store.
2950 v8::Local<v8::Function> foo = CompileFunction( 2950 v8::Local<v8::Function> foo = CompileFunction(
2951 &env, 2951 &env,
2952 "function foo() {\n" 2952 "function foo() {\n"
2953 " var a = {a:1};\n" 2953 " var a = {a:1};\n"
2954 " for (var i = 0; i < 10; i++) {\n" 2954 " for (var i = 0; i < 10; i++) {\n"
(...skipping 20 matching lines...) Expand all
2975 2975
2976 2976
2977 // Test of the stepping mechanism for named load in a loop. 2977 // Test of the stepping mechanism for named load in a loop.
2978 TEST(DebugStepNamedStoreLoop) { 2978 TEST(DebugStepNamedStoreLoop) {
2979 DoDebugStepNamedStoreLoop(23); 2979 DoDebugStepNamedStoreLoop(23);
2980 } 2980 }
2981 2981
2982 2982
2983 // Test the stepping mechanism with different ICs. 2983 // Test the stepping mechanism with different ICs.
2984 TEST(DebugStepLinearMixedICs) { 2984 TEST(DebugStepLinearMixedICs) {
2985 v8::HandleScope scope;
2986 DebugLocalContext env; 2985 DebugLocalContext env;
2986 v8::HandleScope scope(env->GetIsolate());
2987 2987
2988 // Register a debug event listener which steps and counts. 2988 // Register a debug event listener which steps and counts.
2989 v8::Debug::SetDebugEventListener(DebugEventStep); 2989 v8::Debug::SetDebugEventListener(DebugEventStep);
2990 2990
2991 // Create a function for testing stepping. 2991 // Create a function for testing stepping.
2992 v8::Local<v8::Function> foo = CompileFunction(&env, 2992 v8::Local<v8::Function> foo = CompileFunction(&env,
2993 "function bar() {};" 2993 "function bar() {};"
2994 "function foo() {" 2994 "function foo() {"
2995 " var x;" 2995 " var x;"
2996 " var index='name';" 2996 " var index='name';"
(...skipping 24 matching lines...) Expand all
3021 3021
3022 // Without stepping only active break points are hit. 3022 // Without stepping only active break points are hit.
3023 CHECK_EQ(1, break_point_hit_count); 3023 CHECK_EQ(1, break_point_hit_count);
3024 3024
3025 v8::Debug::SetDebugEventListener(NULL); 3025 v8::Debug::SetDebugEventListener(NULL);
3026 CheckDebuggerUnloaded(); 3026 CheckDebuggerUnloaded();
3027 } 3027 }
3028 3028
3029 3029
3030 TEST(DebugStepDeclarations) { 3030 TEST(DebugStepDeclarations) {
3031 v8::HandleScope scope;
3032 DebugLocalContext env; 3031 DebugLocalContext env;
3032 v8::HandleScope scope(env->GetIsolate());
3033 3033
3034 // Register a debug event listener which steps and counts. 3034 // Register a debug event listener which steps and counts.
3035 v8::Debug::SetDebugEventListener(DebugEventStep); 3035 v8::Debug::SetDebugEventListener(DebugEventStep);
3036 3036
3037 // Create a function for testing stepping. Run it to allow it to get 3037 // Create a function for testing stepping. Run it to allow it to get
3038 // optimized. 3038 // optimized.
3039 const char* src = "function foo() { " 3039 const char* src = "function foo() { "
3040 " var a;" 3040 " var a;"
3041 " var b = 1;" 3041 " var b = 1;"
3042 " var c = foo;" 3042 " var c = foo;"
(...skipping 11 matching lines...) Expand all
3054 foo->Call(env->Global(), 0, NULL); 3054 foo->Call(env->Global(), 0, NULL);
3055 CHECK_EQ(6, break_point_hit_count); 3055 CHECK_EQ(6, break_point_hit_count);
3056 3056
3057 // Get rid of the debug event listener. 3057 // Get rid of the debug event listener.
3058 v8::Debug::SetDebugEventListener(NULL); 3058 v8::Debug::SetDebugEventListener(NULL);
3059 CheckDebuggerUnloaded(); 3059 CheckDebuggerUnloaded();
3060 } 3060 }
3061 3061
3062 3062
3063 TEST(DebugStepLocals) { 3063 TEST(DebugStepLocals) {
3064 v8::HandleScope scope;
3065 DebugLocalContext env; 3064 DebugLocalContext env;
3065 v8::HandleScope scope(env->GetIsolate());
3066 3066
3067 // Register a debug event listener which steps and counts. 3067 // Register a debug event listener which steps and counts.
3068 v8::Debug::SetDebugEventListener(DebugEventStep); 3068 v8::Debug::SetDebugEventListener(DebugEventStep);
3069 3069
3070 // Create a function for testing stepping. Run it to allow it to get 3070 // Create a function for testing stepping. Run it to allow it to get
3071 // optimized. 3071 // optimized.
3072 const char* src = "function foo() { " 3072 const char* src = "function foo() { "
3073 " var a,b;" 3073 " var a,b;"
3074 " a = 1;" 3074 " a = 1;"
3075 " b = a + 2;" 3075 " b = a + 2;"
(...skipping 11 matching lines...) Expand all
3087 foo->Call(env->Global(), 0, NULL); 3087 foo->Call(env->Global(), 0, NULL);
3088 CHECK_EQ(6, break_point_hit_count); 3088 CHECK_EQ(6, break_point_hit_count);
3089 3089
3090 // Get rid of the debug event listener. 3090 // Get rid of the debug event listener.
3091 v8::Debug::SetDebugEventListener(NULL); 3091 v8::Debug::SetDebugEventListener(NULL);
3092 CheckDebuggerUnloaded(); 3092 CheckDebuggerUnloaded();
3093 } 3093 }
3094 3094
3095 3095
3096 TEST(DebugStepIf) { 3096 TEST(DebugStepIf) {
3097 v8::HandleScope scope;
3098 DebugLocalContext env; 3097 DebugLocalContext env;
3098 v8::HandleScope scope(env->GetIsolate());
3099 3099
3100 // Register a debug event listener which steps and counts. 3100 // Register a debug event listener which steps and counts.
3101 v8::Debug::SetDebugEventListener(DebugEventStep); 3101 v8::Debug::SetDebugEventListener(DebugEventStep);
3102 3102
3103 // Create a function for testing stepping. Run it to allow it to get 3103 // Create a function for testing stepping. Run it to allow it to get
3104 // optimized. 3104 // optimized.
3105 const int argc = 1; 3105 const int argc = 1;
3106 const char* src = "function foo(x) { " 3106 const char* src = "function foo(x) { "
3107 " a = 1;" 3107 " a = 1;"
3108 " if (x) {" 3108 " if (x) {"
(...skipping 21 matching lines...) Expand all
3130 foo->Call(env->Global(), argc, argv_false); 3130 foo->Call(env->Global(), argc, argv_false);
3131 CHECK_EQ(5, break_point_hit_count); 3131 CHECK_EQ(5, break_point_hit_count);
3132 3132
3133 // Get rid of the debug event listener. 3133 // Get rid of the debug event listener.
3134 v8::Debug::SetDebugEventListener(NULL); 3134 v8::Debug::SetDebugEventListener(NULL);
3135 CheckDebuggerUnloaded(); 3135 CheckDebuggerUnloaded();
3136 } 3136 }
3137 3137
3138 3138
3139 TEST(DebugStepSwitch) { 3139 TEST(DebugStepSwitch) {
3140 v8::HandleScope scope;
3141 DebugLocalContext env; 3140 DebugLocalContext env;
3141 v8::HandleScope scope(env->GetIsolate());
3142 3142
3143 // Register a debug event listener which steps and counts. 3143 // Register a debug event listener which steps and counts.
3144 v8::Debug::SetDebugEventListener(DebugEventStep); 3144 v8::Debug::SetDebugEventListener(DebugEventStep);
3145 3145
3146 // Create a function for testing stepping. Run it to allow it to get 3146 // Create a function for testing stepping. Run it to allow it to get
3147 // optimized. 3147 // optimized.
3148 const int argc = 1; 3148 const int argc = 1;
3149 const char* src = "function foo(x) { " 3149 const char* src = "function foo(x) { "
3150 " a = 1;" 3150 " a = 1;"
3151 " switch (x) {" 3151 " switch (x) {"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3186 foo->Call(env->Global(), argc, argv_3); 3186 foo->Call(env->Global(), argc, argv_3);
3187 CHECK_EQ(7, break_point_hit_count); 3187 CHECK_EQ(7, break_point_hit_count);
3188 3188
3189 // Get rid of the debug event listener. 3189 // Get rid of the debug event listener.
3190 v8::Debug::SetDebugEventListener(NULL); 3190 v8::Debug::SetDebugEventListener(NULL);
3191 CheckDebuggerUnloaded(); 3191 CheckDebuggerUnloaded();
3192 } 3192 }
3193 3193
3194 3194
3195 TEST(DebugStepWhile) { 3195 TEST(DebugStepWhile) {
3196 v8::HandleScope scope;
3197 DebugLocalContext env; 3196 DebugLocalContext env;
3197 v8::HandleScope scope(env->GetIsolate());
3198 3198
3199 // Register a debug event listener which steps and counts. 3199 // Register a debug event listener which steps and counts.
3200 v8::Debug::SetDebugEventListener(DebugEventStep); 3200 v8::Debug::SetDebugEventListener(DebugEventStep);
3201 3201
3202 // Create a function for testing stepping. Run it to allow it to get 3202 // Create a function for testing stepping. Run it to allow it to get
3203 // optimized. 3203 // optimized.
3204 const int argc = 1; 3204 const int argc = 1;
3205 const char* src = "function foo(x) { " 3205 const char* src = "function foo(x) { "
3206 " var a = 0;" 3206 " var a = 0;"
3207 " while (a < x) {" 3207 " while (a < x) {"
(...skipping 18 matching lines...) Expand all
3226 foo->Call(env->Global(), argc, argv_100); 3226 foo->Call(env->Global(), argc, argv_100);
3227 CHECK_EQ(202, break_point_hit_count); 3227 CHECK_EQ(202, break_point_hit_count);
3228 3228
3229 // Get rid of the debug event listener. 3229 // Get rid of the debug event listener.
3230 v8::Debug::SetDebugEventListener(NULL); 3230 v8::Debug::SetDebugEventListener(NULL);
3231 CheckDebuggerUnloaded(); 3231 CheckDebuggerUnloaded();
3232 } 3232 }
3233 3233
3234 3234
3235 TEST(DebugStepDoWhile) { 3235 TEST(DebugStepDoWhile) {
3236 v8::HandleScope scope;
3237 DebugLocalContext env; 3236 DebugLocalContext env;
3237 v8::HandleScope scope(env->GetIsolate());
3238 3238
3239 // Register a debug event listener which steps and counts. 3239 // Register a debug event listener which steps and counts.
3240 v8::Debug::SetDebugEventListener(DebugEventStep); 3240 v8::Debug::SetDebugEventListener(DebugEventStep);
3241 3241
3242 // Create a function for testing stepping. Run it to allow it to get 3242 // Create a function for testing stepping. Run it to allow it to get
3243 // optimized. 3243 // optimized.
3244 const int argc = 1; 3244 const int argc = 1;
3245 const char* src = "function foo(x) { " 3245 const char* src = "function foo(x) { "
3246 " var a = 0;" 3246 " var a = 0;"
3247 " do {" 3247 " do {"
(...skipping 18 matching lines...) Expand all
3266 foo->Call(env->Global(), argc, argv_100); 3266 foo->Call(env->Global(), argc, argv_100);
3267 CHECK_EQ(202, break_point_hit_count); 3267 CHECK_EQ(202, break_point_hit_count);
3268 3268
3269 // Get rid of the debug event listener. 3269 // Get rid of the debug event listener.
3270 v8::Debug::SetDebugEventListener(NULL); 3270 v8::Debug::SetDebugEventListener(NULL);
3271 CheckDebuggerUnloaded(); 3271 CheckDebuggerUnloaded();
3272 } 3272 }
3273 3273
3274 3274
3275 TEST(DebugStepFor) { 3275 TEST(DebugStepFor) {
3276 v8::HandleScope scope;
3277 DebugLocalContext env; 3276 DebugLocalContext env;
3277 v8::HandleScope scope(env->GetIsolate());
3278 3278
3279 // Register a debug event listener which steps and counts. 3279 // Register a debug event listener which steps and counts.
3280 v8::Debug::SetDebugEventListener(DebugEventStep); 3280 v8::Debug::SetDebugEventListener(DebugEventStep);
3281 3281
3282 // Create a function for testing stepping. Run it to allow it to get 3282 // Create a function for testing stepping. Run it to allow it to get
3283 // optimized. 3283 // optimized.
3284 const int argc = 1; 3284 const int argc = 1;
3285 const char* src = "function foo(x) { " 3285 const char* src = "function foo(x) { "
3286 " a = 1;" 3286 " a = 1;"
3287 " for (i = 0; i < x; i++) {" 3287 " for (i = 0; i < x; i++) {"
(...skipping 19 matching lines...) Expand all
3307 foo->Call(env->Global(), argc, argv_100); 3307 foo->Call(env->Global(), argc, argv_100);
3308 CHECK_EQ(203, break_point_hit_count); 3308 CHECK_EQ(203, break_point_hit_count);
3309 3309
3310 // Get rid of the debug event listener. 3310 // Get rid of the debug event listener.
3311 v8::Debug::SetDebugEventListener(NULL); 3311 v8::Debug::SetDebugEventListener(NULL);
3312 CheckDebuggerUnloaded(); 3312 CheckDebuggerUnloaded();
3313 } 3313 }
3314 3314
3315 3315
3316 TEST(DebugStepForContinue) { 3316 TEST(DebugStepForContinue) {
3317 v8::HandleScope scope;
3318 DebugLocalContext env; 3317 DebugLocalContext env;
3318 v8::HandleScope scope(env->GetIsolate());
3319 3319
3320 // Register a debug event listener which steps and counts. 3320 // Register a debug event listener which steps and counts.
3321 v8::Debug::SetDebugEventListener(DebugEventStep); 3321 v8::Debug::SetDebugEventListener(DebugEventStep);
3322 3322
3323 // Create a function for testing stepping. Run it to allow it to get 3323 // Create a function for testing stepping. Run it to allow it to get
3324 // optimized. 3324 // optimized.
3325 const int argc = 1; 3325 const int argc = 1;
3326 const char* src = "function foo(x) { " 3326 const char* src = "function foo(x) { "
3327 " var a = 0;" 3327 " var a = 0;"
3328 " var b = 0;" 3328 " var b = 0;"
(...skipping 29 matching lines...) Expand all
3358 CHECK_EQ(50, result->Int32Value()); 3358 CHECK_EQ(50, result->Int32Value());
3359 CHECK_EQ(456, break_point_hit_count); 3359 CHECK_EQ(456, break_point_hit_count);
3360 3360
3361 // Get rid of the debug event listener. 3361 // Get rid of the debug event listener.
3362 v8::Debug::SetDebugEventListener(NULL); 3362 v8::Debug::SetDebugEventListener(NULL);
3363 CheckDebuggerUnloaded(); 3363 CheckDebuggerUnloaded();
3364 } 3364 }
3365 3365
3366 3366
3367 TEST(DebugStepForBreak) { 3367 TEST(DebugStepForBreak) {
3368 v8::HandleScope scope;
3369 DebugLocalContext env; 3368 DebugLocalContext env;
3369 v8::HandleScope scope(env->GetIsolate());
3370 3370
3371 // Register a debug event listener which steps and counts. 3371 // Register a debug event listener which steps and counts.
3372 v8::Debug::SetDebugEventListener(DebugEventStep); 3372 v8::Debug::SetDebugEventListener(DebugEventStep);
3373 3373
3374 // Create a function for testing stepping. Run it to allow it to get 3374 // Create a function for testing stepping. Run it to allow it to get
3375 // optimized. 3375 // optimized.
3376 const int argc = 1; 3376 const int argc = 1;
3377 const char* src = "function foo(x) { " 3377 const char* src = "function foo(x) { "
3378 " var a = 0;" 3378 " var a = 0;"
3379 " var b = 0;" 3379 " var b = 0;"
(...skipping 30 matching lines...) Expand all
3410 CHECK_EQ(99, result->Int32Value()); 3410 CHECK_EQ(99, result->Int32Value());
3411 CHECK_EQ(504, break_point_hit_count); 3411 CHECK_EQ(504, break_point_hit_count);
3412 3412
3413 // Get rid of the debug event listener. 3413 // Get rid of the debug event listener.
3414 v8::Debug::SetDebugEventListener(NULL); 3414 v8::Debug::SetDebugEventListener(NULL);
3415 CheckDebuggerUnloaded(); 3415 CheckDebuggerUnloaded();
3416 } 3416 }
3417 3417
3418 3418
3419 TEST(DebugStepForIn) { 3419 TEST(DebugStepForIn) {
3420 v8::HandleScope scope;
3421 DebugLocalContext env; 3420 DebugLocalContext env;
3421 v8::HandleScope scope(env->GetIsolate());
3422 3422
3423 // Register a debug event listener which steps and counts. 3423 // Register a debug event listener which steps and counts.
3424 v8::Debug::SetDebugEventListener(DebugEventStep); 3424 v8::Debug::SetDebugEventListener(DebugEventStep);
3425 3425
3426 // Create a function for testing stepping. Run it to allow it to get 3426 // Create a function for testing stepping. Run it to allow it to get
3427 // optimized. 3427 // optimized.
3428 v8::Local<v8::Function> foo; 3428 v8::Local<v8::Function> foo;
3429 const char* src_1 = "function foo() { " 3429 const char* src_1 = "function foo() { "
3430 " var a = [1, 2];" 3430 " var a = [1, 2];"
3431 " for (x in a) {" 3431 " for (x in a) {"
(...skipping 26 matching lines...) Expand all
3458 foo->Call(env->Global(), 0, NULL); 3458 foo->Call(env->Global(), 0, NULL);
3459 CHECK_EQ(8, break_point_hit_count); 3459 CHECK_EQ(8, break_point_hit_count);
3460 3460
3461 // Get rid of the debug event listener. 3461 // Get rid of the debug event listener.
3462 v8::Debug::SetDebugEventListener(NULL); 3462 v8::Debug::SetDebugEventListener(NULL);
3463 CheckDebuggerUnloaded(); 3463 CheckDebuggerUnloaded();
3464 } 3464 }
3465 3465
3466 3466
3467 TEST(DebugStepWith) { 3467 TEST(DebugStepWith) {
3468 v8::HandleScope scope;
3469 DebugLocalContext env; 3468 DebugLocalContext env;
3469 v8::HandleScope scope(env->GetIsolate());
3470 3470
3471 // Register a debug event listener which steps and counts. 3471 // Register a debug event listener which steps and counts.
3472 v8::Debug::SetDebugEventListener(DebugEventStep); 3472 v8::Debug::SetDebugEventListener(DebugEventStep);
3473 3473
3474 // Create a function for testing stepping. Run it to allow it to get 3474 // Create a function for testing stepping. Run it to allow it to get
3475 // optimized. 3475 // optimized.
3476 const char* src = "function foo(x) { " 3476 const char* src = "function foo(x) { "
3477 " var a = {};" 3477 " var a = {};"
3478 " with (a) {}" 3478 " with (a) {}"
3479 " with (b) {}" 3479 " with (b) {}"
3480 "}" 3480 "}"
3481 "foo()"; 3481 "foo()";
3482 env->Global()->Set(v8::String::New("b"), v8::Object::New()); 3482 env->Global()->Set(v8::String::New("b"), v8::Object::New());
3483 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); 3483 v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
3484 v8::Handle<v8::Value> result; 3484 v8::Handle<v8::Value> result;
3485 SetBreakPoint(foo, 8); // "var a = {};" 3485 SetBreakPoint(foo, 8); // "var a = {};"
3486 3486
3487 step_action = StepIn; 3487 step_action = StepIn;
3488 break_point_hit_count = 0; 3488 break_point_hit_count = 0;
3489 foo->Call(env->Global(), 0, NULL); 3489 foo->Call(env->Global(), 0, NULL);
3490 CHECK_EQ(4, break_point_hit_count); 3490 CHECK_EQ(4, break_point_hit_count);
3491 3491
3492 // Get rid of the debug event listener. 3492 // Get rid of the debug event listener.
3493 v8::Debug::SetDebugEventListener(NULL); 3493 v8::Debug::SetDebugEventListener(NULL);
3494 CheckDebuggerUnloaded(); 3494 CheckDebuggerUnloaded();
3495 } 3495 }
3496 3496
3497 3497
3498 TEST(DebugConditional) { 3498 TEST(DebugConditional) {
3499 v8::HandleScope scope;
3500 DebugLocalContext env; 3499 DebugLocalContext env;
3500 v8::HandleScope scope(env->GetIsolate());
3501 3501
3502 // Register a debug event listener which steps and counts. 3502 // Register a debug event listener which steps and counts.
3503 v8::Debug::SetDebugEventListener(DebugEventStep); 3503 v8::Debug::SetDebugEventListener(DebugEventStep);
3504 3504
3505 // Create a function for testing stepping. Run it to allow it to get 3505 // Create a function for testing stepping. Run it to allow it to get
3506 // optimized. 3506 // optimized.
3507 const char* src = "function foo(x) { " 3507 const char* src = "function foo(x) { "
3508 " var a;" 3508 " var a;"
3509 " a = x ? 1 : 2;" 3509 " a = x ? 1 : 2;"
3510 " return a;" 3510 " return a;"
(...skipping 14 matching lines...) Expand all
3525 foo->Call(env->Global(), argc, argv_true); 3525 foo->Call(env->Global(), argc, argv_true);
3526 CHECK_EQ(5, break_point_hit_count); 3526 CHECK_EQ(5, break_point_hit_count);
3527 3527
3528 // Get rid of the debug event listener. 3528 // Get rid of the debug event listener.
3529 v8::Debug::SetDebugEventListener(NULL); 3529 v8::Debug::SetDebugEventListener(NULL);
3530 CheckDebuggerUnloaded(); 3530 CheckDebuggerUnloaded();
3531 } 3531 }
3532 3532
3533 3533
3534 TEST(StepInOutSimple) { 3534 TEST(StepInOutSimple) {
3535 v8::HandleScope scope;
3536 DebugLocalContext env; 3535 DebugLocalContext env;
3536 v8::HandleScope scope(env->GetIsolate());
3537 3537
3538 // Create a function for checking the function when hitting a break point. 3538 // Create a function for checking the function when hitting a break point.
3539 frame_function_name = CompileFunction(&env, 3539 frame_function_name = CompileFunction(&env,
3540 frame_function_name_source, 3540 frame_function_name_source,
3541 "frame_function_name"); 3541 "frame_function_name");
3542 3542
3543 // Register a debug event listener which steps and counts. 3543 // Register a debug event listener which steps and counts.
3544 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3544 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3545 3545
3546 // Create a function for testing stepping. Run it to allow it to get 3546 // Create a function for testing stepping. Run it to allow it to get
(...skipping 29 matching lines...) Expand all
3576 CHECK_EQ(StrLength(expected_step_sequence), 3576 CHECK_EQ(StrLength(expected_step_sequence),
3577 break_point_hit_count); 3577 break_point_hit_count);
3578 3578
3579 // Get rid of the debug event listener. 3579 // Get rid of the debug event listener.
3580 v8::Debug::SetDebugEventListener(NULL); 3580 v8::Debug::SetDebugEventListener(NULL);
3581 CheckDebuggerUnloaded(); 3581 CheckDebuggerUnloaded();
3582 } 3582 }
3583 3583
3584 3584
3585 TEST(StepInOutTree) { 3585 TEST(StepInOutTree) {
3586 v8::HandleScope scope;
3587 DebugLocalContext env; 3586 DebugLocalContext env;
3587 v8::HandleScope scope(env->GetIsolate());
3588 3588
3589 // Create a function for checking the function when hitting a break point. 3589 // Create a function for checking the function when hitting a break point.
3590 frame_function_name = CompileFunction(&env, 3590 frame_function_name = CompileFunction(&env,
3591 frame_function_name_source, 3591 frame_function_name_source,
3592 "frame_function_name"); 3592 "frame_function_name");
3593 3593
3594 // Register a debug event listener which steps and counts. 3594 // Register a debug event listener which steps and counts.
3595 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3595 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3596 3596
3597 // Create a function for testing stepping. Run it to allow it to get 3597 // Create a function for testing stepping. Run it to allow it to get
(...skipping 30 matching lines...) Expand all
3628 CHECK_EQ(StrLength(expected_step_sequence), 3628 CHECK_EQ(StrLength(expected_step_sequence),
3629 break_point_hit_count); 3629 break_point_hit_count);
3630 3630
3631 // Get rid of the debug event listener. 3631 // Get rid of the debug event listener.
3632 v8::Debug::SetDebugEventListener(NULL); 3632 v8::Debug::SetDebugEventListener(NULL);
3633 CheckDebuggerUnloaded(true); 3633 CheckDebuggerUnloaded(true);
3634 } 3634 }
3635 3635
3636 3636
3637 TEST(StepInOutBranch) { 3637 TEST(StepInOutBranch) {
3638 v8::HandleScope scope;
3639 DebugLocalContext env; 3638 DebugLocalContext env;
3639 v8::HandleScope scope(env->GetIsolate());
3640 3640
3641 // Create a function for checking the function when hitting a break point. 3641 // Create a function for checking the function when hitting a break point.
3642 frame_function_name = CompileFunction(&env, 3642 frame_function_name = CompileFunction(&env,
3643 frame_function_name_source, 3643 frame_function_name_source,
3644 "frame_function_name"); 3644 "frame_function_name");
3645 3645
3646 // Register a debug event listener which steps and counts. 3646 // Register a debug event listener which steps and counts.
3647 v8::Debug::SetDebugEventListener(DebugEventStepSequence); 3647 v8::Debug::SetDebugEventListener(DebugEventStepSequence);
3648 3648
3649 // Create a function for testing stepping. Run it to allow it to get 3649 // Create a function for testing stepping. Run it to allow it to get
(...skipping 14 matching lines...) Expand all
3664 break_point_hit_count); 3664 break_point_hit_count);
3665 3665
3666 // Get rid of the debug event listener. 3666 // Get rid of the debug event listener.
3667 v8::Debug::SetDebugEventListener(NULL); 3667 v8::Debug::SetDebugEventListener(NULL);
3668 CheckDebuggerUnloaded(); 3668 CheckDebuggerUnloaded();
3669 } 3669 }
3670 3670
3671 3671
3672 // Test that step in does not step into native functions. 3672 // Test that step in does not step into native functions.
3673 TEST(DebugStepNatives) { 3673 TEST(DebugStepNatives) {
3674 v8::HandleScope scope;
3675 DebugLocalContext env; 3674 DebugLocalContext env;
3675 v8::HandleScope scope(env->GetIsolate());
3676 3676
3677 // Create a function for testing stepping. 3677 // Create a function for testing stepping.
3678 v8::Local<v8::Function> foo = CompileFunction( 3678 v8::Local<v8::Function> foo = CompileFunction(
3679 &env, 3679 &env,
3680 "function foo(){debugger;Math.sin(1);}", 3680 "function foo(){debugger;Math.sin(1);}",
3681 "foo"); 3681 "foo");
3682 3682
3683 // Register a debug event listener which steps and counts. 3683 // Register a debug event listener which steps and counts.
3684 v8::Debug::SetDebugEventListener(DebugEventStep); 3684 v8::Debug::SetDebugEventListener(DebugEventStep);
3685 3685
(...skipping 16 matching lines...) Expand all
3702 // Without stepping only active break points are hit. 3702 // Without stepping only active break points are hit.
3703 CHECK_EQ(1, break_point_hit_count); 3703 CHECK_EQ(1, break_point_hit_count);
3704 3704
3705 v8::Debug::SetDebugEventListener(NULL); 3705 v8::Debug::SetDebugEventListener(NULL);
3706 CheckDebuggerUnloaded(); 3706 CheckDebuggerUnloaded();
3707 } 3707 }
3708 3708
3709 3709
3710 // Test that step in works with function.apply. 3710 // Test that step in works with function.apply.
3711 TEST(DebugStepFunctionApply) { 3711 TEST(DebugStepFunctionApply) {
3712 v8::HandleScope scope;
3713 DebugLocalContext env; 3712 DebugLocalContext env;
3713 v8::HandleScope scope(env->GetIsolate());
3714 3714
3715 // Create a function for testing stepping. 3715 // Create a function for testing stepping.
3716 v8::Local<v8::Function> foo = CompileFunction( 3716 v8::Local<v8::Function> foo = CompileFunction(
3717 &env, 3717 &env,
3718 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" 3718 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3719 "function foo(){ debugger; bar.apply(this, [1,2,3]); }", 3719 "function foo(){ debugger; bar.apply(this, [1,2,3]); }",
3720 "foo"); 3720 "foo");
3721 3721
3722 // Register a debug event listener which steps and counts. 3722 // Register a debug event listener which steps and counts.
3723 v8::Debug::SetDebugEventListener(DebugEventStep); 3723 v8::Debug::SetDebugEventListener(DebugEventStep);
(...skipping 17 matching lines...) Expand all
3741 // Without stepping only the debugger statement is hit. 3741 // Without stepping only the debugger statement is hit.
3742 CHECK_EQ(1, break_point_hit_count); 3742 CHECK_EQ(1, break_point_hit_count);
3743 3743
3744 v8::Debug::SetDebugEventListener(NULL); 3744 v8::Debug::SetDebugEventListener(NULL);
3745 CheckDebuggerUnloaded(); 3745 CheckDebuggerUnloaded();
3746 } 3746 }
3747 3747
3748 3748
3749 // Test that step in works with function.call. 3749 // Test that step in works with function.call.
3750 TEST(DebugStepFunctionCall) { 3750 TEST(DebugStepFunctionCall) {
3751 v8::HandleScope scope;
3752 DebugLocalContext env; 3751 DebugLocalContext env;
3752 v8::HandleScope scope(env->GetIsolate());
3753 3753
3754 // Create a function for testing stepping. 3754 // Create a function for testing stepping.
3755 v8::Local<v8::Function> foo = CompileFunction( 3755 v8::Local<v8::Function> foo = CompileFunction(
3756 &env, 3756 &env,
3757 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }" 3757 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3758 "function foo(a){ debugger;" 3758 "function foo(a){ debugger;"
3759 " if (a) {" 3759 " if (a) {"
3760 " bar.call(this, 1, 2, 3);" 3760 " bar.call(this, 1, 2, 3);"
3761 " } else {" 3761 " } else {"
3762 " bar.call(this, 0);" 3762 " bar.call(this, 0);"
(...skipping 29 matching lines...) Expand all
3792 // Without stepping only the debugger statement is hit. 3792 // Without stepping only the debugger statement is hit.
3793 CHECK_EQ(1, break_point_hit_count); 3793 CHECK_EQ(1, break_point_hit_count);
3794 3794
3795 v8::Debug::SetDebugEventListener(NULL); 3795 v8::Debug::SetDebugEventListener(NULL);
3796 CheckDebuggerUnloaded(); 3796 CheckDebuggerUnloaded();
3797 } 3797 }
3798 3798
3799 3799
3800 // Tests that breakpoint will be hit if it's set in script. 3800 // Tests that breakpoint will be hit if it's set in script.
3801 TEST(PauseInScript) { 3801 TEST(PauseInScript) {
3802 v8::HandleScope scope;
3803 DebugLocalContext env; 3802 DebugLocalContext env;
3803 v8::HandleScope scope(env->GetIsolate());
3804 env.ExposeDebug(); 3804 env.ExposeDebug();
3805 3805
3806 // Register a debug event listener which counts. 3806 // Register a debug event listener which counts.
3807 v8::Debug::SetDebugEventListener(DebugEventCounter); 3807 v8::Debug::SetDebugEventListener(DebugEventCounter);
3808 3808
3809 // Create a script that returns a function. 3809 // Create a script that returns a function.
3810 const char* src = "(function (evt) {})"; 3810 const char* src = "(function (evt) {})";
3811 const char* script_name = "StepInHandlerTest"; 3811 const char* script_name = "StepInHandlerTest";
3812 3812
3813 // Set breakpoint in the script. 3813 // Set breakpoint in the script.
(...skipping 14 matching lines...) Expand all
3828 } 3828 }
3829 3829
3830 3830
3831 // Test break on exceptions. For each exception break combination the number 3831 // Test break on exceptions. For each exception break combination the number
3832 // of debug event exception callbacks and message callbacks are collected. The 3832 // of debug event exception callbacks and message callbacks are collected. The
3833 // number of debug event exception callbacks are used to check that the 3833 // number of debug event exception callbacks are used to check that the
3834 // debugger is called correctly and the number of message callbacks is used to 3834 // debugger is called correctly and the number of message callbacks is used to
3835 // check that uncaught exceptions are still returned even if there is a break 3835 // check that uncaught exceptions are still returned even if there is a break
3836 // for them. 3836 // for them.
3837 TEST(BreakOnException) { 3837 TEST(BreakOnException) {
3838 v8::HandleScope scope;
3839 DebugLocalContext env; 3838 DebugLocalContext env;
3839 v8::HandleScope scope(env->GetIsolate());
3840 env.ExposeDebug(); 3840 env.ExposeDebug();
3841 3841
3842 v8::internal::Isolate::Current()->TraceException(false); 3842 v8::internal::Isolate::Current()->TraceException(false);
3843 3843
3844 // Create functions for testing break on exception. 3844 // Create functions for testing break on exception.
3845 CompileFunction(&env, "function throws(){throw 1;}", "throws"); 3845 CompileFunction(&env, "function throws(){throw 1;}", "throws");
3846 v8::Local<v8::Function> caught = 3846 v8::Local<v8::Function> caught =
3847 CompileFunction(&env, 3847 CompileFunction(&env,
3848 "function caught(){try {throws();} catch(e) {};}", 3848 "function caught(){try {throws();} catch(e) {};}",
3849 "caught"); 3849 "caught");
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3972 v8::Debug::SetDebugEventListener(NULL); 3972 v8::Debug::SetDebugEventListener(NULL);
3973 CheckDebuggerUnloaded(); 3973 CheckDebuggerUnloaded();
3974 v8::V8::RemoveMessageListeners(MessageCallbackCount); 3974 v8::V8::RemoveMessageListeners(MessageCallbackCount);
3975 } 3975 }
3976 3976
3977 3977
3978 // Test break on exception from compiler errors. When compiling using 3978 // Test break on exception from compiler errors. When compiling using
3979 // v8::Script::Compile there is no JavaScript stack whereas when compiling using 3979 // v8::Script::Compile there is no JavaScript stack whereas when compiling using
3980 // eval there are JavaScript frames. 3980 // eval there are JavaScript frames.
3981 TEST(BreakOnCompileException) { 3981 TEST(BreakOnCompileException) {
3982 v8::HandleScope scope;
3983 DebugLocalContext env; 3982 DebugLocalContext env;
3983 v8::HandleScope scope(env->GetIsolate());
3984 3984
3985 // For this test, we want to break on uncaught exceptions: 3985 // For this test, we want to break on uncaught exceptions:
3986 ChangeBreakOnException(false, true); 3986 ChangeBreakOnException(false, true);
3987 3987
3988 v8::internal::Isolate::Current()->TraceException(false); 3988 v8::internal::Isolate::Current()->TraceException(false);
3989 3989
3990 // Create a function for checking the function when hitting a break point. 3990 // Create a function for checking the function when hitting a break point.
3991 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); 3991 frame_count = CompileFunction(&env, frame_count_source, "frame_count");
3992 3992
3993 v8::V8::AddMessageListener(MessageCallbackCount); 3993 v8::V8::AddMessageListener(MessageCallbackCount);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 // Throws SyntaxError: Unexpected identifier 4026 // Throws SyntaxError: Unexpected identifier
4027 v8::Script::Compile(v8::String::New("eval('x x')"))->Run(); 4027 v8::Script::Compile(v8::String::New("eval('x x')"))->Run();
4028 CHECK_EQ(4, exception_hit_count); 4028 CHECK_EQ(4, exception_hit_count);
4029 CHECK_EQ(4, uncaught_exception_hit_count); 4029 CHECK_EQ(4, uncaught_exception_hit_count);
4030 CHECK_EQ(4, message_callback_count); 4030 CHECK_EQ(4, message_callback_count);
4031 CHECK_EQ(1, last_js_stack_height); 4031 CHECK_EQ(1, last_js_stack_height);
4032 } 4032 }
4033 4033
4034 4034
4035 TEST(StepWithException) { 4035 TEST(StepWithException) {
4036 v8::HandleScope scope;
4037 DebugLocalContext env; 4036 DebugLocalContext env;
4037 v8::HandleScope scope(env->GetIsolate());
4038 4038
4039 // For this test, we want to break on uncaught exceptions: 4039 // For this test, we want to break on uncaught exceptions:
4040 ChangeBreakOnException(false, true); 4040 ChangeBreakOnException(false, true);
4041 4041
4042 // Create a function for checking the function when hitting a break point. 4042 // Create a function for checking the function when hitting a break point.
4043 frame_function_name = CompileFunction(&env, 4043 frame_function_name = CompileFunction(&env,
4044 frame_function_name_source, 4044 frame_function_name_source,
4045 "frame_function_name"); 4045 "frame_function_name");
4046 4046
4047 // Register a debug event listener which steps and counts. 4047 // Register a debug event listener which steps and counts.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
4119 // Get rid of the debug event listener. 4119 // Get rid of the debug event listener.
4120 v8::Debug::SetDebugEventListener(NULL); 4120 v8::Debug::SetDebugEventListener(NULL);
4121 CheckDebuggerUnloaded(); 4121 CheckDebuggerUnloaded();
4122 } 4122 }
4123 4123
4124 4124
4125 TEST(DebugBreak) { 4125 TEST(DebugBreak) {
4126 #ifdef VERIFY_HEAP 4126 #ifdef VERIFY_HEAP
4127 i::FLAG_verify_heap = true; 4127 i::FLAG_verify_heap = true;
4128 #endif 4128 #endif
4129 v8::HandleScope scope;
4130 DebugLocalContext env; 4129 DebugLocalContext env;
4130 v8::HandleScope scope(env->GetIsolate());
4131 4131
4132 // Register a debug event listener which sets the break flag and counts. 4132 // Register a debug event listener which sets the break flag and counts.
4133 v8::Debug::SetDebugEventListener(DebugEventBreak); 4133 v8::Debug::SetDebugEventListener(DebugEventBreak);
4134 4134
4135 // Create a function for testing stepping. 4135 // Create a function for testing stepping.
4136 const char* src = "function f0() {}" 4136 const char* src = "function f0() {}"
4137 "function f1(x1) {}" 4137 "function f1(x1) {}"
4138 "function f2(x1,x2) {}" 4138 "function f2(x1,x2) {}"
4139 "function f3(x1,x2,x3) {}"; 4139 "function f3(x1,x2,x3) {}";
4140 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); 4140 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0");
(...skipping 30 matching lines...) Expand all
4171 4171
4172 // Get rid of the debug event listener. 4172 // Get rid of the debug event listener.
4173 v8::Debug::SetDebugEventListener(NULL); 4173 v8::Debug::SetDebugEventListener(NULL);
4174 CheckDebuggerUnloaded(); 4174 CheckDebuggerUnloaded();
4175 } 4175 }
4176 4176
4177 4177
4178 // Test to ensure that JavaScript code keeps running while the debug break 4178 // Test to ensure that JavaScript code keeps running while the debug break
4179 // through the stack limit flag is set but breaks are disabled. 4179 // through the stack limit flag is set but breaks are disabled.
4180 TEST(DisableBreak) { 4180 TEST(DisableBreak) {
4181 v8::HandleScope scope;
4182 DebugLocalContext env; 4181 DebugLocalContext env;
4182 v8::HandleScope scope(env->GetIsolate());
4183 4183
4184 // Register a debug event listener which sets the break flag and counts. 4184 // Register a debug event listener which sets the break flag and counts.
4185 v8::Debug::SetDebugEventListener(DebugEventCounter); 4185 v8::Debug::SetDebugEventListener(DebugEventCounter);
4186 4186
4187 // Create a function for testing stepping. 4187 // Create a function for testing stepping.
4188 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; 4188 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
4189 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 4189 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4190 4190
4191 // Set the debug break flag. 4191 // Set the debug break flag.
4192 v8::Debug::DebugBreak(); 4192 v8::Debug::DebugBreak();
(...skipping 19 matching lines...) Expand all
4212 } 4212 }
4213 4213
4214 static const char* kSimpleExtensionSource = 4214 static const char* kSimpleExtensionSource =
4215 "(function Foo() {" 4215 "(function Foo() {"
4216 " return 4;" 4216 " return 4;"
4217 "})() "; 4217 "})() ";
4218 4218
4219 // http://crbug.com/28933 4219 // http://crbug.com/28933
4220 // Test that debug break is disabled when bootstrapper is active. 4220 // Test that debug break is disabled when bootstrapper is active.
4221 TEST(NoBreakWhenBootstrapping) { 4221 TEST(NoBreakWhenBootstrapping) {
4222 v8::HandleScope scope; 4222 v8::HandleScope scope(v8::Isolate::GetCurrent());
4223 4223
4224 // Register a debug event listener which sets the break flag and counts. 4224 // Register a debug event listener which sets the break flag and counts.
4225 v8::Debug::SetDebugEventListener(DebugEventCounter); 4225 v8::Debug::SetDebugEventListener(DebugEventCounter);
4226 4226
4227 // Set the debug break flag. 4227 // Set the debug break flag.
4228 v8::Debug::DebugBreak(); 4228 v8::Debug::DebugBreak();
4229 break_point_hit_count = 0; 4229 break_point_hit_count = 0;
4230 { 4230 {
4231 // Create a context with an extension to make sure that some JavaScript 4231 // Create a context with an extension to make sure that some JavaScript
4232 // code is executed during bootstrapping. 4232 // code is executed during bootstrapping.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4280 4280
4281 4281
4282 static v8::Handle<v8::Value> IndexedGetter(uint32_t index, 4282 static v8::Handle<v8::Value> IndexedGetter(uint32_t index,
4283 const v8::AccessorInfo& info) { 4283 const v8::AccessorInfo& info) {
4284 return v8::Number::New(index + 1); 4284 return v8::Number::New(index + 1);
4285 } 4285 }
4286 4286
4287 4287
4288 TEST(InterceptorPropertyMirror) { 4288 TEST(InterceptorPropertyMirror) {
4289 // Create a V8 environment with debug access. 4289 // Create a V8 environment with debug access.
4290 v8::HandleScope scope;
4291 DebugLocalContext env; 4290 DebugLocalContext env;
4291 v8::HandleScope scope(env->GetIsolate());
4292 env.ExposeDebug(); 4292 env.ExposeDebug();
4293 4293
4294 // Create object with named interceptor. 4294 // Create object with named interceptor.
4295 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); 4295 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4296 named->SetNamedPropertyHandler(NamedGetter, NULL, NULL, NULL, NamedEnum); 4296 named->SetNamedPropertyHandler(NamedGetter, NULL, NULL, NULL, NamedEnum);
4297 env->Global()->Set(v8::String::New("intercepted_named"), 4297 env->Global()->Set(v8::String::New("intercepted_named"),
4298 named->NewInstance()); 4298 named->NewInstance());
4299 4299
4300 // Create object with indexed interceptor. 4300 // Create object with indexed interceptor.
4301 v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New(); 4301 v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 source = "both_values[3].name() == 1"; 4411 source = "both_values[3].name() == 1";
4412 CHECK(CompileRun(source)->BooleanValue()); 4412 CHECK(CompileRun(source)->BooleanValue());
4413 4413
4414 source = "both_values[4].name() == 10"; 4414 source = "both_values[4].name() == 10";
4415 CHECK(CompileRun(source)->BooleanValue()); 4415 CHECK(CompileRun(source)->BooleanValue());
4416 } 4416 }
4417 4417
4418 4418
4419 TEST(HiddenPrototypePropertyMirror) { 4419 TEST(HiddenPrototypePropertyMirror) {
4420 // Create a V8 environment with debug access. 4420 // Create a V8 environment with debug access.
4421 v8::HandleScope scope;
4422 DebugLocalContext env; 4421 DebugLocalContext env;
4422 v8::HandleScope scope(env->GetIsolate());
4423 env.ExposeDebug(); 4423 env.ExposeDebug();
4424 4424
4425 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 4425 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
4426 t0->InstanceTemplate()->Set(v8::String::New("x"), v8::Number::New(0)); 4426 t0->InstanceTemplate()->Set(v8::String::New("x"), v8::Number::New(0));
4427 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 4427 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
4428 t1->SetHiddenPrototype(true); 4428 t1->SetHiddenPrototype(true);
4429 t1->InstanceTemplate()->Set(v8::String::New("y"), v8::Number::New(1)); 4429 t1->InstanceTemplate()->Set(v8::String::New("y"), v8::Number::New(1));
4430 v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 4430 v8::Handle<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
4431 t2->SetHiddenPrototype(true); 4431 t2->SetHiddenPrototype(true);
4432 t2->InstanceTemplate()->Set(v8::String::New("z"), v8::Number::New(2)); 4432 t2->InstanceTemplate()->Set(v8::String::New("z"), v8::Number::New(2));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4512 4512
4513 4513
4514 static v8::Handle<v8::Value> ProtperyXNativeGetter( 4514 static v8::Handle<v8::Value> ProtperyXNativeGetter(
4515 v8::Local<v8::String> property, const v8::AccessorInfo& info) { 4515 v8::Local<v8::String> property, const v8::AccessorInfo& info) {
4516 return v8::Integer::New(10); 4516 return v8::Integer::New(10);
4517 } 4517 }
4518 4518
4519 4519
4520 TEST(NativeGetterPropertyMirror) { 4520 TEST(NativeGetterPropertyMirror) {
4521 // Create a V8 environment with debug access. 4521 // Create a V8 environment with debug access.
4522 v8::HandleScope scope;
4523 DebugLocalContext env; 4522 DebugLocalContext env;
4523 v8::HandleScope scope(env->GetIsolate());
4524 env.ExposeDebug(); 4524 env.ExposeDebug();
4525 4525
4526 v8::Handle<v8::String> name = v8::String::New("x"); 4526 v8::Handle<v8::String> name = v8::String::New("x");
4527 // Create object with named accessor. 4527 // Create object with named accessor.
4528 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); 4528 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4529 named->SetAccessor(name, &ProtperyXNativeGetter, NULL, 4529 named->SetAccessor(name, &ProtperyXNativeGetter, NULL,
4530 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None); 4530 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
4531 4531
4532 // Create object with named property getter. 4532 // Create object with named property getter.
4533 env->Global()->Set(v8::String::New("instance"), named->NewInstance()); 4533 env->Global()->Set(v8::String::New("instance"), named->NewInstance());
(...skipping 15 matching lines...) Expand all
4549 4549
4550 4550
4551 static v8::Handle<v8::Value> ProtperyXNativeGetterThrowingError( 4551 static v8::Handle<v8::Value> ProtperyXNativeGetterThrowingError(
4552 v8::Local<v8::String> property, const v8::AccessorInfo& info) { 4552 v8::Local<v8::String> property, const v8::AccessorInfo& info) {
4553 return CompileRun("throw new Error('Error message');"); 4553 return CompileRun("throw new Error('Error message');");
4554 } 4554 }
4555 4555
4556 4556
4557 TEST(NativeGetterThrowingErrorPropertyMirror) { 4557 TEST(NativeGetterThrowingErrorPropertyMirror) {
4558 // Create a V8 environment with debug access. 4558 // Create a V8 environment with debug access.
4559 v8::HandleScope scope;
4560 DebugLocalContext env; 4559 DebugLocalContext env;
4560 v8::HandleScope scope(env->GetIsolate());
4561 env.ExposeDebug(); 4561 env.ExposeDebug();
4562 4562
4563 v8::Handle<v8::String> name = v8::String::New("x"); 4563 v8::Handle<v8::String> name = v8::String::New("x");
4564 // Create object with named accessor. 4564 // Create object with named accessor.
4565 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); 4565 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
4566 named->SetAccessor(name, &ProtperyXNativeGetterThrowingError, NULL, 4566 named->SetAccessor(name, &ProtperyXNativeGetterThrowingError, NULL,
4567 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None); 4567 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None);
4568 4568
4569 // Create object with named property getter. 4569 // Create object with named property getter.
4570 env->Global()->Set(v8::String::New("instance"), named->NewInstance()); 4570 env->Global()->Set(v8::String::New("instance"), named->NewInstance());
(...skipping 13 matching lines...) Expand all
4584 "instance_mirror.property('x').value().message() == 'Error message'")-> 4584 "instance_mirror.property('x').value().message() == 'Error message'")->
4585 BooleanValue()); 4585 BooleanValue());
4586 } 4586 }
4587 4587
4588 4588
4589 // Test that hidden properties object is not returned as an unnamed property 4589 // Test that hidden properties object is not returned as an unnamed property
4590 // among regular properties. 4590 // among regular properties.
4591 // See http://crbug.com/26491 4591 // See http://crbug.com/26491
4592 TEST(NoHiddenProperties) { 4592 TEST(NoHiddenProperties) {
4593 // Create a V8 environment with debug access. 4593 // Create a V8 environment with debug access.
4594 v8::HandleScope scope;
4595 DebugLocalContext env; 4594 DebugLocalContext env;
4595 v8::HandleScope scope(env->GetIsolate());
4596 env.ExposeDebug(); 4596 env.ExposeDebug();
4597 4597
4598 // Create an object in the global scope. 4598 // Create an object in the global scope.
4599 const char* source = "var obj = {a: 1};"; 4599 const char* source = "var obj = {a: 1};";
4600 v8::Script::Compile(v8::String::New(source))->Run(); 4600 v8::Script::Compile(v8::String::New(source))->Run();
4601 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast( 4601 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(
4602 env->Global()->Get(v8::String::New("obj"))); 4602 env->Global()->Get(v8::String::New("obj")));
4603 // Set a hidden property on the object. 4603 // Set a hidden property on the object.
4604 obj->SetHiddenValue(v8::String::New("v8::test-debug::a"), 4604 obj->SetHiddenValue(v8::String::New("v8::test-debug::a"),
4605 v8::Int32::New(11)); 4605 v8::Int32::New(11));
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
4931 } 4931 }
4932 // Main thread continues running source_3 to end, waits for this thread. 4932 // Main thread continues running source_3 to end, waits for this thread.
4933 } 4933 }
4934 4934
4935 4935
4936 // This thread runs the v8 engine. 4936 // This thread runs the v8 engine.
4937 TEST(MessageQueues) { 4937 TEST(MessageQueues) {
4938 MessageQueueDebuggerThread message_queue_debugger_thread; 4938 MessageQueueDebuggerThread message_queue_debugger_thread;
4939 4939
4940 // Create a V8 environment 4940 // Create a V8 environment
4941 v8::HandleScope scope;
4942 DebugLocalContext env; 4941 DebugLocalContext env;
4942 v8::HandleScope scope(env->GetIsolate());
4943 message_queue_barriers.Initialize(); 4943 message_queue_barriers.Initialize();
4944 v8::Debug::SetMessageHandler(MessageHandler); 4944 v8::Debug::SetMessageHandler(MessageHandler);
4945 message_queue_debugger_thread.Start(); 4945 message_queue_debugger_thread.Start();
4946 4946
4947 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 4947 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
4948 const char* source_2 = "e = 17;"; 4948 const char* source_2 = "e = 17;";
4949 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; 4949 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;";
4950 4950
4951 // See MessageQueueDebuggerThread::Run for interleaved sequence of 4951 // See MessageQueueDebuggerThread::Run for interleaved sequence of
4952 // API calls and events in the two threads. 4952 // API calls and events in the two threads.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 const v8::Debug::Message& message) { 5023 const v8::Debug::Message& message) {
5024 if (message.GetClientData() != NULL) { 5024 if (message.GetClientData() != NULL) {
5025 handled_client_data_instances_count++; 5025 handled_client_data_instances_count++;
5026 } 5026 }
5027 } 5027 }
5028 5028
5029 5029
5030 // Tests that all client data passed to the debugger are sent to the handler. 5030 // Tests that all client data passed to the debugger are sent to the handler.
5031 TEST(SendClientDataToHandler) { 5031 TEST(SendClientDataToHandler) {
5032 // Create a V8 environment 5032 // Create a V8 environment
5033 v8::HandleScope scope;
5034 DebugLocalContext env; 5033 DebugLocalContext env;
5034 v8::HandleScope scope(env->GetIsolate());
5035 TestClientData::ResetCounters(); 5035 TestClientData::ResetCounters();
5036 handled_client_data_instances_count = 0; 5036 handled_client_data_instances_count = 0;
5037 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData); 5037 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
5038 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 5038 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
5039 const int kBufferSize = 1000; 5039 const int kBufferSize = 1000;
5040 uint16_t buffer[kBufferSize]; 5040 uint16_t buffer[kBufferSize];
5041 const char* command_1 = 5041 const char* command_1 =
5042 "{\"seq\":117," 5042 "{\"seq\":117,"
5043 "\"type\":\"request\"," 5043 "\"type\":\"request\","
5044 "\"command\":\"evaluate\"," 5044 "\"command\":\"evaluate\","
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
5129 " if ( x == 1 ) {\n" 5129 " if ( x == 1 ) {\n"
5130 " ThreadedAtBarrier1();\n" 5130 " ThreadedAtBarrier1();\n"
5131 " }\n" 5131 " }\n"
5132 " x = x + 1;\n" 5132 " x = x + 1;\n"
5133 " }\n" 5133 " }\n"
5134 "}\n" 5134 "}\n"
5135 "\n" 5135 "\n"
5136 "foo();\n"; 5136 "foo();\n";
5137 5137
5138 v8::V8::Initialize(); 5138 v8::V8::Initialize();
5139 v8::HandleScope scope;
5140 DebugLocalContext env; 5139 DebugLocalContext env;
5140 v8::HandleScope scope(env->GetIsolate());
5141 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); 5141 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
5142 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5142 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5143 global_template->Set(v8::String::New("ThreadedAtBarrier1"), 5143 global_template->Set(v8::String::New("ThreadedAtBarrier1"),
5144 v8::FunctionTemplate::New(ThreadedAtBarrier1)); 5144 v8::FunctionTemplate::New(ThreadedAtBarrier1));
5145 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); 5145 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
5146 v8::Context::Scope context_scope(context); 5146 v8::Context::Scope context_scope(context);
5147 5147
5148 CompileRun(source); 5148 CompileRun(source);
5149 } 5149 }
5150 5150
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
5242 " x = y_global;" 5242 " x = y_global;"
5243 " var z = 3;" 5243 " var z = 3;"
5244 " x += 100;\n" 5244 " x += 100;\n"
5245 " return x;\n" 5245 " return x;\n"
5246 "}\n" 5246 "}\n"
5247 "\n"; 5247 "\n";
5248 const char* source_2 = "cat(17);\n" 5248 const char* source_2 = "cat(17);\n"
5249 "cat(19);\n"; 5249 "cat(19);\n";
5250 5250
5251 v8::V8::Initialize(); 5251 v8::V8::Initialize();
5252 v8::HandleScope scope;
5253 DebugLocalContext env; 5252 DebugLocalContext env;
5253 v8::HandleScope scope(env->GetIsolate());
5254 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler); 5254 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
5255 5255
5256 CompileRun(source_1); 5256 CompileRun(source_1);
5257 breakpoints_barriers->barrier_1.Wait(); 5257 breakpoints_barriers->barrier_1.Wait();
5258 breakpoints_barriers->barrier_2.Wait(); 5258 breakpoints_barriers->barrier_2.Wait();
5259 CompileRun(source_2); 5259 CompileRun(source_2);
5260 } 5260 }
5261 5261
5262 5262
5263 void BreakpointsDebuggerThread::Run() { 5263 void BreakpointsDebuggerThread::Run() {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
5501 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber()); 5501 CHECK(v8::Debug::Call(debugger_call_with_closure)->IsNumber());
5502 CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value()); 5502 CHECK_EQ(3, v8::Debug::Call(debugger_call_with_closure)->Int32Value());
5503 return v8::Undefined(); 5503 return v8::Undefined();
5504 } 5504 }
5505 5505
5506 5506
5507 // Test functions called through the debugger. 5507 // Test functions called through the debugger.
5508 TEST(CallFunctionInDebugger) { 5508 TEST(CallFunctionInDebugger) {
5509 // Create and enter a context with the functions CheckFrameCount, 5509 // Create and enter a context with the functions CheckFrameCount,
5510 // CheckSourceLine and CheckDataParameter installed. 5510 // CheckSourceLine and CheckDataParameter installed.
5511 v8::HandleScope scope; 5511 v8::HandleScope scope(v8::Isolate::GetCurrent());
5512 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5512 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5513 global_template->Set(v8::String::New("CheckFrameCount"), 5513 global_template->Set(v8::String::New("CheckFrameCount"),
5514 v8::FunctionTemplate::New(CheckFrameCount)); 5514 v8::FunctionTemplate::New(CheckFrameCount));
5515 global_template->Set(v8::String::New("CheckSourceLine"), 5515 global_template->Set(v8::String::New("CheckSourceLine"),
5516 v8::FunctionTemplate::New(CheckSourceLine)); 5516 v8::FunctionTemplate::New(CheckSourceLine));
5517 global_template->Set(v8::String::New("CheckDataParameter"), 5517 global_template->Set(v8::String::New("CheckDataParameter"),
5518 v8::FunctionTemplate::New(CheckDataParameter)); 5518 v8::FunctionTemplate::New(CheckDataParameter));
5519 global_template->Set(v8::String::New("CheckClosure"), 5519 global_template->Set(v8::String::New("CheckClosure"),
5520 v8::FunctionTemplate::New(CheckClosure)); 5520 v8::FunctionTemplate::New(CheckClosure));
5521 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); 5521 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
5597 DebugLocalContext env; 5597 DebugLocalContext env;
5598 5598
5599 // Check debugger is unloaded before it is used. 5599 // Check debugger is unloaded before it is used.
5600 CheckDebuggerUnloaded(); 5600 CheckDebuggerUnloaded();
5601 5601
5602 // Set a debug event listener. 5602 // Set a debug event listener.
5603 break_point_hit_count = 0; 5603 break_point_hit_count = 0;
5604 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 5604 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
5605 v8::Undefined()); 5605 v8::Undefined());
5606 { 5606 {
5607 v8::HandleScope scope; 5607 v8::HandleScope scope(env->GetIsolate());
5608 // Create a couple of functions for the test. 5608 // Create a couple of functions for the test.
5609 v8::Local<v8::Function> foo = 5609 v8::Local<v8::Function> foo =
5610 CompileFunction(&env, "function foo(){x=1}", "foo"); 5610 CompileFunction(&env, "function foo(){x=1}", "foo");
5611 v8::Local<v8::Function> bar = 5611 v8::Local<v8::Function> bar =
5612 CompileFunction(&env, "function bar(){y=2}", "bar"); 5612 CompileFunction(&env, "function bar(){y=2}", "bar");
5613 5613
5614 // Set some break points. 5614 // Set some break points.
5615 SetBreakPoint(foo, 0); 5615 SetBreakPoint(foo, 0);
5616 SetBreakPoint(foo, 4); 5616 SetBreakPoint(foo, 4);
5617 SetBreakPoint(bar, 0); 5617 SetBreakPoint(bar, 0);
5618 SetBreakPoint(bar, 4); 5618 SetBreakPoint(bar, 4);
5619 5619
5620 // Make sure that the break points are there. 5620 // Make sure that the break points are there.
5621 break_point_hit_count = 0; 5621 break_point_hit_count = 0;
5622 foo->Call(env->Global(), 0, NULL); 5622 foo->Call(env->Global(), 0, NULL);
5623 CHECK_EQ(2, break_point_hit_count); 5623 CHECK_EQ(2, break_point_hit_count);
5624 bar->Call(env->Global(), 0, NULL); 5624 bar->Call(env->Global(), 0, NULL);
5625 CHECK_EQ(4, break_point_hit_count); 5625 CHECK_EQ(4, break_point_hit_count);
5626 } 5626 }
5627 5627
5628 // Remove the debug event listener without clearing breakpoints. Do this 5628 // Remove the debug event listener without clearing breakpoints. Do this
5629 // outside a handle scope. 5629 // outside a handle scope.
5630 v8::Debug::SetDebugEventListener(NULL); 5630 v8::Debug::SetDebugEventListener(NULL);
5631 CheckDebuggerUnloaded(true); 5631 CheckDebuggerUnloaded(true);
5632 5632
5633 // Now set a debug message handler. 5633 // Now set a debug message handler.
5634 break_point_hit_count = 0; 5634 break_point_hit_count = 0;
5635 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); 5635 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount);
5636 { 5636 {
5637 v8::HandleScope scope; 5637 v8::HandleScope scope(env->GetIsolate());
5638 5638
5639 // Get the test functions again. 5639 // Get the test functions again.
5640 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( 5640 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast(
5641 env->Global()->Get(v8::String::New("foo")))); 5641 env->Global()->Get(v8::String::New("foo"))));
5642 5642
5643 foo->Call(env->Global(), 0, NULL); 5643 foo->Call(env->Global(), 0, NULL);
5644 CHECK_EQ(0, break_point_hit_count); 5644 CHECK_EQ(0, break_point_hit_count);
5645 5645
5646 // Set break points and run again. 5646 // Set break points and run again.
5647 SetBreakPoint(foo, 0); 5647 SetBreakPoint(foo, 0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5680 Utf16ToAscii(*json, json.length(), print_buffer); 5680 Utf16ToAscii(*json, json.length(), print_buffer);
5681 if (IsExceptionEventMessage(print_buffer)) { 5681 if (IsExceptionEventMessage(print_buffer)) {
5682 // Send a continue command for exception events. 5682 // Send a continue command for exception events.
5683 SendContinueCommand(); 5683 SendContinueCommand();
5684 } 5684 }
5685 } 5685 }
5686 5686
5687 5687
5688 // Test clearing the debug message handler. 5688 // Test clearing the debug message handler.
5689 TEST(DebuggerClearMessageHandler) { 5689 TEST(DebuggerClearMessageHandler) {
5690 v8::HandleScope scope;
5691 DebugLocalContext env; 5690 DebugLocalContext env;
5691 v8::HandleScope scope(env->GetIsolate());
5692 5692
5693 // Check debugger is unloaded before it is used. 5693 // Check debugger is unloaded before it is used.
5694 CheckDebuggerUnloaded(); 5694 CheckDebuggerUnloaded();
5695 5695
5696 // Set a debug message handler. 5696 // Set a debug message handler.
5697 v8::Debug::SetMessageHandler2(MessageHandlerHitCount); 5697 v8::Debug::SetMessageHandler2(MessageHandlerHitCount);
5698 5698
5699 // Run code to throw a unhandled exception. This should end up in the message 5699 // Run code to throw a unhandled exception. This should end up in the message
5700 // handler. 5700 // handler.
5701 CompileRun("throw 1"); 5701 CompileRun("throw 1");
(...skipping 21 matching lines...) Expand all
5723 const v8::Debug::Message& message) { 5723 const v8::Debug::Message& message) {
5724 message_handler_hit_count++; 5724 message_handler_hit_count++;
5725 5725
5726 // Clear debug message handler. 5726 // Clear debug message handler.
5727 v8::Debug::SetMessageHandler(NULL); 5727 v8::Debug::SetMessageHandler(NULL);
5728 } 5728 }
5729 5729
5730 5730
5731 // Test clearing the debug message handler while processing a debug event. 5731 // Test clearing the debug message handler while processing a debug event.
5732 TEST(DebuggerClearMessageHandlerWhileActive) { 5732 TEST(DebuggerClearMessageHandlerWhileActive) {
5733 v8::HandleScope scope;
5734 DebugLocalContext env; 5733 DebugLocalContext env;
5734 v8::HandleScope scope(env->GetIsolate());
5735 5735
5736 // Check debugger is unloaded before it is used. 5736 // Check debugger is unloaded before it is used.
5737 CheckDebuggerUnloaded(); 5737 CheckDebuggerUnloaded();
5738 5738
5739 // Set a debug message handler. 5739 // Set a debug message handler.
5740 v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler); 5740 v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler);
5741 5741
5742 // Run code to throw a unhandled exception. This should end up in the message 5742 // Run code to throw a unhandled exception. This should end up in the message
5743 // handler. 5743 // handler.
5744 CompileRun("throw 1"); 5744 CompileRun("throw 1");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5787 " var x = new_value;\n" 5787 " var x = new_value;\n"
5788 " y_global = 4;\n" 5788 " y_global = 4;\n"
5789 " x = 3 * x + 1;\n" 5789 " x = 3 * x + 1;\n"
5790 " y_global = 5;\n" 5790 " y_global = 5;\n"
5791 " return x;\n" 5791 " return x;\n"
5792 "}\n" 5792 "}\n"
5793 "\n"; 5793 "\n";
5794 const char* source_2 = "cat(17);\n"; 5794 const char* source_2 = "cat(17);\n";
5795 5795
5796 v8::V8::Initialize(); 5796 v8::V8::Initialize();
5797 v8::HandleScope scope;
5798 DebugLocalContext env; 5797 DebugLocalContext env;
5798 v8::HandleScope scope(env->GetIsolate());
5799 5799
5800 // Set up message and host dispatch handlers. 5800 // Set up message and host dispatch handlers.
5801 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler); 5801 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler);
5802 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */); 5802 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
5803 5803
5804 CompileRun(source_1); 5804 CompileRun(source_1);
5805 host_dispatch_barriers->barrier_1.Wait(); 5805 host_dispatch_barriers->barrier_1.Wait();
5806 host_dispatch_barriers->barrier_2.Wait(); 5806 host_dispatch_barriers->barrier_2.Wait();
5807 CompileRun(source_2); 5807 CompileRun(source_2);
5808 } 5808 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
5875 Barriers* debug_message_dispatch_barriers; 5875 Barriers* debug_message_dispatch_barriers;
5876 5876
5877 5877
5878 static void DebugMessageHandler() { 5878 static void DebugMessageHandler() {
5879 debug_message_dispatch_barriers->semaphore_1->Signal(); 5879 debug_message_dispatch_barriers->semaphore_1->Signal();
5880 } 5880 }
5881 5881
5882 5882
5883 void DebugMessageDispatchV8Thread::Run() { 5883 void DebugMessageDispatchV8Thread::Run() {
5884 v8::V8::Initialize(); 5884 v8::V8::Initialize();
5885 v8::HandleScope scope;
5886 DebugLocalContext env; 5885 DebugLocalContext env;
5886 v8::HandleScope scope(env->GetIsolate());
5887 5887
5888 // Set up debug message dispatch handler. 5888 // Set up debug message dispatch handler.
5889 v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler); 5889 v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler);
5890 5890
5891 CompileRun("var y = 1 + 2;\n"); 5891 CompileRun("var y = 1 + 2;\n");
5892 debug_message_dispatch_barriers->barrier_1.Wait(); 5892 debug_message_dispatch_barriers->barrier_1.Wait();
5893 debug_message_dispatch_barriers->semaphore_1->Wait(); 5893 debug_message_dispatch_barriers->semaphore_1->Wait();
5894 debug_message_dispatch_barriers->barrier_2.Wait(); 5894 debug_message_dispatch_barriers->barrier_2.Wait();
5895 } 5895 }
5896 5896
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
6102 EmptyExternalStringResource() { empty_[0] = 0; } 6102 EmptyExternalStringResource() { empty_[0] = 0; }
6103 virtual ~EmptyExternalStringResource() {} 6103 virtual ~EmptyExternalStringResource() {}
6104 virtual size_t length() const { return empty_.length(); } 6104 virtual size_t length() const { return empty_.length(); }
6105 virtual const uint16_t* data() const { return empty_.start(); } 6105 virtual const uint16_t* data() const { return empty_.start(); }
6106 private: 6106 private:
6107 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_; 6107 ::v8::internal::EmbeddedVector<uint16_t, 1> empty_;
6108 }; 6108 };
6109 6109
6110 6110
6111 TEST(DebugGetLoadedScripts) { 6111 TEST(DebugGetLoadedScripts) {
6112 v8::HandleScope scope;
6113 DebugLocalContext env; 6112 DebugLocalContext env;
6113 v8::HandleScope scope(env->GetIsolate());
6114 env.ExposeDebug(); 6114 env.ExposeDebug();
6115 6115
6116 EmptyExternalStringResource source_ext_str; 6116 EmptyExternalStringResource source_ext_str;
6117 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); 6117 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
6118 v8::Handle<v8::Script> evil_script(v8::Script::Compile(source)); 6118 v8::Handle<v8::Script> evil_script(v8::Script::Compile(source));
6119 // "use" evil_script to make the compiler happy. 6119 // "use" evil_script to make the compiler happy.
6120 (void) evil_script; 6120 (void) evil_script;
6121 Handle<i::ExternalTwoByteString> i_source( 6121 Handle<i::ExternalTwoByteString> i_source(
6122 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); 6122 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
6123 // This situation can happen if source was an external string disposed 6123 // This situation can happen if source was an external string disposed
(...skipping 11 matching lines...) Expand all
6135 // Must not crash while accessing line_ends. 6135 // Must not crash while accessing line_ends.
6136 i::FLAG_allow_natives_syntax = allow_natives_syntax; 6136 i::FLAG_allow_natives_syntax = allow_natives_syntax;
6137 6137
6138 // Some scripts are retrieved - at least the number of native scripts. 6138 // Some scripts are retrieved - at least the number of native scripts.
6139 CHECK_GT((*env)->Global()->Get(v8::String::New("count"))->Int32Value(), 8); 6139 CHECK_GT((*env)->Global()->Get(v8::String::New("count"))->Int32Value(), 8);
6140 } 6140 }
6141 6141
6142 6142
6143 // Test script break points set on lines. 6143 // Test script break points set on lines.
6144 TEST(ScriptNameAndData) { 6144 TEST(ScriptNameAndData) {
6145 v8::HandleScope scope;
6146 DebugLocalContext env; 6145 DebugLocalContext env;
6146 v8::HandleScope scope(env->GetIsolate());
6147 env.ExposeDebug(); 6147 env.ExposeDebug();
6148 6148
6149 // Create functions for retrieving script name and data for the function on 6149 // Create functions for retrieving script name and data for the function on
6150 // the top frame when hitting a break point. 6150 // the top frame when hitting a break point.
6151 frame_script_name = CompileFunction(&env, 6151 frame_script_name = CompileFunction(&env,
6152 frame_script_name_source, 6152 frame_script_name_source,
6153 "frame_script_name"); 6153 "frame_script_name");
6154 frame_script_data = CompileFunction(&env, 6154 frame_script_data = CompileFunction(&env,
6155 frame_script_data_source, 6155 frame_script_data_source,
6156 "frame_script_data"); 6156 "frame_script_data");
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
6235 if (IsBreakEventMessage(print_buffer)) { 6235 if (IsBreakEventMessage(print_buffer)) {
6236 SendContinueCommand(); 6236 SendContinueCommand();
6237 } 6237 }
6238 } 6238 }
6239 6239
6240 6240
6241 // Test which creates two contexts and sets different embedder data on each. 6241 // Test which creates two contexts and sets different embedder data on each.
6242 // Checks that this data is set correctly and that when the debug message 6242 // Checks that this data is set correctly and that when the debug message
6243 // handler is called the expected context is the one active. 6243 // handler is called the expected context is the one active.
6244 TEST(ContextData) { 6244 TEST(ContextData) {
6245 v8::HandleScope scope; 6245 v8::HandleScope scope(v8::Isolate::GetCurrent());
6246 6246
6247 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); 6247 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
6248 6248
6249 // Create two contexts. 6249 // Create two contexts.
6250 v8::Persistent<v8::Context> context_1; 6250 v8::Persistent<v8::Context> context_1;
6251 v8::Persistent<v8::Context> context_2; 6251 v8::Persistent<v8::Context> context_2;
6252 v8::Handle<v8::ObjectTemplate> global_template = 6252 v8::Handle<v8::ObjectTemplate> global_template =
6253 v8::Handle<v8::ObjectTemplate>(); 6253 v8::Handle<v8::ObjectTemplate>();
6254 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); 6254 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
6255 context_1 = v8::Context::New(NULL, global_template, global_object); 6255 context_1 = v8::Context::New(NULL, global_template, global_object);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
6311 // Issue a continue command if this event will not cause the VM to start 6311 // Issue a continue command if this event will not cause the VM to start
6312 // running. 6312 // running.
6313 if (!message.WillStartRunning()) { 6313 if (!message.WillStartRunning()) {
6314 SendContinueCommand(); 6314 SendContinueCommand();
6315 } 6315 }
6316 } 6316 }
6317 6317
6318 6318
6319 // Test that a debug break can be scheduled while in a message handler. 6319 // Test that a debug break can be scheduled while in a message handler.
6320 TEST(DebugBreakInMessageHandler) { 6320 TEST(DebugBreakInMessageHandler) {
6321 v8::HandleScope scope;
6322 DebugLocalContext env; 6321 DebugLocalContext env;
6322 v8::HandleScope scope(env->GetIsolate());
6323 6323
6324 v8::Debug::SetMessageHandler2(DebugBreakMessageHandler); 6324 v8::Debug::SetMessageHandler2(DebugBreakMessageHandler);
6325 6325
6326 // Test functions. 6326 // Test functions.
6327 const char* script = "function f() { debugger; g(); } function g() { }"; 6327 const char* script = "function f() { debugger; g(); } function g() { }";
6328 CompileRun(script); 6328 CompileRun(script);
6329 v8::Local<v8::Function> f = 6329 v8::Local<v8::Function> f =
6330 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 6330 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6331 v8::Local<v8::Function> g = 6331 v8::Local<v8::Function> g =
6332 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); 6332 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6372 // Keep forcing breaks. 6372 // Keep forcing breaks.
6373 if (break_point_hit_count < 20) { 6373 if (break_point_hit_count < 20) {
6374 v8::Debug::DebugBreak(); 6374 v8::Debug::DebugBreak();
6375 } 6375 }
6376 } 6376 }
6377 } 6377 }
6378 6378
6379 6379
6380 TEST(RegExpDebugBreak) { 6380 TEST(RegExpDebugBreak) {
6381 // This test only applies to native regexps. 6381 // This test only applies to native regexps.
6382 v8::HandleScope scope;
6383 DebugLocalContext env; 6382 DebugLocalContext env;
6383 v8::HandleScope scope(env->GetIsolate());
6384 6384
6385 // Create a function for checking the function when hitting a break point. 6385 // Create a function for checking the function when hitting a break point.
6386 frame_function_name = CompileFunction(&env, 6386 frame_function_name = CompileFunction(&env,
6387 frame_function_name_source, 6387 frame_function_name_source,
6388 "frame_function_name"); 6388 "frame_function_name");
6389 6389
6390 // Test RegExp which matches white spaces and comments at the begining of a 6390 // Test RegExp which matches white spaces and comments at the begining of a
6391 // source line. 6391 // source line.
6392 const char* script = 6392 const char* script =
6393 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" 6393 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6439 f->Call(context_1->Global(), 0, NULL); 6439 f->Call(context_1->Global(), 0, NULL);
6440 } 6440 }
6441 } 6441 }
6442 6442
6443 6443
6444 // Test which creates a context and sets embedder data on it. Checks that this 6444 // Test which creates a context and sets embedder data on it. Checks that this
6445 // data is set correctly and that when the debug message handler is called for 6445 // data is set correctly and that when the debug message handler is called for
6446 // break event in an eval statement the expected context is the one returned by 6446 // break event in an eval statement the expected context is the one returned by
6447 // Message.GetEventContext. 6447 // Message.GetEventContext.
6448 TEST(EvalContextData) { 6448 TEST(EvalContextData) {
6449 v8::HandleScope scope; 6449 v8::HandleScope scope(v8::Isolate::GetCurrent());
6450 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); 6450 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler);
6451 6451
6452 ExecuteScriptForContextCheck(); 6452 ExecuteScriptForContextCheck();
6453 6453
6454 // One time compile event and one time break event. 6454 // One time compile event and one time break event.
6455 CHECK_GT(message_handler_hit_count, 2); 6455 CHECK_GT(message_handler_hit_count, 2);
6456 v8::Debug::SetMessageHandler2(NULL); 6456 v8::Debug::SetMessageHandler2(NULL);
6457 CheckDebuggerUnloaded(); 6457 CheckDebuggerUnloaded();
6458 } 6458 }
6459 6459
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6502 // send continue. 6502 // send continue.
6503 SendContinueCommand(); 6503 SendContinueCommand();
6504 continue_command_send_count++; 6504 continue_command_send_count++;
6505 } 6505 }
6506 } 6506 }
6507 6507
6508 6508
6509 // Tests that context returned for break event is correct when the event occurs 6509 // Tests that context returned for break event is correct when the event occurs
6510 // in 'evaluate' debugger request. 6510 // in 'evaluate' debugger request.
6511 TEST(NestedBreakEventContextData) { 6511 TEST(NestedBreakEventContextData) {
6512 v8::HandleScope scope; 6512 v8::HandleScope scope(v8::Isolate::GetCurrent());
6513 break_count = 0; 6513 break_count = 0;
6514 message_handler_hit_count = 0; 6514 message_handler_hit_count = 0;
6515 v8::Debug::SetMessageHandler2(DebugEvalContextCheckMessageHandler); 6515 v8::Debug::SetMessageHandler2(DebugEvalContextCheckMessageHandler);
6516 6516
6517 ExecuteScriptForContextCheck(); 6517 ExecuteScriptForContextCheck();
6518 6518
6519 // One time compile event and two times break event. 6519 // One time compile event and two times break event.
6520 CHECK_GT(message_handler_hit_count, 3); 6520 CHECK_GT(message_handler_hit_count, 3);
6521 6521
6522 // One break from the source and another from the evaluate request. 6522 // One break from the source and another from the evaluate request.
(...skipping 14 matching lines...) Expand all
6537 script_collected_count++; 6537 script_collected_count++;
6538 } 6538 }
6539 } 6539 }
6540 6540
6541 6541
6542 // Test that scripts collected are reported through the debug event listener. 6542 // Test that scripts collected are reported through the debug event listener.
6543 TEST(ScriptCollectedEvent) { 6543 TEST(ScriptCollectedEvent) {
6544 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 6544 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6545 break_point_hit_count = 0; 6545 break_point_hit_count = 0;
6546 script_collected_count = 0; 6546 script_collected_count = 0;
6547 v8::HandleScope scope;
6548 DebugLocalContext env; 6547 DebugLocalContext env;
6548 v8::HandleScope scope(env->GetIsolate());
6549 6549
6550 // Request the loaded scripts to initialize the debugger script cache. 6550 // Request the loaded scripts to initialize the debugger script cache.
6551 debug->GetLoadedScripts(); 6551 debug->GetLoadedScripts();
6552 6552
6553 // Do garbage collection to ensure that only the script in this test will be 6553 // Do garbage collection to ensure that only the script in this test will be
6554 // collected afterwards. 6554 // collected afterwards.
6555 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 6555 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6556 6556
6557 script_collected_count = 0; 6557 script_collected_count = 0;
6558 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent, 6558 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent,
(...skipping 22 matching lines...) Expand all
6581 script_collected_message_count++; 6581 script_collected_message_count++;
6582 v8::Handle<v8::Context> context = message.GetEventContext(); 6582 v8::Handle<v8::Context> context = message.GetEventContext();
6583 CHECK(context.IsEmpty()); 6583 CHECK(context.IsEmpty());
6584 } 6584 }
6585 } 6585 }
6586 6586
6587 6587
6588 // Test that GetEventContext doesn't fail and return empty handle for 6588 // Test that GetEventContext doesn't fail and return empty handle for
6589 // ScriptCollected events. 6589 // ScriptCollected events.
6590 TEST(ScriptCollectedEventContext) { 6590 TEST(ScriptCollectedEventContext) {
6591 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 6591 v8::Isolate* isolate = v8::Isolate::GetCurrent();
6592 v8::internal::Debug* debug =
6593 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug();
6592 script_collected_message_count = 0; 6594 script_collected_message_count = 0;
6593 v8::HandleScope scope; 6595 v8::HandleScope scope(isolate);
6594 6596
6595 { // Scope for the DebugLocalContext. 6597 { // Scope for the DebugLocalContext.
6596 DebugLocalContext env; 6598 DebugLocalContext env;
6597 6599
6598 // Request the loaded scripts to initialize the debugger script cache. 6600 // Request the loaded scripts to initialize the debugger script cache.
6599 debug->GetLoadedScripts(); 6601 debug->GetLoadedScripts();
6600 6602
6601 // Do garbage collection to ensure that only the script in this test will be 6603 // Do garbage collection to ensure that only the script in this test will be
6602 // collected afterwards. 6604 // collected afterwards.
6603 HEAP->CollectAllGarbage(Heap::kNoGCFlags); 6605 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
(...skipping 25 matching lines...) Expand all
6629 } else if (message.GetEvent() == v8::Break) { 6631 } else if (message.GetEvent() == v8::Break) {
6630 SendContinueCommand(); 6632 SendContinueCommand();
6631 } 6633 }
6632 } 6634 }
6633 } 6635 }
6634 6636
6635 6637
6636 // Tests that after compile event is sent as many times as there are scripts 6638 // Tests that after compile event is sent as many times as there are scripts
6637 // compiled. 6639 // compiled.
6638 TEST(AfterCompileMessageWhenMessageHandlerIsReset) { 6640 TEST(AfterCompileMessageWhenMessageHandlerIsReset) {
6639 v8::HandleScope scope;
6640 DebugLocalContext env; 6641 DebugLocalContext env;
6642 v8::HandleScope scope(env->GetIsolate());
6641 after_compile_message_count = 0; 6643 after_compile_message_count = 0;
6642 const char* script = "var a=1"; 6644 const char* script = "var a=1";
6643 6645
6644 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6646 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6645 v8::Script::Compile(v8::String::New(script))->Run(); 6647 v8::Script::Compile(v8::String::New(script))->Run();
6646 v8::Debug::SetMessageHandler2(NULL); 6648 v8::Debug::SetMessageHandler2(NULL);
6647 6649
6648 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6650 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6649 v8::Debug::DebugBreak(); 6651 v8::Debug::DebugBreak();
6650 v8::Script::Compile(v8::String::New(script))->Run(); 6652 v8::Script::Compile(v8::String::New(script))->Run();
6651 6653
6652 // Setting listener to NULL should cause debugger unload. 6654 // Setting listener to NULL should cause debugger unload.
6653 v8::Debug::SetMessageHandler2(NULL); 6655 v8::Debug::SetMessageHandler2(NULL);
6654 CheckDebuggerUnloaded(); 6656 CheckDebuggerUnloaded();
6655 6657
6656 // Compilation cache should be disabled when debugger is active. 6658 // Compilation cache should be disabled when debugger is active.
6657 CHECK_EQ(2, after_compile_message_count); 6659 CHECK_EQ(2, after_compile_message_count);
6658 } 6660 }
6659 6661
6660 6662
6661 // Tests that break event is sent when message handler is reset. 6663 // Tests that break event is sent when message handler is reset.
6662 TEST(BreakMessageWhenMessageHandlerIsReset) { 6664 TEST(BreakMessageWhenMessageHandlerIsReset) {
6663 v8::HandleScope scope;
6664 DebugLocalContext env; 6665 DebugLocalContext env;
6666 v8::HandleScope scope(env->GetIsolate());
6665 after_compile_message_count = 0; 6667 after_compile_message_count = 0;
6666 const char* script = "function f() {};"; 6668 const char* script = "function f() {};";
6667 6669
6668 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6670 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6669 v8::Script::Compile(v8::String::New(script))->Run(); 6671 v8::Script::Compile(v8::String::New(script))->Run();
6670 v8::Debug::SetMessageHandler2(NULL); 6672 v8::Debug::SetMessageHandler2(NULL);
6671 6673
6672 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6674 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6673 v8::Debug::DebugBreak(); 6675 v8::Debug::DebugBreak();
6674 v8::Local<v8::Function> f = 6676 v8::Local<v8::Function> f =
(...skipping 13 matching lines...) Expand all
6688 static void ExceptionMessageHandler(const v8::Debug::Message& message) { 6690 static void ExceptionMessageHandler(const v8::Debug::Message& message) {
6689 if (message.IsEvent() && message.GetEvent() == v8::Exception) { 6691 if (message.IsEvent() && message.GetEvent() == v8::Exception) {
6690 exception_event_count++; 6692 exception_event_count++;
6691 SendContinueCommand(); 6693 SendContinueCommand();
6692 } 6694 }
6693 } 6695 }
6694 6696
6695 6697
6696 // Tests that exception event is sent when message handler is reset. 6698 // Tests that exception event is sent when message handler is reset.
6697 TEST(ExceptionMessageWhenMessageHandlerIsReset) { 6699 TEST(ExceptionMessageWhenMessageHandlerIsReset) {
6698 v8::HandleScope scope;
6699 DebugLocalContext env; 6700 DebugLocalContext env;
6701 v8::HandleScope scope(env->GetIsolate());
6700 6702
6701 // For this test, we want to break on uncaught exceptions: 6703 // For this test, we want to break on uncaught exceptions:
6702 ChangeBreakOnException(false, true); 6704 ChangeBreakOnException(false, true);
6703 6705
6704 exception_event_count = 0; 6706 exception_event_count = 0;
6705 const char* script = "function f() {throw new Error()};"; 6707 const char* script = "function f() {throw new Error()};";
6706 6708
6707 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6709 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6708 v8::Script::Compile(v8::String::New(script))->Run(); 6710 v8::Script::Compile(v8::String::New(script))->Run();
6709 v8::Debug::SetMessageHandler2(NULL); 6711 v8::Debug::SetMessageHandler2(NULL);
6710 6712
6711 v8::Debug::SetMessageHandler2(ExceptionMessageHandler); 6713 v8::Debug::SetMessageHandler2(ExceptionMessageHandler);
6712 v8::Local<v8::Function> f = 6714 v8::Local<v8::Function> f =
6713 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 6715 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6714 f->Call(env->Global(), 0, NULL); 6716 f->Call(env->Global(), 0, NULL);
6715 6717
6716 // Setting message handler to NULL should cause debugger unload. 6718 // Setting message handler to NULL should cause debugger unload.
6717 v8::Debug::SetMessageHandler2(NULL); 6719 v8::Debug::SetMessageHandler2(NULL);
6718 CheckDebuggerUnloaded(); 6720 CheckDebuggerUnloaded();
6719 6721
6720 CHECK_EQ(1, exception_event_count); 6722 CHECK_EQ(1, exception_event_count);
6721 } 6723 }
6722 6724
6723 6725
6724 // Tests after compile event is sent when there are some provisional 6726 // Tests after compile event is sent when there are some provisional
6725 // breakpoints out of the scripts lines range. 6727 // breakpoints out of the scripts lines range.
6726 TEST(ProvisionalBreakpointOnLineOutOfRange) { 6728 TEST(ProvisionalBreakpointOnLineOutOfRange) {
6727 v8::HandleScope scope;
6728 DebugLocalContext env; 6729 DebugLocalContext env;
6730 v8::HandleScope scope(env->GetIsolate());
6729 env.ExposeDebug(); 6731 env.ExposeDebug();
6730 const char* script = "function f() {};"; 6732 const char* script = "function f() {};";
6731 const char* resource_name = "test_resource"; 6733 const char* resource_name = "test_resource";
6732 6734
6733 // Set a couple of provisional breakpoint on lines out of the script lines 6735 // Set a couple of provisional breakpoint on lines out of the script lines
6734 // range. 6736 // range.
6735 int sbp1 = SetScriptBreakPointByNameFromJS(resource_name, 3, 6737 int sbp1 = SetScriptBreakPointByNameFromJS(resource_name, 3,
6736 -1 /* no column */); 6738 -1 /* no column */);
6737 int sbp2 = SetScriptBreakPointByNameFromJS(resource_name, 5, 5); 6739 int sbp2 = SetScriptBreakPointByNameFromJS(resource_name, 5, 5);
6738 6740
(...skipping 18 matching lines...) Expand all
6757 v8::Debug::SetMessageHandler2(NULL); 6759 v8::Debug::SetMessageHandler2(NULL);
6758 } 6760 }
6759 6761
6760 6762
6761 static void BreakMessageHandler(const v8::Debug::Message& message) { 6763 static void BreakMessageHandler(const v8::Debug::Message& message) {
6762 i::Isolate* isolate = i::Isolate::Current(); 6764 i::Isolate* isolate = i::Isolate::Current();
6763 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6765 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6764 // Count the number of breaks. 6766 // Count the number of breaks.
6765 break_point_hit_count++; 6767 break_point_hit_count++;
6766 6768
6767 v8::HandleScope scope; 6769 i::HandleScope scope(isolate);
6768 message.GetJSON(); 6770 message.GetJSON();
6769 6771
6770 SendContinueCommand(); 6772 SendContinueCommand();
6771 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { 6773 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) {
6772 v8::HandleScope scope; 6774 i::HandleScope scope(isolate);
6773 6775
6774 bool is_debug_break = isolate->stack_guard()->IsDebugBreak(); 6776 bool is_debug_break = isolate->stack_guard()->IsDebugBreak();
6775 // Force DebugBreak flag while serializer is working. 6777 // Force DebugBreak flag while serializer is working.
6776 isolate->stack_guard()->DebugBreak(); 6778 isolate->stack_guard()->DebugBreak();
6777 6779
6778 // Force serialization to trigger some internal JS execution. 6780 // Force serialization to trigger some internal JS execution.
6779 message.GetJSON(); 6781 message.GetJSON();
6780 6782
6781 // Restore previous state. 6783 // Restore previous state.
6782 if (is_debug_break) { 6784 if (is_debug_break) {
6783 isolate->stack_guard()->DebugBreak(); 6785 isolate->stack_guard()->DebugBreak();
6784 } else { 6786 } else {
6785 isolate->stack_guard()->Continue(i::DEBUGBREAK); 6787 isolate->stack_guard()->Continue(i::DEBUGBREAK);
6786 } 6788 }
6787 } 6789 }
6788 } 6790 }
6789 6791
6790 6792
6791 // Test that if DebugBreak is forced it is ignored when code from 6793 // Test that if DebugBreak is forced it is ignored when code from
6792 // debug-delay.js is executed. 6794 // debug-delay.js is executed.
6793 TEST(NoDebugBreakInAfterCompileMessageHandler) { 6795 TEST(NoDebugBreakInAfterCompileMessageHandler) {
6794 v8::HandleScope scope;
6795 DebugLocalContext env; 6796 DebugLocalContext env;
6797 v8::HandleScope scope(env->GetIsolate());
6796 6798
6797 // Register a debug event listener which sets the break flag and counts. 6799 // Register a debug event listener which sets the break flag and counts.
6798 v8::Debug::SetMessageHandler2(BreakMessageHandler); 6800 v8::Debug::SetMessageHandler2(BreakMessageHandler);
6799 6801
6800 // Set the debug break flag. 6802 // Set the debug break flag.
6801 v8::Debug::DebugBreak(); 6803 v8::Debug::DebugBreak();
6802 6804
6803 // Create a function for testing stepping. 6805 // Create a function for testing stepping.
6804 const char* src = "function f() { eval('var x = 10;'); } "; 6806 const char* src = "function f() { eval('var x = 10;'); } ";
6805 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 6807 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
(...skipping 14 matching lines...) Expand all
6820 6822
6821 6823
6822 static int counting_message_handler_counter; 6824 static int counting_message_handler_counter;
6823 6825
6824 static void CountingMessageHandler(const v8::Debug::Message& message) { 6826 static void CountingMessageHandler(const v8::Debug::Message& message) {
6825 counting_message_handler_counter++; 6827 counting_message_handler_counter++;
6826 } 6828 }
6827 6829
6828 // Test that debug messages get processed when ProcessDebugMessages is called. 6830 // Test that debug messages get processed when ProcessDebugMessages is called.
6829 TEST(ProcessDebugMessages) { 6831 TEST(ProcessDebugMessages) {
6830 v8::HandleScope scope;
6831 DebugLocalContext env; 6832 DebugLocalContext env;
6833 v8::HandleScope scope(env->GetIsolate());
6832 6834
6833 counting_message_handler_counter = 0; 6835 counting_message_handler_counter = 0;
6834 6836
6835 v8::Debug::SetMessageHandler2(CountingMessageHandler); 6837 v8::Debug::SetMessageHandler2(CountingMessageHandler);
6836 6838
6837 const int kBufferSize = 1000; 6839 const int kBufferSize = 1000;
6838 uint16_t buffer[kBufferSize]; 6840 uint16_t buffer[kBufferSize];
6839 const char* scripts_command = 6841 const char* scripts_command =
6840 "{\"seq\":0," 6842 "{\"seq\":0,"
6841 "\"type\":\"request\"," 6843 "\"type\":\"request\","
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6876 } 6878 }
6877 frame_counter = GetTotalFramesInt(print_buffer); 6879 frame_counter = GetTotalFramesInt(print_buffer);
6878 } 6880 }
6879 }; 6881 };
6880 6882
6881 int BacktraceData::frame_counter; 6883 int BacktraceData::frame_counter;
6882 6884
6883 6885
6884 // Test that debug messages get processed when ProcessDebugMessages is called. 6886 // Test that debug messages get processed when ProcessDebugMessages is called.
6885 TEST(Backtrace) { 6887 TEST(Backtrace) {
6886 v8::HandleScope scope;
6887 DebugLocalContext env; 6888 DebugLocalContext env;
6889 v8::HandleScope scope(env->GetIsolate());
6888 6890
6889 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler); 6891 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler);
6890 6892
6891 const int kBufferSize = 1000; 6893 const int kBufferSize = 1000;
6892 uint16_t buffer[kBufferSize]; 6894 uint16_t buffer[kBufferSize];
6893 const char* scripts_command = 6895 const char* scripts_command =
6894 "{\"seq\":0," 6896 "{\"seq\":0,"
6895 "\"type\":\"request\"," 6897 "\"type\":\"request\","
6896 "\"command\":\"backtrace\"}"; 6898 "\"command\":\"backtrace\"}";
6897 6899
(...skipping 12 matching lines...) Expand all
6910 script->Run(); 6912 script->Run();
6911 CHECK_EQ(BacktraceData::frame_counter, 1); 6913 CHECK_EQ(BacktraceData::frame_counter, 1);
6912 6914
6913 // Get rid of the debug message handler. 6915 // Get rid of the debug message handler.
6914 v8::Debug::SetMessageHandler2(NULL); 6916 v8::Debug::SetMessageHandler2(NULL);
6915 CheckDebuggerUnloaded(); 6917 CheckDebuggerUnloaded();
6916 } 6918 }
6917 6919
6918 6920
6919 TEST(GetMirror) { 6921 TEST(GetMirror) {
6920 v8::HandleScope scope;
6921 DebugLocalContext env; 6922 DebugLocalContext env;
6923 v8::HandleScope scope(env->GetIsolate());
6922 v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja")); 6924 v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja"));
6923 v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast( 6925 v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast(
6924 v8::Script::New( 6926 v8::Script::New(
6925 v8::String::New( 6927 v8::String::New(
6926 "function runTest(mirror) {" 6928 "function runTest(mirror) {"
6927 " return mirror.isString() && (mirror.length() == 5);" 6929 " return mirror.isString() && (mirror.length() == 5);"
6928 "}" 6930 "}"
6929 "" 6931 ""
6930 "runTest;"))->Run()); 6932 "runTest;"))->Run());
6931 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); 6933 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj);
6932 CHECK(result->IsTrue()); 6934 CHECK(result->IsTrue());
6933 } 6935 }
6934 6936
6935 6937
6936 // Test that the debug break flag works with function.apply. 6938 // Test that the debug break flag works with function.apply.
6937 TEST(DebugBreakFunctionApply) { 6939 TEST(DebugBreakFunctionApply) {
6938 v8::HandleScope scope;
6939 DebugLocalContext env; 6940 DebugLocalContext env;
6941 v8::HandleScope scope(env->GetIsolate());
6940 6942
6941 // Create a function for testing breaking in apply. 6943 // Create a function for testing breaking in apply.
6942 v8::Local<v8::Function> foo = CompileFunction( 6944 v8::Local<v8::Function> foo = CompileFunction(
6943 &env, 6945 &env,
6944 "function baz(x) { }" 6946 "function baz(x) { }"
6945 "function bar(x) { baz(); }" 6947 "function bar(x) { baz(); }"
6946 "function foo(){ bar.apply(this, [1]); }", 6948 "function foo(){ bar.apply(this, [1]); }",
6947 "foo"); 6949 "foo");
6948 6950
6949 // Register a debug event listener which steps and counts. 6951 // Register a debug event listener which steps and counts.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
7006 v8::Handle<v8::Value> argv[argc] = { exec_state }; 7008 v8::Handle<v8::Value> argv[argc] = { exec_state };
7007 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv); 7009 v8::Handle<v8::Value> result = func->Call(exec_state, argc, argv);
7008 CHECK(result->IsTrue()); 7010 CHECK(result->IsTrue());
7009 } 7011 }
7010 } 7012 }
7011 7013
7012 7014
7013 TEST(CallingContextIsNotDebugContext) { 7015 TEST(CallingContextIsNotDebugContext) {
7014 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 7016 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
7015 // Create and enter a debugee context. 7017 // Create and enter a debugee context.
7016 v8::HandleScope scope;
7017 DebugLocalContext env; 7018 DebugLocalContext env;
7019 v8::HandleScope scope(env->GetIsolate());
7018 env.ExposeDebug(); 7020 env.ExposeDebug();
7019 7021
7020 // Save handles to the debugger and debugee contexts to be used in 7022 // Save handles to the debugger and debugee contexts to be used in
7021 // NamedGetterWithCallingContextCheck. 7023 // NamedGetterWithCallingContextCheck.
7022 debugee_context = v8::Local<v8::Context>(*env); 7024 debugee_context = v8::Local<v8::Context>(*env);
7023 debugger_context = v8::Utils::ToLocal(debug->debug_context()); 7025 debugger_context = v8::Utils::ToLocal(debug->debug_context());
7024 7026
7025 // Create object with 'a' property accessor. 7027 // Create object with 'a' property accessor.
7026 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); 7028 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New();
7027 named->SetAccessor(v8::String::New("a"), 7029 named->SetAccessor(v8::String::New("a"),
(...skipping 16 matching lines...) Expand all
7044 CHECK_EQ(1, break_point_hit_count); 7046 CHECK_EQ(1, break_point_hit_count);
7045 7047
7046 v8::Debug::SetDebugEventListener(NULL); 7048 v8::Debug::SetDebugEventListener(NULL);
7047 debugee_context = v8::Handle<v8::Context>(); 7049 debugee_context = v8::Handle<v8::Context>();
7048 debugger_context = v8::Handle<v8::Context>(); 7050 debugger_context = v8::Handle<v8::Context>();
7049 CheckDebuggerUnloaded(); 7051 CheckDebuggerUnloaded();
7050 } 7052 }
7051 7053
7052 7054
7053 TEST(DebugContextIsPreservedBetweenAccesses) { 7055 TEST(DebugContextIsPreservedBetweenAccesses) {
7054 v8::HandleScope scope; 7056 v8::HandleScope scope(v8::Isolate::GetCurrent());
7055 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext(); 7057 v8::Local<v8::Context> context1 = v8::Debug::GetDebugContext();
7056 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext(); 7058 v8::Local<v8::Context> context2 = v8::Debug::GetDebugContext();
7057 CHECK_EQ(*context1, *context2); 7059 CHECK_EQ(*context1, *context2);
7058 } 7060 }
7059 7061
7060 7062
7061 static v8::Handle<v8::Value> expected_callback_data; 7063 static v8::Handle<v8::Value> expected_callback_data;
7062 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) { 7064 static void DebugEventContextChecker(const v8::Debug::EventDetails& details) {
7063 CHECK(details.GetEventContext() == expected_context); 7065 CHECK(details.GetEventContext() == expected_context);
7064 CHECK_EQ(expected_callback_data, details.GetCallbackData()); 7066 CHECK_EQ(expected_callback_data, details.GetCallbackData());
7065 } 7067 }
7066 7068
7067 // Check that event details contain context where debug event occured. 7069 // Check that event details contain context where debug event occured.
7068 TEST(DebugEventContext) { 7070 TEST(DebugEventContext) {
7069 v8::HandleScope scope; 7071 v8::HandleScope scope(v8::Isolate::GetCurrent());
7070 expected_callback_data = v8::Int32::New(2010); 7072 expected_callback_data = v8::Int32::New(2010);
7071 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, 7073 v8::Debug::SetDebugEventListener2(DebugEventContextChecker,
7072 expected_callback_data); 7074 expected_callback_data);
7073 expected_context = v8::Context::New(); 7075 expected_context = v8::Context::New();
7074 v8::Context::Scope context_scope(expected_context); 7076 v8::Context::Scope context_scope(expected_context);
7075 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); 7077 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run();
7076 expected_context.Dispose(expected_context->GetIsolate()); 7078 expected_context.Dispose(expected_context->GetIsolate());
7077 expected_context.Clear(); 7079 expected_context.Clear();
7078 v8::Debug::SetDebugEventListener(NULL); 7080 v8::Debug::SetDebugEventListener(NULL);
7079 expected_context_data = v8::Handle<v8::Value>(); 7081 expected_context_data = v8::Handle<v8::Value>();
7080 CheckDebuggerUnloaded(); 7082 CheckDebuggerUnloaded();
7081 } 7083 }
7082 7084
7083 7085
7084 static void* expected_break_data; 7086 static void* expected_break_data;
7085 static bool was_debug_break_called; 7087 static bool was_debug_break_called;
7086 static bool was_debug_event_called; 7088 static bool was_debug_event_called;
7087 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) { 7089 static void DebugEventBreakDataChecker(const v8::Debug::EventDetails& details) {
7088 if (details.GetEvent() == v8::BreakForCommand) { 7090 if (details.GetEvent() == v8::BreakForCommand) {
7089 CHECK_EQ(expected_break_data, details.GetClientData()); 7091 CHECK_EQ(expected_break_data, details.GetClientData());
7090 was_debug_event_called = true; 7092 was_debug_event_called = true;
7091 } else if (details.GetEvent() == v8::Break) { 7093 } else if (details.GetEvent() == v8::Break) {
7092 was_debug_break_called = true; 7094 was_debug_break_called = true;
7093 } 7095 }
7094 } 7096 }
7095 7097
7096 7098
7097 // Check that event details contain context where debug event occured. 7099 // Check that event details contain context where debug event occured.
7098 TEST(DebugEventBreakData) { 7100 TEST(DebugEventBreakData) {
7099 v8::HandleScope scope;
7100 DebugLocalContext env; 7101 DebugLocalContext env;
7102 v8::HandleScope scope(env->GetIsolate());
7101 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker); 7103 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker);
7102 7104
7103 TestClientData::constructor_call_counter = 0; 7105 TestClientData::constructor_call_counter = 0;
7104 TestClientData::destructor_call_counter = 0; 7106 TestClientData::destructor_call_counter = 0;
7105 7107
7106 expected_break_data = NULL; 7108 expected_break_data = NULL;
7107 was_debug_event_called = false; 7109 was_debug_event_called = false;
7108 was_debug_break_called = false; 7110 was_debug_break_called = false;
7109 v8::Debug::DebugBreakForCommand(); 7111 v8::Debug::DebugBreakForCommand();
7110 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run(); 7112 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
7172 } 7174 }
7173 7175
7174 v8::Debug::DebugBreak(); 7176 v8::Debug::DebugBreak();
7175 } 7177 }
7176 } 7178 }
7177 7179
7178 7180
7179 // Test deoptimization when execution is broken using the debug break stack 7181 // Test deoptimization when execution is broken using the debug break stack
7180 // check interrupt. 7182 // check interrupt.
7181 TEST(DeoptimizeDuringDebugBreak) { 7183 TEST(DeoptimizeDuringDebugBreak) {
7182 v8::HandleScope scope;
7183 DebugLocalContext env; 7184 DebugLocalContext env;
7185 v8::HandleScope scope(env->GetIsolate());
7184 env.ExposeDebug(); 7186 env.ExposeDebug();
7185 7187
7186 // Create a function for checking the function when hitting a break point. 7188 // Create a function for checking the function when hitting a break point.
7187 frame_function_name = CompileFunction(&env, 7189 frame_function_name = CompileFunction(&env,
7188 frame_function_name_source, 7190 frame_function_name_source,
7189 "frame_function_name"); 7191 "frame_function_name");
7190 7192
7191 7193
7192 // Set a debug event listener which will keep interrupting execution until 7194 // Set a debug event listener which will keep interrupting execution until
7193 // debug break. When inside function bar it will deoptimize all functions. 7195 // debug break. When inside function bar it will deoptimize all functions.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7259 7261
7260 static v8::Handle<v8::Value> ScheduleBreak(const v8::Arguments& args) { 7262 static v8::Handle<v8::Value> ScheduleBreak(const v8::Arguments& args) {
7261 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack, 7263 v8::Debug::SetDebugEventListener(DebugEventBreakWithOptimizedStack,
7262 v8::Undefined()); 7264 v8::Undefined());
7263 v8::Debug::DebugBreak(); 7265 v8::Debug::DebugBreak();
7264 return v8::Undefined(); 7266 return v8::Undefined();
7265 } 7267 }
7266 7268
7267 7269
7268 TEST(DebugBreakStackInspection) { 7270 TEST(DebugBreakStackInspection) {
7269 v8::HandleScope scope;
7270 DebugLocalContext env; 7271 DebugLocalContext env;
7272 v8::HandleScope scope(env->GetIsolate());
7271 7273
7272 frame_function_name = 7274 frame_function_name =
7273 CompileFunction(&env, frame_function_name_source, "frame_function_name"); 7275 CompileFunction(&env, frame_function_name_source, "frame_function_name");
7274 frame_argument_name = 7276 frame_argument_name =
7275 CompileFunction(&env, frame_argument_name_source, "frame_argument_name"); 7277 CompileFunction(&env, frame_argument_name_source, "frame_argument_name");
7276 frame_argument_value = CompileFunction(&env, 7278 frame_argument_value = CompileFunction(&env,
7277 frame_argument_value_source, 7279 frame_argument_value_source,
7278 "frame_argument_value"); 7280 "frame_argument_value");
7279 frame_local_name = 7281 frame_local_name =
7280 CompileFunction(&env, frame_local_name_source, "frame_local_name"); 7282 CompileFunction(&env, frame_local_name_source, "frame_local_name");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
7332 CompileRun("f();"); 7334 CompileRun("f();");
7333 CHECK_EQ(kBreaksPerTest, break_point_hit_count); 7335 CHECK_EQ(kBreaksPerTest, break_point_hit_count);
7334 7336
7335 CHECK(!v8::V8::IsExecutionTerminating()); 7337 CHECK(!v8::V8::IsExecutionTerminating());
7336 } 7338 }
7337 } 7339 }
7338 } 7340 }
7339 7341
7340 7342
7341 TEST(DebugBreakLoop) { 7343 TEST(DebugBreakLoop) {
7342 v8::HandleScope scope;
7343 DebugLocalContext env; 7344 DebugLocalContext env;
7345 v8::HandleScope scope(env->GetIsolate());
7344 7346
7345 // Register a debug event listener which sets the break flag and counts. 7347 // Register a debug event listener which sets the break flag and counts.
7346 v8::Debug::SetDebugEventListener(DebugEventBreakMax); 7348 v8::Debug::SetDebugEventListener(DebugEventBreakMax);
7347 7349
7348 // Create a function for getting the frame count when hitting the break. 7350 // Create a function for getting the frame count when hitting the break.
7349 frame_count = CompileFunction(&env, frame_count_source, "frame_count"); 7351 frame_count = CompileFunction(&env, frame_count_source, "frame_count");
7350 7352
7351 CompileRun("var a = 1;"); 7353 CompileRun("var a = 1;");
7352 CompileRun("function g() { }"); 7354 CompileRun("function g() { }");
7353 CompileRun("function h() { }"); 7355 CompileRun("function h() { }");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7414 CHECK_EQ(expected_line_number[i], 7416 CHECK_EQ(expected_line_number[i],
7415 i::GetScriptLineNumber(source_script, result->Int32Value())); 7417 i::GetScriptLineNumber(source_script, result->Int32Value()));
7416 } 7418 }
7417 v8::Debug::SetDebugEventListener(NULL); 7419 v8::Debug::SetDebugEventListener(NULL);
7418 v8::V8::TerminateExecution(); 7420 v8::V8::TerminateExecution();
7419 } 7421 }
7420 7422
7421 7423
7422 TEST(DebugBreakInline) { 7424 TEST(DebugBreakInline) {
7423 i::FLAG_allow_natives_syntax = true; 7425 i::FLAG_allow_natives_syntax = true;
7424 v8::HandleScope scope;
7425 DebugLocalContext env; 7426 DebugLocalContext env;
7427 v8::HandleScope scope(env->GetIsolate());
7426 const char* source = 7428 const char* source =
7427 "function debug(b) { \n" 7429 "function debug(b) { \n"
7428 " if (b) debugger; \n" 7430 " if (b) debugger; \n"
7429 "} \n" 7431 "} \n"
7430 "function f(b) { \n" 7432 "function f(b) { \n"
7431 " debug(b) \n" 7433 " debug(b) \n"
7432 "}; \n" 7434 "}; \n"
7433 "function g(b) { \n" 7435 "function g(b) { \n"
7434 " f(b); \n" 7436 " f(b); \n"
7435 "}; \n" 7437 "}; \n"
(...skipping 26 matching lines...) Expand all
7462 7464
7463 TEST(Regress131642) { 7465 TEST(Regress131642) {
7464 // Bug description: 7466 // Bug description:
7465 // When doing StepNext through the first script, the debugger is not reset 7467 // When doing StepNext through the first script, the debugger is not reset
7466 // after exiting through exception. A flawed implementation enabling the 7468 // after exiting through exception. A flawed implementation enabling the
7467 // debugger to step into Array.prototype.forEach breaks inside the callback 7469 // debugger to step into Array.prototype.forEach breaks inside the callback
7468 // for forEach in the second script under the assumption that we are in a 7470 // for forEach in the second script under the assumption that we are in a
7469 // recursive call. In an attempt to step out, we crawl the stack using the 7471 // recursive call. In an attempt to step out, we crawl the stack using the
7470 // recorded frame pointer from the first script and fail when not finding it 7472 // recorded frame pointer from the first script and fail when not finding it
7471 // on the stack. 7473 // on the stack.
7472 v8::HandleScope scope;
7473 DebugLocalContext env; 7474 DebugLocalContext env;
7475 v8::HandleScope scope(env->GetIsolate());
7474 v8::Debug::SetDebugEventListener(DebugEventStepNext); 7476 v8::Debug::SetDebugEventListener(DebugEventStepNext);
7475 7477
7476 // We step through the first script. It exits through an exception. We run 7478 // We step through the first script. It exits through an exception. We run
7477 // this inside a new frame to record a different FP than the second script 7479 // this inside a new frame to record a different FP than the second script
7478 // would expect. 7480 // would expect.
7479 const char* script_1 = "debugger; throw new Error();"; 7481 const char* script_1 = "debugger; throw new Error();";
7480 RunScriptInANewCFrame(script_1); 7482 RunScriptInANewCFrame(script_1);
7481 7483
7482 // The second script uses forEach. 7484 // The second script uses forEach.
7483 const char* script_2 = "[0].forEach(function() { });"; 7485 const char* script_2 = "[0].forEach(function() { });";
7484 CompileRun(script_2); 7486 CompileRun(script_2);
7485 7487
7486 v8::Debug::SetDebugEventListener(NULL); 7488 v8::Debug::SetDebugEventListener(NULL);
7487 } 7489 }
7488 7490
7489 7491
7490 // Import from test-heap.cc 7492 // Import from test-heap.cc
7491 int CountNativeContexts(); 7493 int CountNativeContexts();
7492 7494
7493 7495
7494 static void NopListener(v8::DebugEvent event, 7496 static void NopListener(v8::DebugEvent event,
7495 v8::Handle<v8::Object> exec_state, 7497 v8::Handle<v8::Object> exec_state,
7496 v8::Handle<v8::Object> event_data, 7498 v8::Handle<v8::Object> event_data,
7497 v8::Handle<v8::Value> data) { 7499 v8::Handle<v8::Value> data) {
7498 } 7500 }
7499 7501
7500 7502
7501 TEST(DebuggerCreatesContextIffActive) { 7503 TEST(DebuggerCreatesContextIffActive) {
7502 v8::HandleScope scope;
7503 DebugLocalContext env; 7504 DebugLocalContext env;
7505 v8::HandleScope scope(env->GetIsolate());
7504 CHECK_EQ(1, CountNativeContexts()); 7506 CHECK_EQ(1, CountNativeContexts());
7505 7507
7506 v8::Debug::SetDebugEventListener(NULL); 7508 v8::Debug::SetDebugEventListener(NULL);
7507 CompileRun("debugger;"); 7509 CompileRun("debugger;");
7508 CHECK_EQ(1, CountNativeContexts()); 7510 CHECK_EQ(1, CountNativeContexts());
7509 7511
7510 v8::Debug::SetDebugEventListener(NopListener); 7512 v8::Debug::SetDebugEventListener(NopListener);
7511 CompileRun("debugger;"); 7513 CompileRun("debugger;");
7512 CHECK_EQ(2, CountNativeContexts()); 7514 CHECK_EQ(2, CountNativeContexts());
7513 7515
7514 v8::Debug::SetDebugEventListener(NULL); 7516 v8::Debug::SetDebugEventListener(NULL);
7515 } 7517 }
7516 7518
7517 7519
7518 TEST(LiveEditEnabled) { 7520 TEST(LiveEditEnabled) {
7519 v8::internal::FLAG_allow_natives_syntax = true; 7521 v8::internal::FLAG_allow_natives_syntax = true;
7520 v8::HandleScope scope; 7522 LocalContext env;
7521 LocalContext context; 7523 v8::HandleScope scope(env->GetIsolate());
7522 v8::Debug::SetLiveEditEnabled(true); 7524 v8::Debug::SetLiveEditEnabled(true);
7523 CompileRun("%LiveEditCompareStrings('', '')"); 7525 CompileRun("%LiveEditCompareStrings('', '')");
7524 } 7526 }
7525 7527
7526 7528
7527 TEST(LiveEditDisabled) { 7529 TEST(LiveEditDisabled) {
7528 v8::internal::FLAG_allow_natives_syntax = true; 7530 v8::internal::FLAG_allow_natives_syntax = true;
7529 v8::HandleScope scope; 7531 LocalContext env;
7530 LocalContext context; 7532 v8::HandleScope scope(env->GetIsolate());
7531 v8::Debug::SetLiveEditEnabled(false); 7533 v8::Debug::SetLiveEditEnabled(false);
7532 CompileRun("%LiveEditCompareStrings('', '')"); 7534 CompileRun("%LiveEditCompareStrings('', '')");
7533 } 7535 }
7534 7536
7535 7537
7536 #endif // ENABLE_DEBUGGER_SUPPORT 7538 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698