| 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 | 28 // Flags: --expose-debug-as debug |
| 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 listenerComplete = false; | 32 listenerComplete = false; |
| 33 exception = false; | 33 exception = null; |
| 34 | 34 |
| 35 // The base part of all evaluate requests. | 35 // The base part of all evaluate requests. |
| 36 var base_request = '"seq":0,"type":"request","command":"evaluate"' | 36 var base_request = '"seq":0,"type":"request","command":"evaluate"' |
| 37 | 37 |
| 38 function safeEval(code) { | 38 function safeEval(code) { |
| 39 try { | 39 try { |
| 40 return eval('(' + code + ')'); | 40 return eval('(' + code + ')'); |
| 41 } catch (e) { | 41 } catch (e) { |
| 42 assertEquals(void 0, e); | 42 assertEquals(void 0, e); |
| 43 return undefined; | 43 return undefined; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 68 // Get the debug command processor. | 68 // Get the debug command processor. |
| 69 var dcp = exec_state.debugCommandProcessor(); | 69 var dcp = exec_state.debugCommandProcessor(); |
| 70 | 70 |
| 71 // Test some illegal evaluate requests. | 71 // Test some illegal evaluate requests. |
| 72 testRequest(dcp, void 0, false); | 72 testRequest(dcp, void 0, false); |
| 73 testRequest(dcp, '{"expression":"1","global"=true}', false); | 73 testRequest(dcp, '{"expression":"1","global"=true}', false); |
| 74 testRequest(dcp, '{"expression":"a","frame":4}', false); | 74 testRequest(dcp, '{"expression":"a","frame":4}', false); |
| 75 | 75 |
| 76 // Test some legal evaluate requests. | 76 // Test some legal evaluate requests. |
| 77 testRequest(dcp, '{"expression":"1+2"}', true, 3); | 77 testRequest(dcp, '{"expression":"1+2"}', true, 3); |
| 78 testRequest(dcp, '{"expression":"a+2"}', true, 5); | 78 testRequest(dcp, '{"expression":"a+2"}', true, 6); |
| 79 testRequest(dcp, '{"expression":"({\\"a\\":1,\\"b\\":2}).b+2"}', true, 4); | 79 testRequest(dcp, '{"expression":"({\\"a\\":1,\\"b\\":2}).b+2"}', true, 4); |
| 80 | 80 |
| 81 // Test evaluation of a in the stack frames and the global context. | 81 // Test evaluation of a in the stack frames and the global context. |
| 82 testRequest(dcp, '{"expression":"a"}', true, 3); | 82 testRequest(dcp, '{"expression":"a"}', true, 4); |
| 83 testRequest(dcp, '{"expression":"a","frame":0}', true, 3); | 83 testRequest(dcp, '{"expression":"a","frame":0}', true, 4); |
| 84 testRequest(dcp, '{"expression":"a","frame":1}', true, 2); | 84 testRequest(dcp, '{"expression":"a","frame":1}', true, 3); |
| 85 testRequest(dcp, '{"expression":"a","frame":2}', true, 1); | 85 testRequest(dcp, '{"expression":"a","frame":2}', true, 2); |
| 86 testRequest(dcp, '{"expression":"a","frame":3}', true, 1); |
| 86 testRequest(dcp, '{"expression":"a","global":true}', true, 1); | 87 testRequest(dcp, '{"expression":"a","global":true}', true, 1); |
| 87 testRequest(dcp, '{"expression":"this.a","global":true}', true, 1); | 88 testRequest(dcp, '{"expression":"this.a","global":true}', true, 1); |
| 88 | 89 |
| 90 // Test mutating variables. |
| 91 testRequest(dcp, '{"expression":"b=9","frame":0}', true, 9); |
| 92 testRequest(dcp, '{"expression":"b","frame":0}', true, 9); |
| 93 testRequest(dcp, '{"expression":"a=8","frame":0}', true, 8); |
| 94 testRequest(dcp, '{"expression":"a","frame":0}', true, 8); |
| 95 testRequest(dcp, '{"expression":"a=7","frame":1}', true, 7); |
| 96 testRequest(dcp, '{"expression":"a","frame":1}', true, 7); |
| 97 testRequest(dcp, '{"expression":"a=6","frame":2}', true, 6); |
| 98 testRequest(dcp, '{"expression":"a","frame":2}', true, 6); |
| 99 testRequest(dcp, '{"expression":"a=5","frame":3}', true, 5); |
| 100 testRequest(dcp, '{"expression":"a","frame":3}', true, 5); |
| 101 |
| 102 // Test mutating arguments. |
| 103 testRequest(dcp, '{"expression":"x=-8","frame":0}', true, -8); |
| 104 testRequest(dcp, '{"expression":"x","frame":0}', true, -8); |
| 105 testRequest(dcp, '{"expression":"x=-7","frame":1}', true, -7); |
| 106 testRequest(dcp, '{"expression":"x","frame":1}', true, -7); |
| 107 testRequest(dcp, '{"expression":"arguments[1]=\'!g\'","frame":1}', true, '
!g'); |
| 108 testRequest(dcp, '{"expression":"arguments[1]","frame":1}', true, '!g'); |
| 109 testRequest(dcp, '{"expression":"x=-6","frame":2}', true, -6); |
| 110 testRequest(dcp, '{"expression":"x","frame":2}', true, -6); |
| 111 |
| 112 // Indicate that all was processed. |
| 113 listenerComplete = true; |
| 114 } |
| 115 } catch (e) { |
| 116 print('Exception in listener: ' + e); |
| 117 exception = e; |
| 118 }; |
| 119 }; |
| 120 |
| 121 // Set the debug event listener. |
| 122 Debug.setListener(listener); |
| 123 |
| 124 |
| 125 // Function h is in frame 0 in the test. |
| 126 function h(x) { |
| 127 var a = -1 - x + 1; // This expression avoids optimizing a out. |
| 128 eval('var b = 5') |
| 129 assertEquals(-4, arguments[0]); |
| 130 assertEquals(-3, g.arguments[0]); |
| 131 assertEquals('g', g.arguments[1]); |
| 132 assertEquals(-2, f.arguments[0]); |
| 133 |
| 134 debugger; |
| 135 |
| 136 // Check that the mutation of locals and parameters are visible. |
| 137 assertEquals(9, b); |
| 138 assertEquals(8, a); |
| 139 assertEquals(-8, x); |
| 140 assertEquals(-8, eval('x')); |
| 141 assertEquals(-8, arguments[0]); |
| 142 assertEquals(-8, eval('arguments[0]')); |
| 143 assertEquals(-7, g.arguments[0]); |
| 144 assertEquals('!g', g.arguments[1]); |
| 145 assertEquals(-6, f.arguments[0]); |
| 146 }; |
| 147 |
| 148 |
| 149 // Function g is in frame 1 in the test. g is called with more arguments that is |
| 150 // in its formal parameter list, but does not itself access arguments |
| 151 function g(x) { |
| 152 var a = -1 - x + 1; // This expression avoids optimizing a out. |
| 153 h(-4); |
| 154 assertEquals(7, a); |
| 155 assertEquals(-7, x); |
| 156 }; |
| 157 |
| 158 |
| 159 // Function f is in frame 2 in the test. |
| 160 function f(x) { |
| 161 var a = -1 - x + 1; // This expression avoids optimizing a out. |
| 162 // Invoke g with an additional parameter to ensure an arguments adapter frame. |
| 163 g(-3, 'g'); |
| 164 assertEquals(6, a); |
| 165 assertEquals(-6, x); |
| 166 assertEquals(-6, arguments[0]); |
| 167 }; |
| 168 |
| 169 |
| 170 // Invoke f this will break in the debugger statement in h. |
| 171 a = 1; |
| 172 f(-2); |
| 173 assertEquals(5, a); |
| 174 |
| 175 // Make sure that the debug event listener vas invoked. |
| 176 assertNull(exception, "exception in listener") |
| 177 assertTrue(listenerComplete, "listener did not run to completion"); |
| 178 |
| 179 |
| 180 // Test that exposes a bug caused by the static analysis assumes that the local |
| 181 // x contains a string, however it is mutated by the debugger to be a number, |
| 182 // which makes the %StringAdd throw a runtime exception. See code generated by |
| 183 // CodeGenerator::GenericBinaryOperation. |
| 184 |
| 185 // Debug event listener which changes x expected to be 'ab' to 0 (Smi). |
| 186 function listener_bug1(event, exec_state, event_data, data) { |
| 187 try { |
| 188 if (event == Debug.DebugEvent.Break) { |
| 189 // Get the debug command processor. |
| 190 var dcp = exec_state.debugCommandProcessor(); |
| 191 |
| 192 // Test mutating variables. |
| 193 testRequest(dcp, '{"expression":"x","frame":0}', true, 'ab'); |
| 194 testRequest(dcp, '{"expression":"x=0","frame":0}', true, 0); |
| 195 testRequest(dcp, '{"expression":"x","frame":0}', true, 0); |
| 196 |
| 89 // Indicate that all was processed. | 197 // Indicate that all was processed. |
| 90 listenerComplete = true; | 198 listenerComplete = true; |
| 91 } | 199 } |
| 92 } catch (e) { | 200 } catch (e) { |
| 93 exception = e | 201 print('Exception in listener_bug1: ' + e); |
| 202 exception = e; |
| 94 }; | 203 }; |
| 95 }; | 204 }; |
| 96 | 205 |
| 97 // Add the debug event listener. | |
| 98 Debug.setListener(listener); | |
| 99 | 206 |
| 100 function f() { | 207 // Set the debug event listener. |
| 101 var a = 3; | 208 listenerComplete = false; |
| 209 exception = null; |
| 210 Debug.setListener(listener_bug1); |
| 211 |
| 212 function c() { |
| 213 var x = 'a' + 'b'; |
| 214 debugger; |
| 215 return x + 'b'; |
| 216 } |
| 217 |
| 218 try { |
| 219 c(); |
| 220 } catch (e) { |
| 221 // This exception is not supposed to happen! |
| 222 assertEquals('illegal access', e); |
| 223 } |
| 224 |
| 225 assertNull(exception, "exception in listener_bug1") |
| 226 assertTrue(listenerComplete, "listener_bug1 did not run to completion"); |
| 227 |
| 228 |
| 229 // Test that exposes a bug caused by the static analysis assumes that the local |
| 230 // x is aliased with the parameter p. |
| 231 |
| 232 // Debug event listener which changes x expected to be 1 to 2. |
| 233 function listener_bug2(event, exec_state, event_data, data) { |
| 234 try { |
| 235 if (event == Debug.DebugEvent.Break) { |
| 236 // Get the debug command processor. |
| 237 var dcp = exec_state.debugCommandProcessor(); |
| 238 |
| 239 // Test mutating variables. |
| 240 testRequest(dcp, '{"expression":"x","frame":0}', true, 1); |
| 241 testRequest(dcp, '{"expression":"x=2","frame":0}', true, 2); |
| 242 testRequest(dcp, '{"expression":"x","frame":0}', true, 2); |
| 243 |
| 244 // Indicate that all was processed. |
| 245 listenerComplete = true; |
| 246 } |
| 247 } catch (e) { |
| 248 print('Exception in listener_bug2: ' + e); |
| 249 exception = e; |
| 250 }; |
| 102 }; | 251 }; |
| 103 | 252 |
| 104 function g() { | |
| 105 var a = 2; | |
| 106 f(); | |
| 107 }; | |
| 108 | 253 |
| 109 a = 1; | 254 // Set the debug event listener. |
| 255 listenerComplete = false; |
| 256 exception = null; |
| 257 Debug.setListener(listener_bug2); |
| 110 | 258 |
| 111 // Set a break point at return in f and invoke g to hit the breakpoint. | 259 function dd() {} |
| 112 Debug.setBreakPoint(f, 2, 0); | 260 function d(p) { |
| 113 g(); | 261 var x = p; |
| 262 dd(); |
| 263 return x; |
| 264 } |
| 114 | 265 |
| 115 // Make sure that the debug event listener vas invoked. | 266 Debug.setBreakPoint(d, 2); // Break on dd() call. |
| 116 assertTrue(listenerComplete, "listener did not run to completion"); | 267 // This assertion should expect 2, not 1! |
| 117 assertFalse(exception, "exception in listener") | 268 assertEquals(1, d(1)); |
| 269 assertNull(exception, "exception in listener_bug2") |
| 270 assertTrue(listenerComplete, "listener_bug2 did not run to completion"); |
| OLD | NEW |