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
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.
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.
28 // Flags: --expose-debug-as debug
29 // Get the Debug object exposed from the debug context global object.
35 + " return 'Z';\n" // Breakpoint line ( #6 )
40 + " return 25;\n" // Breakpoint line ( #1 )
42 + "function F26 () {\n"
44 + function_z_text // function takes exactly 3 lines
45 // // Breakpoint line ( #6 )
50 + "function Nested() {\n"
52 + " return function F27() {\n"
53 + " var b = 3;\n" // Breakpoint line ( #14 )
60 assertEquals(25, F25());
61 assertEquals(26, F26());
63 var script = Debug.findScript(F25);
65 assertEquals(0, Debug.scriptBreakPoints().length);
67 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 1, 1, "true || false || false");
68 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 6, 1, "true || false || false");
69 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 14, 1, "true || false || false");
71 assertEquals(3, Debug.scriptBreakPoints().length);
73 var new_source = script.source.replace(function_z_text, "");
74 print("new source: " + new_source);
76 var change_log = new Array();
77 var result = Debug.LiveEdit.SetScriptSource(script, new_source, false, change_log);
78 print("Result: " + JSON.stringify(result) + "\n");
79 print("Change log: " + JSON.stringify(change_log) + "\n");
81 var breaks = Debug.scriptBreakPoints();
83 // One breakpoint gets duplicated in a old version of script.
84 assertTrue(breaks.length > 3 + 1);
86 var breakpoints_in_script = 0;
87 var break_position_map = {};
88 for (var i = 0; i < breaks.length; i++) {
89 if (breaks[i].script_id() == script.id) {
90 break_position_map[breaks[i].line()] = true;
91 breakpoints_in_script++;
95 assertEquals(3, breakpoints_in_script);
97 // Check 2 breakpoints. The one in deleted function should have been moved somewhere.
98 assertTrue(break_position_map[1]);
99 assertTrue(break_position_map[11]);
101 // Delete all breakpoints to make this test reentrant.
102 var breaks = Debug.scriptBreakPoints();
105 for (var i = 0; i < breaks.length; i++) {
106 breaks_ids.push(breaks[i].number());
109 for (var i = 0; i < breaks_ids.length; i++) {
110 Debug.clearBreakPoint(breaks_ids[i]);
113 assertEquals(0, Debug.scriptBreakPoints().length);