| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug |
| 6 | 6 |
| 7 var Debug = debug.Debug; | 7 var Debug = debug.Debug; |
| 8 | 8 |
| 9 function RunTest(name, formals_and_body, args, handler, continuation) { | 9 function RunTest(name, formals_and_body, args, handler, continuation) { |
| 10 var handler_called = false; | 10 var handler_called = false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Send a scopes request and check the result. | 90 // Send a scopes request and check the result. |
| 91 var json; | 91 var json; |
| 92 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | 92 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
| 93 var response_json = dcp.processDebugJSONRequest(request_json); | 93 var response_json = dcp.processDebugJSONRequest(request_json); |
| 94 var response = JSON.parse(response_json); | 94 var response = JSON.parse(response_json); |
| 95 assertEquals(scopes.length, response.body.scopes.length); | 95 assertEquals(scopes.length, response.body.scopes.length); |
| 96 for (var i = 0; i < scopes.length; i++) { | 96 for (var i = 0; i < scopes.length; i++) { |
| 97 assertEquals(i, response.body.scopes[i].index); | 97 assertEquals(i, response.body.scopes[i].index); |
| 98 assertEquals(scopes[i], response.body.scopes[i].type); | 98 assertEquals(scopes[i], response.body.scopes[i].type); |
| 99 if (scopes[i] == debug.ScopeType.Local || | 99 if (scopes[i] == debug.ScopeType.Local || |
| 100 scopes[i] == debug.ScopeType.Script || |
| 100 scopes[i] == debug.ScopeType.Closure) { | 101 scopes[i] == debug.ScopeType.Closure) { |
| 101 assertTrue(response.body.scopes[i].object.ref < 0); | 102 assertTrue(response.body.scopes[i].object.ref < 0); |
| 102 } else { | 103 } else { |
| 103 assertTrue(response.body.scopes[i].object.ref >= 0); | 104 assertTrue(response.body.scopes[i].object.ref >= 0); |
| 104 } | 105 } |
| 105 var found = false; | 106 var found = false; |
| 106 for (var j = 0; j < response.refs.length && !found; j++) { | 107 for (var j = 0; j < response.refs.length && !found; j++) { |
| 107 found = response.refs[j].handle == response.body.scopes[i].object.ref; | 108 found = response.refs[j].handle == response.body.scopes[i].object.ref; |
| 108 } | 109 } |
| 109 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); | 110 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Send a scope request for information on a single scope and check the | 153 // Send a scope request for information on a single scope and check the |
| 153 // result. | 154 // result. |
| 154 var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"
number":'; | 155 var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"
number":'; |
| 155 request_json += scope.scopeIndex(); | 156 request_json += scope.scopeIndex(); |
| 156 request_json += '}}'; | 157 request_json += '}}'; |
| 157 var response_json = dcp.processDebugJSONRequest(request_json); | 158 var response_json = dcp.processDebugJSONRequest(request_json); |
| 158 var response = JSON.parse(response_json); | 159 var response = JSON.parse(response_json); |
| 159 assertEquals(scope.scopeType(), response.body.type); | 160 assertEquals(scope.scopeType(), response.body.type); |
| 160 assertEquals(number, response.body.index); | 161 assertEquals(number, response.body.index); |
| 161 if (scope.scopeType() == debug.ScopeType.Local || | 162 if (scope.scopeType() == debug.ScopeType.Local || |
| 163 scope.scopeType() == debug.ScopeType.Script || |
| 162 scope.scopeType() == debug.ScopeType.Closure) { | 164 scope.scopeType() == debug.ScopeType.Closure) { |
| 163 assertTrue(response.body.object.ref < 0); | 165 assertTrue(response.body.object.ref < 0); |
| 164 } else { | 166 } else { |
| 165 assertTrue(response.body.object.ref >= 0); | 167 assertTrue(response.body.object.ref >= 0); |
| 166 } | 168 } |
| 167 var found = false; | 169 var found = false; |
| 168 for (var i = 0; i < response.refs.length && !found; i++) { | 170 for (var i = 0; i < response.refs.length && !found; i++) { |
| 169 found = response.refs[i].handle == response.body.object.ref; | 171 found = response.refs[i].handle == response.body.object.ref; |
| 170 } | 172 } |
| 171 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); | 173 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); |
| 172 } | 174 } |
| 173 | 175 |
| 174 | 176 |
| 175 // Simple empty local scope. | 177 // Simple empty local scope. |
| 176 RunTest("Local 1", | 178 RunTest("Local 1", |
| 177 ['debugger;'], | 179 ['debugger;'], |
| 178 [], | 180 [], |
| 179 function (exec_state) { | 181 function (exec_state) { |
| 180 CheckScopeChain([debug.ScopeType.Local, | 182 CheckScopeChain([debug.ScopeType.Local, |
| 183 debug.ScopeType.Script, |
| 181 debug.ScopeType.Global], exec_state); | 184 debug.ScopeType.Global], exec_state); |
| 182 CheckScopeContent({}, 0, exec_state); | 185 CheckScopeContent({}, 0, exec_state); |
| 183 }); | 186 }); |
| 184 | 187 |
| 185 // Local scope with a parameter. | 188 // Local scope with a parameter. |
| 186 RunTest("Local 2", | 189 RunTest("Local 2", |
| 187 ['a', 'debugger;'], | 190 ['a', 'debugger;'], |
| 188 [1], | 191 [1], |
| 189 function (exec_state) { | 192 function (exec_state) { |
| 190 CheckScopeChain([debug.ScopeType.Local, | 193 CheckScopeChain([debug.ScopeType.Local, |
| 194 debug.ScopeType.Script, |
| 191 debug.ScopeType.Global], exec_state); | 195 debug.ScopeType.Global], exec_state); |
| 192 CheckScopeContent({a:1}, 0, exec_state); | 196 CheckScopeContent({a:1}, 0, exec_state); |
| 193 }); | 197 }); |
| 194 | 198 |
| 195 // Local scope with a parameter and a local variable. | 199 // Local scope with a parameter and a local variable. |
| 196 RunTest("Local 3", | 200 RunTest("Local 3", |
| 197 ['a', 'var x = 3; debugger;'], | 201 ['a', 'var x = 3; debugger;'], |
| 198 [1], | 202 [1], |
| 199 function (exec_state) { | 203 function (exec_state) { |
| 200 CheckScopeChain([debug.ScopeType.Local, | 204 CheckScopeChain([debug.ScopeType.Local, |
| 205 debug.ScopeType.Script, |
| 201 debug.ScopeType.Global], exec_state); | 206 debug.ScopeType.Global], exec_state); |
| 202 CheckScopeContent({a:1,x:3}, 0, exec_state); | 207 CheckScopeContent({a:1,x:3}, 0, exec_state); |
| 203 }); | 208 }); |
| 204 | 209 |
| 205 // Local scope with parameters and local variables. | 210 // Local scope with parameters and local variables. |
| 206 RunTest("Local 4", | 211 RunTest("Local 4", |
| 207 ['a', 'b', 'var x = 3; var y = 4; debugger;'], | 212 ['a', 'b', 'var x = 3; var y = 4; debugger;'], |
| 208 [1, 2], | 213 [1, 2], |
| 209 function (exec_state) { | 214 function (exec_state) { |
| 210 CheckScopeChain([debug.ScopeType.Local, | 215 CheckScopeChain([debug.ScopeType.Local, |
| 216 debug.ScopeType.Script, |
| 211 debug.ScopeType.Global], exec_state); | 217 debug.ScopeType.Global], exec_state); |
| 212 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); | 218 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); |
| 213 }); | 219 }); |
| 214 | 220 |
| 215 // Empty local scope with use of eval. | 221 // Empty local scope with use of eval. |
| 216 RunTest("Local 5", | 222 RunTest("Local 5", |
| 217 ['eval(""); debugger;'], | 223 ['eval(""); debugger;'], |
| 218 [], | 224 [], |
| 219 function (exec_state) { | 225 function (exec_state) { |
| 220 CheckScopeChain([debug.ScopeType.Local, | 226 CheckScopeChain([debug.ScopeType.Local, |
| 227 debug.ScopeType.Script, |
| 221 debug.ScopeType.Global], exec_state); | 228 debug.ScopeType.Global], exec_state); |
| 222 CheckScopeContent({}, 0, exec_state); | 229 CheckScopeContent({}, 0, exec_state); |
| 223 }); | 230 }); |
| 224 | 231 |
| 225 // Local introducing local variable using eval. | 232 // Local introducing local variable using eval. |
| 226 RunTest("Local 6", | 233 RunTest("Local 6", |
| 227 ['eval("var i = 5"); debugger;'], | 234 ['eval("var i = 5"); debugger;'], |
| 228 [], | 235 [], |
| 229 function (exec_state) { | 236 function (exec_state) { |
| 230 CheckScopeChain([debug.ScopeType.Local, | 237 CheckScopeChain([debug.ScopeType.Local, |
| 238 debug.ScopeType.Script, |
| 231 debug.ScopeType.Global], exec_state); | 239 debug.ScopeType.Global], exec_state); |
| 232 CheckScopeContent({i:5}, 0, exec_state); | 240 CheckScopeContent({i:5}, 0, exec_state); |
| 233 }); | 241 }); |
| 234 | 242 |
| 235 // Local scope with parameters, local variables and local variable introduced | 243 // Local scope with parameters, local variables and local variable introduced |
| 236 // using eval. | 244 // using eval. |
| 237 RunTest("Local 7", | 245 RunTest("Local 7", |
| 238 ['a', 'b', | 246 ['a', 'b', |
| 239 "var x = 3; var y = 4;\n" | 247 "var x = 3; var y = 4;\n" |
| 240 + "eval('var i = 5'); eval ('var j = 6');\n" | 248 + "eval('var i = 5'); eval ('var j = 6');\n" |
| 241 + "debugger;"], | 249 + "debugger;"], |
| 242 [1, 2], | 250 [1, 2], |
| 243 function (exec_state) { | 251 function (exec_state) { |
| 244 CheckScopeChain([debug.ScopeType.Local, | 252 CheckScopeChain([debug.ScopeType.Local, |
| 253 debug.ScopeType.Script, |
| 245 debug.ScopeType.Global], exec_state); | 254 debug.ScopeType.Global], exec_state); |
| 246 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); | 255 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); |
| 247 }); | 256 }); |
| 248 | 257 |
| 249 // Nested empty with blocks. | 258 // Nested empty with blocks. |
| 250 RunTest("With", | 259 RunTest("With", |
| 251 ["with ({}) { with ({}) { debugger; } }"], | 260 ["with ({}) { with ({}) { debugger; } }"], |
| 252 [], | 261 [], |
| 253 function (exec_state) { | 262 function (exec_state) { |
| 254 CheckScopeChain([debug.ScopeType.With, | 263 CheckScopeChain([debug.ScopeType.With, |
| 255 debug.ScopeType.With, | 264 debug.ScopeType.With, |
| 256 debug.ScopeType.Local, | 265 debug.ScopeType.Local, |
| 266 debug.ScopeType.Script, |
| 257 debug.ScopeType.Global], exec_state); | 267 debug.ScopeType.Global], exec_state); |
| 258 CheckScopeContent({}, 0, exec_state); | 268 CheckScopeContent({}, 0, exec_state); |
| 259 CheckScopeContent({}, 1, exec_state); | 269 CheckScopeContent({}, 1, exec_state); |
| 260 }); | 270 }); |
| 261 | 271 |
| 262 // Simple closure formed by returning an inner function referering the outer | 272 // Simple closure formed by returning an inner function referering the outer |
| 263 // functions arguments. | 273 // functions arguments. |
| 264 RunTest("Closure 1", | 274 RunTest("Closure 1", |
| 265 ['a', 'return function() { debugger; return a; }'], | 275 ['a', 'return function() { debugger; return a; }'], |
| 266 [1], | 276 [1], |
| 267 function (exec_state) { | 277 function (exec_state) { |
| 268 CheckScopeChain([debug.ScopeType.Local, | 278 CheckScopeChain([debug.ScopeType.Local, |
| 269 debug.ScopeType.Closure, | 279 debug.ScopeType.Closure, |
| 280 debug.ScopeType.Script, |
| 270 debug.ScopeType.Global], exec_state); | 281 debug.ScopeType.Global], exec_state); |
| 271 CheckScopeContent({a:1}, 1, exec_state); | 282 CheckScopeContent({a:1}, 1, exec_state); |
| 272 }, | 283 }, |
| 273 function (result) { result() }); | 284 function (result) { result() }); |
| 274 | 285 |
| 275 RunTest("The full monty", | 286 RunTest("The full monty", |
| 276 ['a', 'b', | 287 ['a', 'b', |
| 277 "var x = 3;\n" + | 288 "var x = 3;\n" + |
| 278 "var y = 4;\n" + | 289 "var y = 4;\n" + |
| 279 "eval('var i = 5');\n" + | 290 "eval('var i = 5');\n" + |
| (...skipping 18 matching lines...) Expand all Loading... |
| 298 "}\n" + | 309 "}\n" + |
| 299 "return f(a, b);"], | 310 "return f(a, b);"], |
| 300 [1, 2], | 311 [1, 2], |
| 301 function (exec_state) { | 312 function (exec_state) { |
| 302 CheckScopeChain([debug.ScopeType.With, | 313 CheckScopeChain([debug.ScopeType.With, |
| 303 debug.ScopeType.With, | 314 debug.ScopeType.With, |
| 304 debug.ScopeType.Local, | 315 debug.ScopeType.Local, |
| 305 debug.ScopeType.With, | 316 debug.ScopeType.With, |
| 306 debug.ScopeType.Closure, | 317 debug.ScopeType.Closure, |
| 307 debug.ScopeType.Closure, | 318 debug.ScopeType.Closure, |
| 319 debug.ScopeType.Script, |
| 308 debug.ScopeType.Global], exec_state); | 320 debug.ScopeType.Global], exec_state); |
| 309 CheckScopeContent({b:16}, 0, exec_state); | 321 CheckScopeContent({b:16}, 0, exec_state); |
| 310 CheckScopeContent({a:15}, 1, exec_state); | 322 CheckScopeContent({a:15}, 1, exec_state); |
| 311 CheckScopeContent({x:14}, 2, exec_state); | 323 CheckScopeContent({x:14}, 2, exec_state); |
| 312 CheckScopeContent({j:13}, 3, exec_state); | 324 CheckScopeContent({j:13}, 3, exec_state); |
| 313 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); | 325 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); |
| 314 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_st
ate); | 326 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_st
ate); |
| 315 }, | 327 }, |
| 316 function (result) { result() }); | 328 function (result) { result() }); |
| 317 | 329 |
| 318 RunTest("Catch block 1", | 330 RunTest("Catch block 1", |
| 319 ["try { throw 'Exception'; } catch (e) { debugger; }"], | 331 ["try { throw 'Exception'; } catch (e) { debugger; }"], |
| 320 [], | 332 [], |
| 321 function (exec_state) { | 333 function (exec_state) { |
| 322 CheckScopeChain([debug.ScopeType.Catch, | 334 CheckScopeChain([debug.ScopeType.Catch, |
| 323 debug.ScopeType.Local, | 335 debug.ScopeType.Local, |
| 336 debug.ScopeType.Script, |
| 324 debug.ScopeType.Global], exec_state); | 337 debug.ScopeType.Global], exec_state); |
| 325 CheckScopeContent({e:'Exception'}, 0, exec_state); | 338 CheckScopeContent({e:'Exception'}, 0, exec_state); |
| 326 }); | 339 }); |
| OLD | NEW |