debug-liveedit-breakpoints.js revision 8defd9ff6930b4e24729971a61cf7469daf119be
1// Copyright 2010 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Flags: --expose-debug-as debug 29// Get the Debug object exposed from the debug context global object. 30 31Debug = debug.Debug 32 33var function_z_text = 34" function Z() {\n" 35+ " return 'Z';\n" // Breakpoint line ( #6 ) 36+ " }\n"; 37 38eval( 39"function F25() {\n" 40+ " return 25;\n" // Breakpoint line ( #1 ) 41+ "}\n" 42+ "function F26 () {\n" 43+ " var x = 20;\n" 44+ function_z_text // function takes exactly 3 lines 45// // Breakpoint line ( #6 ) 46// 47+ " var y = 6;\n" 48+ " return x + y;\n" 49+ "}\n" 50+ "function Nested() {\n" 51+ " var a = 30;\n" 52+ " return function F27() {\n" 53+ " var b = 3;\n" // Breakpoint line ( #14 ) 54+ " return a - b;\n" 55+ " }\n" 56+ "}\n" 57); 58 59 60assertEquals(25, F25()); 61assertEquals(26, F26()); 62 63var script = Debug.findScript(F25); 64 65Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 1, 1, "true || false || false"); 66Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 6, 1, "true || false || false"); 67Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 14, 1, "true || false || false"); 68 69assertEquals(3, Debug.scriptBreakPoints().length); 70 71var new_source = script.source.replace(function_z_text, ""); 72print("new source: " + new_source); 73 74var change_log = new Array(); 75var result = Debug.LiveEdit.SetScriptSource(script, new_source, false, change_log); 76print("Result: " + JSON.stringify(result) + "\n"); 77print("Change log: " + JSON.stringify(change_log) + "\n"); 78 79var breaks = Debug.scriptBreakPoints(); 80 81// One breakpoint gets duplicated in a old version of script. 82assertTrue(breaks.length > 3 + 1); 83 84var breakpoints_in_script = 0; 85var break_position_map = {}; 86for (var i = 0; i < breaks.length; i++) { 87 if (breaks[i].script_id() == script.id) { 88 break_position_map[breaks[i].line()] = true; 89 breakpoints_in_script++; 90 } 91} 92 93assertEquals(3, breakpoints_in_script); 94 95// Check 2 breakpoints. The one in deleted function should have been moved somewhere. 96assertTrue(break_position_map[1]); 97assertTrue(break_position_map[11]); 98 99