OLD | NEW |
---|---|
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug --nocrankshaft | 28 // Flags: --expose-debug-as debug --nocrankshaft |
29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
30 Debug = debug.Debug | 30 Debug = debug.Debug |
31 | 31 |
32 function DebuggerStatement() { | 32 function DebuggerStatement() { |
33 debugger; | 33 debugger; /*pause*/ |
34 } | 34 } |
35 | 35 |
36 function TestCase(fun) { | 36 function TestCase(fun, frame_number) { |
37 var exception = false; | 37 var exception = false; |
38 var codeSnippet = undefined; | 38 var codeSnippet = undefined; |
39 var resultPositions = undefined; | 39 var resultPositions = undefined; |
40 | 40 |
41 function listener(event, exec_state, event_data, data) { | 41 function listener(event, exec_state, event_data, data) { |
42 try { | 42 try { |
43 if (event == Debug.DebugEvent.Break) { | 43 if (event == Debug.DebugEvent.Break || event == Debug.DebugEvent.Exception ) { |
Yang
2013/08/26 13:52:02
80 char limit.
Peter.Rybin
2013/08/31 16:58:07
Done.
| |
44 Debug.setListener(null); | 44 Debug.setListener(null); |
45 | 45 assertHasLineMark(/pause/, exec_state.frame(0)); |
46 var secondFrame = exec_state.frame(1); | 46 assertHasLineMark(/positions/, exec_state.frame(frame_number)); |
47 codeSnippet = secondFrame.sourceLineText(); | 47 var frame = exec_state.frame(frame_number); |
48 resultPositions = secondFrame.stepInPositions(); | 48 codeSnippet = frame.sourceLineText(); |
49 resultPositions = frame.stepInPositions(); | |
49 } | 50 } |
50 } catch (e) { | 51 } catch (e) { |
51 exception = e | 52 exception = e |
52 } | 53 } |
54 | |
55 function assertHasLineMark(mark, frame) { | |
56 var line = frame.sourceLineText(); | |
57 if (!mark.exec(frame.sourceLineText())) { | |
58 throw new Error("Line " + line + " should contain mark " + mark); | |
59 } | |
60 } | |
53 } | 61 } |
54 | 62 |
55 Debug.setListener(listener); | 63 Debug.setListener(listener); |
56 | 64 |
57 fun(); | 65 fun(); |
58 | 66 |
59 Debug.setListener(null); | 67 Debug.setListener(null); |
60 | 68 |
61 assertTrue(!exception, exception); | 69 assertTrue(!exception, exception); |
62 | 70 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 print(decoratedResult); | 102 print(decoratedResult); |
95 | 103 |
96 for (var n in expectedPositions) { | 104 for (var n in expectedPositions) { |
97 assertTrue(false, "Some positions are not reported: " + decoratedResult); | 105 assertTrue(false, "Some positions are not reported: " + decoratedResult); |
98 break; | 106 break; |
99 } | 107 } |
100 assertFalse(unexpectedPositionFound, "Found unexpected position: " + | 108 assertFalse(unexpectedPositionFound, "Found unexpected position: " + |
101 decoratedResult); | 109 decoratedResult); |
102 } | 110 } |
103 | 111 |
112 function TestCaseWithDebugger(fun) { | |
113 TestCase(fun, 1); | |
114 } | |
115 | |
116 function TestCaseWithBreakpoint(fun, line_number, frame_number) { | |
117 var breakpointId = Debug.setBreakPoint(fun, line_number); | |
118 TestCase(fun, frame_number); | |
119 Debug.clearBreakPoint(breakpointId); | |
120 } | |
121 | |
122 function TestCaseWithException(fun, frame_number) { | |
123 Debug.setBreakOnException(); | |
124 TestCase(fun, frame_number); | |
125 Debug.clearBreakOnException(); | |
126 } | |
127 | |
104 | 128 |
105 // Test cases. | 129 // Test cases. |
106 | 130 |
131 // Step in position, when the function call that we are standing at is already | |
132 // being executed. | |
133 var fun = function() { | |
134 function g(p) { | |
135 throw String(p); /*pause*/ | |
136 } | |
137 try { | |
138 var res = [ g(1), /*#*/g(2) ]; /*positions*/ | |
139 } catch (e) { | |
140 } | |
141 }; | |
142 TestCaseWithBreakpoint(fun, 2, 1); | |
143 TestCaseWithException(fun, 1); | |
144 | |
145 | |
146 // Step in position, when the function call that we are standing at is raising | |
147 // an exception. | |
148 var fun = function() { | |
149 var o = { | |
150 g: function(p) { | |
151 throw p; | |
152 } | |
153 }; | |
154 try { | |
155 var res = [ /*#*/f(1), /*#*/g(2) ]; /*pause, positions*/ | |
156 } catch (e) { | |
157 } | |
158 }; | |
159 TestCaseWithException(fun, 0); | |
160 | |
161 | |
162 // Step-in position, when already paused almost on the first call site. | |
163 var fun = function() { | |
164 function g(p) { | |
165 throw p; | |
166 } | |
167 try { | |
168 var res = [ /*#*/g(Math.rand), /*#*/g(2) ]; /*pause, positions*/ | |
169 } catch (e) { | |
170 } | |
171 }; | |
172 TestCaseWithBreakpoint(fun, 5, 0); | |
173 | |
174 // Step-in position, when already paused on the first call site. | |
175 var fun = function() { | |
176 function g() { | |
177 throw "Debug"; | |
178 } | |
179 try { | |
180 var res = [ /*#*/g(), /*#*/g() ]; /*pause, positions*/ | |
181 } catch (e) { | |
182 } | |
183 }; | |
184 TestCaseWithBreakpoint(fun, 5, 0); | |
185 | |
186 | |
107 // Method calls. | 187 // Method calls. |
108 var fun = function() { | 188 var fun = function() { |
109 var data = { | 189 var data = { |
110 a: function() {} | 190 a: function() {} |
111 }; | 191 }; |
112 var res = [ DebuggerStatement(), data./*#*/a(), data[/*#*/String("a")]/*#*/(), data["a"]/*#*/(), data.a, data["a"] ]; | 192 var res = [ DebuggerStatement(), data./*#*/a(), data[/*#*/String("a")]/*#*/(), data["a"]/*#*/(), data.a, data["a"] ]; /*positions*/ |
113 }; | 193 }; |
114 TestCase(fun); | 194 TestCaseWithDebugger(fun); |
115 | 195 |
116 // Function call on a value. | 196 // Function call on a value. |
117 var fun = function() { | 197 var fun = function() { |
118 function g(p) { | 198 function g(p) { |
119 return g; | 199 return g; |
120 } | 200 } |
121 var res = [ DebuggerStatement(), /*#*/g(2), /*#*/g(2)/*#*/(3), /*#*/g(0)/*#*/( 0)/*#*/(g) ]; | 201 var res = [ DebuggerStatement(), /*#*/g(2), /*#*/g(2)/*#*/(3), /*#*/g(0)/*#*/( 0)/*#*/(g) ]; /*positions*/ |
122 }; | 202 }; |
123 TestCase(fun); | 203 TestCaseWithDebugger(fun); |
124 | 204 |
125 // Local function call, closure function call, | 205 // Local function call, closure function call, |
126 // local function construction call. | 206 // local function construction call. |
127 var fun = (function(p) { | 207 var fun = (function(p) { |
128 return function() { | 208 return function() { |
129 function f(a, b) { | 209 function f(a, b) { |
130 } | 210 } |
131 var res = /*#*/f(DebuggerStatement(), /*#*/p(/*#*/new f())); | 211 var res = /*#*/f(DebuggerStatement(), /*#*/p(/*#*/new f())); /*positions*/ |
132 }; | 212 }; |
133 })(Object); | 213 })(Object); |
134 TestCase(fun); | 214 TestCaseWithDebugger(fun); |
135 | 215 |
136 // Global function, global object construction, calls before pause point. | 216 // Global function, global object construction, calls before pause point. |
137 var fun = (function(p) { | 217 var fun = (function(p) { |
138 return function() { | 218 return function() { |
139 var res = [ Math.abs(new Object()), DebuggerStatement(), Math./*#*/abs(4), / *#*/new Object()./*#*/toString() ]; | 219 var res = [ Math.abs(new Object()), DebuggerStatement(), Math./*#*/abs(4), / *#*/new Object()./*#*/toString() ]; /*positions*/ |
140 }; | 220 }; |
141 })(Object); | 221 })(Object); |
142 TestCase(fun); | 222 TestCaseWithDebugger(fun); |
223 | |
224 | |
OLD | NEW |