OLD | NEW |
| (Empty) |
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 | |
31 Debug = debug.Debug | |
32 Debug.setListener(function(){}); | |
33 | |
34 var function_z_text = | |
35 " function Z() {\n" | |
36 + " return 'Z';\n" // Breakpoint line ( #6 ) | |
37 + " }\n"; | |
38 | |
39 eval( | |
40 "function F25() {\n" | |
41 + " return 25;\n" // Breakpoint line ( #1 ) | |
42 + "}\n" | |
43 + "function F26 () {\n" | |
44 + " var x = 20;\n" | |
45 + function_z_text // function takes exactly 3 lines | |
46 // // Breakpoint line ( #6 ) | |
47 // | |
48 + " var y = 6;\n" | |
49 + " return x + y;\n" | |
50 + "}\n" | |
51 + "function Nested() {\n" | |
52 + " var a = 30;\n" | |
53 + " return function F27() {\n" | |
54 + " var b = 3;\n" // Breakpoint line ( #14 ) | |
55 + " return a - b;\n" | |
56 + " }\n" | |
57 + "}\n" | |
58 ); | |
59 | |
60 | |
61 assertEquals(25, F25()); | |
62 assertEquals(26, F26()); | |
63 | |
64 var script = Debug.findScript(F25); | |
65 | |
66 assertEquals(0, Debug.scriptBreakPoints().length); | |
67 | |
68 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 1, 1,
"true || false || false"); | |
69 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 6, 1,
"true || false || false"); | |
70 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, script.id, 14, 1,
"true || false || false"); | |
71 | |
72 assertEquals(3, Debug.scriptBreakPoints().length); | |
73 | |
74 var new_source = script.source.replace(function_z_text, ""); | |
75 print("new source: " + new_source); | |
76 | |
77 var change_log = new Array(); | |
78 var result = Debug.LiveEdit.SetScriptSource(script, new_source, false, change_lo
g); | |
79 print("Result: " + JSON.stringify(result) + "\n"); | |
80 print("Change log: " + JSON.stringify(change_log) + "\n"); | |
81 | |
82 var breaks = Debug.scriptBreakPoints(); | |
83 | |
84 // One breakpoint gets duplicated in a old version of script. | |
85 assertTrue(breaks.length > 3 + 1); | |
86 | |
87 var breakpoints_in_script = 0; | |
88 var break_position_map = {}; | |
89 for (var i = 0; i < breaks.length; i++) { | |
90 if (breaks[i].script_id() == script.id) { | |
91 break_position_map[breaks[i].line()] = true; | |
92 breakpoints_in_script++; | |
93 } | |
94 } | |
95 | |
96 assertEquals(3, breakpoints_in_script); | |
97 | |
98 // Check 2 breakpoints. The one in deleted function should have been moved somew
here. | |
99 assertTrue(break_position_map[1]); | |
100 assertTrue(break_position_map[11]); | |
101 | |
102 // Delete all breakpoints to make this test reentrant. | |
103 var breaks = Debug.scriptBreakPoints(); | |
104 var breaks_ids = []; | |
105 | |
106 for (var i = 0; i < breaks.length; i++) { | |
107 breaks_ids.push(breaks[i].number()); | |
108 } | |
109 | |
110 for (var i = 0; i < breaks_ids.length; i++) { | |
111 Debug.clearBreakPoint(breaks_ids[i]); | |
112 } | |
113 | |
114 assertEquals(0, Debug.scriptBreakPoints().length); | |
115 Debug.setListener(null); | |
OLD | NEW |