Fix a bug when top level break points fall into the last function in script.

Review URL: http://codereview.chromium.org/2824007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4890 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d1c60571
......@@ -9081,8 +9081,6 @@ Object* Runtime::FindSharedFunctionInfoInScript(Handle<Script> script,
// The current candidate for the source position:
int target_start_position = RelocInfo::kNoPosition;
Handle<SharedFunctionInfo> target;
// The current candidate for the last function in script:
Handle<SharedFunctionInfo> last;
while (!done) {
HeapIterator iterator;
for (HeapObject* obj = iterator.next();
......@@ -9123,26 +9121,13 @@ Object* Runtime::FindSharedFunctionInfoInScript(Handle<Script> script,
}
}
}
// Keep track of the last function in the script.
if (last.is_null() ||
shared->end_position() > last->start_position()) {
last = shared;
}
}
}
}
// Make sure some candidate is selected.
if (target.is_null()) {
if (!last.is_null()) {
// Position after the last function - use last.
target = last;
} else {
// Unable to find function - possibly script without any function.
return Heap::undefined_value();
}
}
// If the candidate found is compiled we are done. NOTE: when lazy
// compilation of inner functions is introduced some additional checking
......
......@@ -2028,6 +2028,51 @@ TEST(ScriptBreakPointLine) {
}
// Test top level script break points set on lines.
TEST(ScriptBreakPointLineTopLevel) {
v8::HandleScope scope;
DebugLocalContext env;
env.ExposeDebug();
v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
v8::Undefined());
v8::Local<v8::String> script = v8::String::New(
"function f() {\n"
" a = 1; // line 1\n"
"}\n"
"a = 2; // line 3\n");
v8::Local<v8::Function> f;
{
v8::HandleScope scope;
v8::Script::Compile(script, v8::String::New("test.html"))->Run();
}
f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
Heap::CollectAllGarbage(false);
SetScriptBreakPointByNameFromJS("test.html", 3, -1);
// Call f and check that there was no break points.
break_point_hit_count = 0;
f->Call(env->Global(), 0, NULL);
CHECK_EQ(0, break_point_hit_count);
// Recompile and run script and check that break point was hit.
break_point_hit_count = 0;
v8::Script::Compile(script, v8::String::New("test.html"))->Run();
CHECK_EQ(1, break_point_hit_count);
// Call f and check that there are still no break points.
break_point_hit_count = 0;
f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
CHECK_EQ(0, break_point_hit_count);
v8::Debug::SetDebugEventListener(NULL);
CheckDebuggerUnloaded();
}
// Test that it is possible to remove the last break point for a function
// inside the break handling of that break point.
TEST(RemoveBreakPointInBreak) {
......
......@@ -116,7 +116,7 @@ function listener(event, exec_state, event_data, data) {
mirror = debug.MakeMirror(o.a);
testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', true, false);
testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":1}', true, true);
testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":0}', true, true);
// Indicate that all was processed.
listenerComplete = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment