diff --git a/src/debug-debugger.js b/src/debug-debugger.js index d9e0ecdd56..ccec6af2fc 100644 --- a/src/debug-debugger.js +++ b/src/debug-debugger.js @@ -124,6 +124,12 @@ BreakPoint.prototype.source_position = function() { }; +BreakPoint.prototype.updateSourcePosition = function(new_position, script) { + this.source_position_ = new_position; + // TODO(635): also update line and column. +}; + + BreakPoint.prototype.hit_count = function() { return this.hit_count_; }; diff --git a/src/liveedit-debugger.js b/src/liveedit-debugger.js index 75effb227f..6ef7a2daed 100644 --- a/src/liveedit-debugger.js +++ b/src/liveedit-debugger.js @@ -180,11 +180,18 @@ Debug.LiveEditChangeScript = function(script, change_pos, change_len, new_str, var position_patch_report; function PatchPositions(new_info, shared_info) { if (!shared_info) { - // TODO: explain what is happening. + // TODO(LiveEdit): explain what is happening. return; } - %LiveEditPatchFunctionPositions(shared_info.raw_array, - position_change_array); + var breakpoint_position_update = %LiveEditPatchFunctionPositions( + shared_info.raw_array, position_change_array); + for (var i = 0; i < breakpoint_position_update.length; i += 2) { + var new_pos = breakpoint_position_update[i]; + var break_point_object = breakpoint_position_update[i + 1]; + change_log.push( { breakpoint_position_update: + { from: break_point_object.source_position(), to: new_pos } } ); + break_point_object.updateSourcePosition(new_pos, script); + } position_patch_report.push( { name: new_info.function_name } ); } diff --git a/src/liveedit.cc b/src/liveedit.cc index 22a26a32dc..8e02b5d9e8 100644 --- a/src/liveedit.cc +++ b/src/liveedit.cc @@ -644,13 +644,28 @@ static Handle PatchPositionsInCode(Handle code, } -void LiveEdit::PatchFunctionPositions(Handle shared_info_array, - Handle position_change_array) { +static Handle GetBreakPointObjectsForJS( + Handle break_point_info) { + if (break_point_info->break_point_objects()->IsFixedArray()) { + Handle fixed_array( + FixedArray::cast(break_point_info->break_point_objects())); + Handle array = Factory::NewJSArrayWithElements(fixed_array); + return array; + } else { + return Handle(break_point_info->break_point_objects()); + } +} + + +Handle LiveEdit::PatchFunctionPositions( + Handle shared_info_array, Handle position_change_array) { SharedInfoWrapper shared_info_wrapper(shared_info_array); Handle info = shared_info_wrapper.GetInfo(); - info->set_start_position(TranslatePosition(info->start_position(), - position_change_array)); + int old_function_start = info->start_position(); + int new_function_start = TranslatePosition(old_function_start, + position_change_array); + info->set_start_position(new_function_start); info->set_end_position(TranslatePosition(info->end_position(), position_change_array)); @@ -672,6 +687,10 @@ void LiveEdit::PatchFunctionPositions(Handle shared_info_array, } } + + Handle result = Factory::NewJSArray(0); + int result_len = 0; + if (info->debug_info()->IsDebugInfo()) { Handle debug_info(DebugInfo::cast(info->debug_info())); Handle patched_orig_code = @@ -690,12 +709,22 @@ void LiveEdit::PatchFunctionPositions(Handle shared_info_array, } Handle info( BreakPointInfo::cast(break_point_infos->get(i))); - int new_position = TranslatePosition(info->source_position()->value(), + int old_in_script_position = info->source_position()->value() + + old_function_start; + int new_in_script_position = TranslatePosition(old_in_script_position, position_change_array); - info->set_source_position(Smi::FromInt(new_position)); + info->set_source_position( + Smi::FromInt(new_in_script_position - new_function_start)); + if (old_in_script_position != new_in_script_position) { + SetElement(result, result_len, + Handle(Smi::FromInt(new_in_script_position))); + SetElement(result, result_len + 1, + GetBreakPointObjectsForJS(info)); + result_len += 2; + } } } - // TODO(635): Also patch breakpoint objects in JS. + return result; } diff --git a/src/liveedit.h b/src/liveedit.h index bd4c1ee85a..a81bacfb70 100644 --- a/src/liveedit.h +++ b/src/liveedit.h @@ -88,8 +88,10 @@ class LiveEdit : AllStatic { static void RelinkFunctionToScript(Handle shared_info_array, Handle