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 || |
| 44 event == Debug.DebugEvent.Exception) { |
44 Debug.setListener(null); | 45 Debug.setListener(null); |
45 | 46 assertHasLineMark(/pause/, exec_state.frame(0)); |
46 var secondFrame = exec_state.frame(1); | 47 assertHasLineMark(/positions/, exec_state.frame(frame_number)); |
47 codeSnippet = secondFrame.sourceLineText(); | 48 var frame = exec_state.frame(frame_number); |
48 resultPositions = secondFrame.stepInPositions(); | 49 codeSnippet = frame.sourceLineText(); |
| 50 resultPositions = frame.stepInPositions(); |
49 } | 51 } |
50 } catch (e) { | 52 } catch (e) { |
51 exception = e | 53 exception = e |
52 } | 54 } |
| 55 |
| 56 function assertHasLineMark(mark, frame) { |
| 57 var line = frame.sourceLineText(); |
| 58 if (!mark.exec(frame.sourceLineText())) { |
| 59 throw new Error("Line " + line + " should contain mark " + mark); |
| 60 } |
| 61 } |
53 } | 62 } |
54 | 63 |
55 Debug.setListener(listener); | 64 Debug.setListener(listener); |
56 | 65 |
57 fun(); | 66 fun(); |
58 | 67 |
59 Debug.setListener(null); | 68 Debug.setListener(null); |
60 | 69 |
61 assertTrue(!exception, exception); | 70 assertTrue(!exception, exception); |
62 | 71 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 print(decoratedResult); | 103 print(decoratedResult); |
95 | 104 |
96 for (var n in expectedPositions) { | 105 for (var n in expectedPositions) { |
97 assertTrue(false, "Some positions are not reported: " + decoratedResult); | 106 assertTrue(false, "Some positions are not reported: " + decoratedResult); |
98 break; | 107 break; |
99 } | 108 } |
100 assertFalse(unexpectedPositionFound, "Found unexpected position: " + | 109 assertFalse(unexpectedPositionFound, "Found unexpected position: " + |
101 decoratedResult); | 110 decoratedResult); |
102 } | 111 } |
103 | 112 |
| 113 function TestCaseWithDebugger(fun) { |
| 114 TestCase(fun, 1); |
| 115 } |
| 116 |
| 117 function TestCaseWithBreakpoint(fun, line_number, frame_number) { |
| 118 var breakpointId = Debug.setBreakPoint(fun, line_number); |
| 119 TestCase(fun, frame_number); |
| 120 Debug.clearBreakPoint(breakpointId); |
| 121 } |
| 122 |
| 123 function TestCaseWithException(fun, frame_number) { |
| 124 Debug.setBreakOnException(); |
| 125 TestCase(fun, frame_number); |
| 126 Debug.clearBreakOnException(); |
| 127 } |
| 128 |
104 | 129 |
105 // Test cases. | 130 // Test cases. |
106 | 131 |
| 132 // Step in position, when the function call that we are standing at is already |
| 133 // being executed. |
| 134 var fun = function() { |
| 135 function g(p) { |
| 136 throw String(p); /*pause*/ |
| 137 } |
| 138 try { |
| 139 var res = [ g(1), /*#*/g(2) ]; /*positions*/ |
| 140 } catch (e) { |
| 141 } |
| 142 }; |
| 143 TestCaseWithBreakpoint(fun, 2, 1); |
| 144 TestCaseWithException(fun, 1); |
| 145 |
| 146 |
| 147 // Step in position, when the function call that we are standing at is raising |
| 148 // an exception. |
| 149 var fun = function() { |
| 150 var o = { |
| 151 g: function(p) { |
| 152 throw p; |
| 153 } |
| 154 }; |
| 155 try { |
| 156 var res = [ /*#*/f(1), /*#*/g(2) ]; /*pause, positions*/ |
| 157 } catch (e) { |
| 158 } |
| 159 }; |
| 160 TestCaseWithException(fun, 0); |
| 161 |
| 162 |
| 163 // Step-in position, when already paused almost on the first call site. |
| 164 var fun = function() { |
| 165 function g(p) { |
| 166 throw p; |
| 167 } |
| 168 try { |
| 169 var res = [ /*#*/g(Math.rand), /*#*/g(2) ]; /*pause, positions*/ |
| 170 } catch (e) { |
| 171 } |
| 172 }; |
| 173 TestCaseWithBreakpoint(fun, 5, 0); |
| 174 |
| 175 // Step-in position, when already paused on the first call site. |
| 176 var fun = function() { |
| 177 function g() { |
| 178 throw "Debug"; |
| 179 } |
| 180 try { |
| 181 var res = [ /*#*/g(), /*#*/g() ]; /*pause, positions*/ |
| 182 } catch (e) { |
| 183 } |
| 184 }; |
| 185 TestCaseWithBreakpoint(fun, 5, 0); |
| 186 |
| 187 |
107 // Method calls. | 188 // Method calls. |
108 var fun = function() { | 189 var fun = function() { |
109 var data = { | 190 var data = { |
110 a: function() {} | 191 a: function() {} |
111 }; | 192 }; |
112 var res = [ DebuggerStatement(), data./*#*/a(), data[/*#*/String("a")]/*#*/(),
data["a"]/*#*/(), data.a, data["a"] ]; | 193 var res = [ DebuggerStatement(), data./*#*/a(), data[/*#*/String("a")]/*#*/(),
data["a"]/*#*/(), data.a, data["a"] ]; /*positions*/ |
113 }; | 194 }; |
114 TestCase(fun); | 195 TestCaseWithDebugger(fun); |
115 | 196 |
116 // Function call on a value. | 197 // Function call on a value. |
117 var fun = function() { | 198 var fun = function() { |
118 function g(p) { | 199 function g(p) { |
119 return g; | 200 return g; |
120 } | 201 } |
121 var res = [ DebuggerStatement(), /*#*/g(2), /*#*/g(2)/*#*/(3), /*#*/g(0)/*#*/(
0)/*#*/(g) ]; | 202 var res = [ DebuggerStatement(), /*#*/g(2), /*#*/g(2)/*#*/(3), /*#*/g(0)/*#*/(
0)/*#*/(g) ]; /*positions*/ |
122 }; | 203 }; |
123 TestCase(fun); | 204 TestCaseWithDebugger(fun); |
124 | 205 |
125 // Local function call, closure function call, | 206 // Local function call, closure function call, |
126 // local function construction call. | 207 // local function construction call. |
127 var fun = (function(p) { | 208 var fun = (function(p) { |
128 return function() { | 209 return function() { |
129 function f(a, b) { | 210 function f(a, b) { |
130 } | 211 } |
131 var res = /*#*/f(DebuggerStatement(), /*#*/p(/*#*/new f())); | 212 var res = /*#*/f(DebuggerStatement(), /*#*/p(/*#*/new f())); /*positions*/ |
132 }; | 213 }; |
133 })(Object); | 214 })(Object); |
134 TestCase(fun); | 215 TestCaseWithDebugger(fun); |
135 | 216 |
136 // Global function, global object construction, calls before pause point. | 217 // Global function, global object construction, calls before pause point. |
137 var fun = (function(p) { | 218 var fun = (function(p) { |
138 return function() { | 219 return function() { |
139 var res = [ Math.abs(new Object()), DebuggerStatement(), Math./*#*/abs(4), /
*#*/new Object()./*#*/toString() ]; | 220 var res = [ Math.abs(new Object()), DebuggerStatement(), Math./*#*/abs(4), /
*#*/new Object()./*#*/toString() ]; /*positions*/ |
140 }; | 221 }; |
141 })(Object); | 222 })(Object); |
142 TestCase(fun); | 223 TestCaseWithDebugger(fun); |
| 224 |
| 225 |
OLD | NEW |