From 30b85b39624d11a0ce801335cb4eac6b1efa72d8 Mon Sep 17 00:00:00 2001 From: "peter.rybin@gmail.com" Date: Fri, 23 Jul 2010 17:21:55 +0000 Subject: [PATCH] Fix break position not to be outside of the script Review URL: http://codereview.chromium.org/3017021 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5131 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/runtime.cc | 7 +++++++ test/mjsunit/debug-setbreakpoint.js | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/runtime.cc b/src/runtime.cc index 0330abd..a6924a0 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -9381,6 +9381,13 @@ static Object* Runtime_SetScriptBreakPoint(Arguments args) { } Debug::SetBreakPoint(shared, break_point_object_arg, &position); position += shared->start_position(); + + // The result position may become beyond script source end. + // This is expected when the function is toplevel. This may become + // a problem later when actual position gets converted into line/column. + if (shared->is_toplevel() && position == shared->end_position()) { + position = shared->end_position() - 1; + } return Smi::FromInt(position); } return Heap::undefined_value(); diff --git a/test/mjsunit/debug-setbreakpoint.js b/test/mjsunit/debug-setbreakpoint.js index 8201d63..90dfcd1 100644 --- a/test/mjsunit/debug-setbreakpoint.js +++ b/test/mjsunit/debug-setbreakpoint.js @@ -192,3 +192,26 @@ Debug.setListener(breakListener); sourceUrlFunc(); assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by sourceURL"); + + +// Breakpoint in a script with no statements test case. If breakpoint is set +// to the script body, its actual position is taken from the nearest statement +// below or like in this case is reset to the very end of the script. +// Unless some precautions made, this position becomes out-of-range and +// we get an exception. + +// Gets a script of 'i1' function and sets the breakpoint at line #4 which +// should be empty. +function SetBreakpointInI1Script() { + var i_script = Debug.findScript(i1); + assertTrue(!!i_script, "invalid script for i1"); + Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, + i_script.id, 4); +} + +// Creates the eval script and tries to set the breakpoint. +// The tricky part is that the script function must be strongly reachable at the +// moment. Since there's no way of simply getting the pointer to the function, +// we run this code while the script function is being activated on stack. +eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); + -- 2.7.4