📄 test-debug.cc.svn-base
字号:
// Now set a function break point int bp7 = SetBreakPointFromJS("g", 0, 0); g->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); // Reload the script and get g again checking that the break point survives. // This tests that the function break point was converted to a script break // point. v8::Script::Compile(script, &origin)->Run(); g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); g->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount); // Make sure that the break point numbers are consecutive. CHECK_EQ(1, sbp1); CHECK_EQ(2, sbp2); CHECK_EQ(3, sbp3); CHECK_EQ(4, sbp4); CHECK_EQ(5, sbp5); CHECK_EQ(6, sbp6); CHECK_EQ(7, bp7);}// Test conditional script break points.TEST(EnableDisableScriptBreakPoint) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::String> script = v8::String::New( "function f() {\n" " a = 0; // line 1\n" "};"); // Compile the script and get function f. v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); v8::Script::Compile(script, &origin)->Run(); v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Set script break point on line 1 (in function f). int sbp = SetScriptBreakPointFromJS("test", 1, 0); // Call f while enabeling and disabling the script break point. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); DisableScriptBreakPointFromJS(sbp); f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); EnableScriptBreakPointFromJS(sbp); f->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); DisableScriptBreakPointFromJS(sbp); f->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); // Reload the script and get f again checking that the disabeling survives. v8::Script::Compile(script, &origin)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); f->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); EnableScriptBreakPointFromJS(sbp); f->Call(env->Global(), 0, NULL); CHECK_EQ(3, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test conditional script break points.TEST(ConditionalScriptBreakPoint) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::String> script = v8::String::New( "count = 0;\n" "function f() {\n" " g(count++); // line 2\n" "};\n" "function g(x) {\n" " var a=x; // line 5\n" "};"); // Compile the script and get function f. v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); v8::Script::Compile(script, &origin)->Run(); v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Set script break point on line 5 (in function g). int sbp1 = SetScriptBreakPointFromJS("test", 5, 0); // Call f with different conditions on the script break point. break_point_hit_count = 0; ChangeScriptBreakPointConditionFromJS(sbp1, "false"); f->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); ChangeScriptBreakPointConditionFromJS(sbp1, "true"); break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); ChangeScriptBreakPointConditionFromJS(sbp1, "a % 2 == 0"); break_point_hit_count = 0; for (int i = 0; i < 10; i++) { f->Call(env->Global(), 0, NULL); } CHECK_EQ(5, break_point_hit_count); // Reload the script and get f again checking that the condition survives. v8::Script::Compile(script, &origin)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); break_point_hit_count = 0; for (int i = 0; i < 10; i++) { f->Call(env->Global(), 0, NULL); } CHECK_EQ(5, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test ignore count on script break points.TEST(ScriptBreakPointIgnoreCount) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::String> script = v8::String::New( "function f() {\n" " a = 0; // line 1\n" "};"); // Compile the script and get function f. v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); v8::Script::Compile(script, &origin)->Run(); v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Set script break point on line 1 (in function f). int sbp = SetScriptBreakPointFromJS("test", 1, 0); // Call f with different ignores on the script break point. break_point_hit_count = 0; ChangeScriptBreakPointIgnoreCountFromJS(sbp, 1); f->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); ChangeScriptBreakPointIgnoreCountFromJS(sbp, 5); break_point_hit_count = 0; for (int i = 0; i < 10; i++) { f->Call(env->Global(), 0, NULL); } CHECK_EQ(5, break_point_hit_count); // Reload the script and get f again checking that the ignore survives. v8::Script::Compile(script, &origin)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); break_point_hit_count = 0; for (int i = 0; i < 10; i++) { f->Call(env->Global(), 0, NULL); } CHECK_EQ(5, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test that script break points survive when a script is reloaded.TEST(ScriptBreakPointReload) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::Function> f; v8::Local<v8::String> script = v8::String::New( "function f() {\n" " function h() {\n" " a = 0; // line 2\n" " }\n" " b = 1; // line 4\n" " return h();\n" "}"); v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8::String::New("1")); v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8::String::New("2")); // Set a script break point before the script is loaded. SetScriptBreakPointFromJS("1", 2, 0); // Compile the script and get the function. v8::Script::Compile(script, &origin_1)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Call f and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); // Compile the script again with a different script data and get the // function. v8::Script::Compile(script, &origin_2)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Call f and check that no break points are set. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); // Compile the script again and get the function. v8::Script::Compile(script, &origin_1)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Call f and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test when several scripts has the same script dataTEST(ScriptBreakPointMultiple) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::Function> f; v8::Local<v8::String> script_f = v8::String::New( "function f() {\n" " a = 0; // line 1\n" "}"); v8::Local<v8::Function> g; v8::Local<v8::String> script_g = v8::String::New( "function g() {\n" " b = 0; // line 1\n" "}"); v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); // Set a script break point before the scripts are loaded. int sbp = SetScriptBreakPointFromJS("test", 1, 0); // Compile the scripts with same script data and get the functions. v8::Script::Compile(script_f, &origin)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); v8::Script::Compile(script_g, &origin)->Run(); g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); // Call f and g and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); g->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); // Clear the script break point. ClearBreakPointFromJS(sbp); // Call f and g and check that the script break point is no longer active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); g->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); // Set script break point with the scripts loaded. sbp = SetScriptBreakPointFromJS("test", 1, 0); // Call f and g and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); g->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test the script origin which has both name and line offset.TEST(ScriptBreakPointLineOffset) { break_point_hit_count = 0; v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug(); v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); v8::Local<v8::Function> f; v8::Local<v8::String> script = v8::String::New( "function f() {\n" " a = 0; // line 8 as this script has line offset 7\n" " b = 0; // line 9 as this script has line offset 7\n" "}"); // Create script origin both name and line offset. v8::ScriptOrigin origin(v8::String::New("test.html"), v8::Integer::New(7)); // Set two script break points before the script is loaded. int sbp1 = SetScriptBreakPointFromJS("test.html", 8, 0); int sbp2 = SetScriptBreakPointFromJS("test.html", 9, 0); // Compile the script and get the function. v8::Script::Compile(script, &origin)->Run(); f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); // Call f and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(2, break_point_hit_count); // Clear the script break points. ClearBreakPointFromJS(sbp1); ClearBreakPointFromJS(sbp2); // Call f and check that no script break points are active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(0, break_point_hit_count); // Set a script break point with the script loaded. sbp1 = SetScriptBreakPointFromJS("test.html", 9, 0); // Call f and check that the script break point is active. break_point_hit_count = 0; f->Call(env->Global(), 0, NULL); CHECK_EQ(1, break_point_hit_count); v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test script break points set on lines.TEST(ScriptBreakPointLine) { v8::HandleScope scope; DebugLocalContext env; env.ExposeDebug();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -