| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 listener_delegate = null; | 66 listener_delegate = null; |
| 67 listener_called = false; | 67 listener_called = false; |
| 68 exception = null; | 68 exception = null; |
| 69 begin_test_count++; | 69 begin_test_count++; |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 // Check result of a test. | 73 // Check result of a test. |
| 74 function EndTest() { | 74 function EndTest() { |
| 75 assertTrue(listener_called, "listerner not called for " + test_name); | 75 assertTrue(listener_called, "listerner not called for " + test_name); |
| 76 assertNull(exception, test_name); | 76 assertNull(exception, test_name, exception); |
| 77 end_test_count++; | 77 end_test_count++; |
| 78 } | 78 } |
| 79 | 79 |
| 80 var global_object = this; | 80 var global_object = this; |
| 81 | 81 |
| 82 // Check that the scope chain contains the expected types of scopes. | 82 // Check that the scope chain contains the expected types of scopes. |
| 83 function CheckScopeChain(scopes, exec_state) { | 83 function CheckScopeChain(scopes, exec_state) { |
| 84 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 84 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
| 85 for (var i = 0; i < scopes.length; i++) { | 85 for (var i = 0; i < scopes.length; i++) { |
| 86 var scope = exec_state.frame().scope(i); | 86 var scope = exec_state.frame().scope(i); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 // Send a scopes request and check the result. | 101 // Send a scopes request and check the result. |
| 102 var json; | 102 var json; |
| 103 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | 103 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
| 104 var response_json = dcp.processDebugJSONRequest(request_json); | 104 var response_json = dcp.processDebugJSONRequest(request_json); |
| 105 var response = JSON.parse(response_json); | 105 var response = JSON.parse(response_json); |
| 106 assertEquals(scopes.length, response.body.scopes.length); | 106 assertEquals(scopes.length, response.body.scopes.length); |
| 107 for (var i = 0; i < scopes.length; i++) { | 107 for (var i = 0; i < scopes.length; i++) { |
| 108 assertEquals(i, response.body.scopes[i].index); | 108 assertEquals(i, response.body.scopes[i].index); |
| 109 assertEquals(scopes[i], response.body.scopes[i].type); | 109 assertEquals(scopes[i], response.body.scopes[i].type); |
| 110 if (scopes[i] == debug.ScopeType.Local || | 110 if (scopes[i] == debug.ScopeType.Local || |
| 111 scopes[i] == debug.ScopeType.Script || |
| 111 scopes[i] == debug.ScopeType.Closure) { | 112 scopes[i] == debug.ScopeType.Closure) { |
| 112 assertTrue(response.body.scopes[i].object.ref < 0); | 113 assertTrue(response.body.scopes[i].object.ref < 0); |
| 113 } else { | 114 } else { |
| 114 assertTrue(response.body.scopes[i].object.ref >= 0); | 115 assertTrue(response.body.scopes[i].object.ref >= 0); |
| 115 } | 116 } |
| 116 var found = false; | 117 var found = false; |
| 117 for (var j = 0; j < response.refs.length && !found; j++) { | 118 for (var j = 0; j < response.refs.length && !found; j++) { |
| 118 found = response.refs[j].handle == response.body.scopes[i].object.ref; | 119 found = response.refs[j].handle == response.body.scopes[i].object.ref; |
| 119 } | 120 } |
| 120 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); | 121 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 BeginTest("Local block 1"); | 191 BeginTest("Local block 1"); |
| 191 | 192 |
| 192 function local_block_1() { | 193 function local_block_1() { |
| 193 { | 194 { |
| 194 debugger; | 195 debugger; |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 | 198 |
| 198 listener_delegate = function(exec_state) { | 199 listener_delegate = function(exec_state) { |
| 199 CheckScopeChain([debug.ScopeType.Local, | 200 CheckScopeChain([debug.ScopeType.Local, |
| 201 debug.ScopeType.Script, |
| 200 debug.ScopeType.Global], exec_state); | 202 debug.ScopeType.Global], exec_state); |
| 201 CheckScopeContent({}, 0, exec_state); | 203 CheckScopeContent({}, 0, exec_state); |
| 202 }; | 204 }; |
| 203 local_block_1(); | 205 local_block_1(); |
| 204 EndTest(); | 206 EndTest(); |
| 205 | 207 |
| 206 | 208 |
| 207 // Simple empty block scope in local scope with a parameter. | 209 // Simple empty block scope in local scope with a parameter. |
| 208 BeginTest("Local 2"); | 210 BeginTest("Local 2"); |
| 209 | 211 |
| 210 function local_2(a) { | 212 function local_2(a) { |
| 211 { | 213 { |
| 212 debugger; | 214 debugger; |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 | 217 |
| 216 listener_delegate = function(exec_state) { | 218 listener_delegate = function(exec_state) { |
| 217 CheckScopeChain([debug.ScopeType.Local, | 219 CheckScopeChain([debug.ScopeType.Local, |
| 220 debug.ScopeType.Script, |
| 218 debug.ScopeType.Global], exec_state); | 221 debug.ScopeType.Global], exec_state); |
| 219 CheckScopeContent({a:1}, 0, exec_state); | 222 CheckScopeContent({a:1}, 0, exec_state); |
| 220 }; | 223 }; |
| 221 local_2(1); | 224 local_2(1); |
| 222 EndTest(); | 225 EndTest(); |
| 223 | 226 |
| 224 | 227 |
| 225 // Local scope with a parameter and a local variable. | 228 // Local scope with a parameter and a local variable. |
| 226 BeginTest("Local 3"); | 229 BeginTest("Local 3"); |
| 227 | 230 |
| 228 function local_3(a) { | 231 function local_3(a) { |
| 229 let x = 3; | 232 let x = 3; |
| 230 debugger; | 233 debugger; |
| 231 } | 234 } |
| 232 | 235 |
| 233 listener_delegate = function(exec_state) { | 236 listener_delegate = function(exec_state) { |
| 234 CheckScopeChain([debug.ScopeType.Local, | 237 CheckScopeChain([debug.ScopeType.Local, |
| 238 debug.ScopeType.Script, |
| 235 debug.ScopeType.Global], exec_state); | 239 debug.ScopeType.Global], exec_state); |
| 236 CheckScopeContent({a:1,x:3}, 0, exec_state); | 240 CheckScopeContent({a:1,x:3}, 0, exec_state); |
| 237 }; | 241 }; |
| 238 local_3(1); | 242 local_3(1); |
| 239 EndTest(); | 243 EndTest(); |
| 240 | 244 |
| 241 | 245 |
| 242 // Local scope with parameters and local variables. | 246 // Local scope with parameters and local variables. |
| 243 BeginTest("Local 4"); | 247 BeginTest("Local 4"); |
| 244 | 248 |
| 245 function local_4(a, b) { | 249 function local_4(a, b) { |
| 246 let x = 3; | 250 let x = 3; |
| 247 let y = 4; | 251 let y = 4; |
| 248 debugger; | 252 debugger; |
| 249 } | 253 } |
| 250 | 254 |
| 251 listener_delegate = function(exec_state) { | 255 listener_delegate = function(exec_state) { |
| 252 CheckScopeChain([debug.ScopeType.Local, | 256 CheckScopeChain([debug.ScopeType.Local, |
| 257 debug.ScopeType.Script, |
| 253 debug.ScopeType.Global], exec_state); | 258 debug.ScopeType.Global], exec_state); |
| 254 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); | 259 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); |
| 255 }; | 260 }; |
| 256 local_4(1, 2); | 261 local_4(1, 2); |
| 257 EndTest(); | 262 EndTest(); |
| 258 | 263 |
| 259 | 264 |
| 260 // Single variable in a block scope. | 265 // Single variable in a block scope. |
| 261 BeginTest("Local 5"); | 266 BeginTest("Local 5"); |
| 262 | 267 |
| 263 function local_5(a) { | 268 function local_5(a) { |
| 264 { | 269 { |
| 265 let x = 5; | 270 let x = 5; |
| 266 debugger; | 271 debugger; |
| 267 } | 272 } |
| 268 } | 273 } |
| 269 | 274 |
| 270 listener_delegate = function(exec_state) { | 275 listener_delegate = function(exec_state) { |
| 271 CheckScopeChain([debug.ScopeType.Block, | 276 CheckScopeChain([debug.ScopeType.Block, |
| 272 debug.ScopeType.Local, | 277 debug.ScopeType.Local, |
| 278 debug.ScopeType.Script, |
| 273 debug.ScopeType.Global], exec_state); | 279 debug.ScopeType.Global], exec_state); |
| 274 CheckScopeContent({x:5}, 0, exec_state); | 280 CheckScopeContent({x:5}, 0, exec_state); |
| 275 CheckScopeContent({a:1}, 1, exec_state); | 281 CheckScopeContent({a:1}, 1, exec_state); |
| 276 }; | 282 }; |
| 277 local_5(1); | 283 local_5(1); |
| 278 EndTest(); | 284 EndTest(); |
| 279 | 285 |
| 280 | 286 |
| 281 // Two variables in a block scope. | 287 // Two variables in a block scope. |
| 282 BeginTest("Local 6"); | 288 BeginTest("Local 6"); |
| 283 | 289 |
| 284 function local_6(a) { | 290 function local_6(a) { |
| 285 { | 291 { |
| 286 let x = 6; | 292 let x = 6; |
| 287 let y = 7; | 293 let y = 7; |
| 288 debugger; | 294 debugger; |
| 289 } | 295 } |
| 290 } | 296 } |
| 291 | 297 |
| 292 listener_delegate = function(exec_state) { | 298 listener_delegate = function(exec_state) { |
| 293 CheckScopeChain([debug.ScopeType.Block, | 299 CheckScopeChain([debug.ScopeType.Block, |
| 294 debug.ScopeType.Local, | 300 debug.ScopeType.Local, |
| 301 debug.ScopeType.Script, |
| 295 debug.ScopeType.Global], exec_state); | 302 debug.ScopeType.Global], exec_state); |
| 296 CheckScopeContent({x:6,y:7}, 0, exec_state); | 303 CheckScopeContent({x:6,y:7}, 0, exec_state); |
| 297 CheckScopeContent({a:1}, 1, exec_state); | 304 CheckScopeContent({a:1}, 1, exec_state); |
| 298 }; | 305 }; |
| 299 local_6(1); | 306 local_6(1); |
| 300 EndTest(); | 307 EndTest(); |
| 301 | 308 |
| 302 | 309 |
| 303 // Two variables in a block scope. | 310 // Two variables in a block scope. |
| 304 BeginTest("Local 7"); | 311 BeginTest("Local 7"); |
| 305 | 312 |
| 306 function local_7(a) { | 313 function local_7(a) { |
| 307 { | 314 { |
| 308 { | 315 { |
| 309 let x = 8; | 316 let x = 8; |
| 310 debugger; | 317 debugger; |
| 311 } | 318 } |
| 312 } | 319 } |
| 313 } | 320 } |
| 314 | 321 |
| 315 listener_delegate = function(exec_state) { | 322 listener_delegate = function(exec_state) { |
| 316 CheckScopeChain([debug.ScopeType.Block, | 323 CheckScopeChain([debug.ScopeType.Block, |
| 317 debug.ScopeType.Local, | 324 debug.ScopeType.Local, |
| 325 debug.ScopeType.Script, |
| 318 debug.ScopeType.Global], exec_state); | 326 debug.ScopeType.Global], exec_state); |
| 319 CheckScopeContent({x:8}, 0, exec_state); | 327 CheckScopeContent({x:8}, 0, exec_state); |
| 320 CheckScopeContent({a:1}, 1, exec_state); | 328 CheckScopeContent({a:1}, 1, exec_state); |
| 321 }; | 329 }; |
| 322 local_7(1); | 330 local_7(1); |
| 323 EndTest(); | 331 EndTest(); |
| 324 | 332 |
| 325 | 333 |
| 326 // Simple closure formed by returning an inner function referering to an outer | 334 // Simple closure formed by returning an inner function referering to an outer |
| 327 // block local variable and an outer function's parameter. | 335 // block local variable and an outer function's parameter. |
| 328 BeginTest("Closure 1"); | 336 BeginTest("Closure 1"); |
| 329 | 337 |
| 330 function closure_1(a) { | 338 function closure_1(a) { |
| 331 var x = 2; | 339 var x = 2; |
| 332 let y = 3; | 340 let y = 3; |
| 333 if (true) { | 341 if (true) { |
| 334 let z = 4; | 342 let z = 4; |
| 335 function f() { | 343 function f() { |
| 336 debugger; | 344 debugger; |
| 337 return a + x + y + z; | 345 return a + x + y + z; |
| 338 }; | 346 }; |
| 339 return f; | 347 return f; |
| 340 } | 348 } |
| 341 } | 349 } |
| 342 | 350 |
| 343 listener_delegate = function(exec_state) { | 351 listener_delegate = function(exec_state) { |
| 344 CheckScopeChain([debug.ScopeType.Local, | 352 CheckScopeChain([debug.ScopeType.Local, |
| 345 debug.ScopeType.Block, | 353 debug.ScopeType.Block, |
| 346 debug.ScopeType.Closure, | 354 debug.ScopeType.Closure, |
| 355 debug.ScopeType.Script, |
| 347 debug.ScopeType.Global], exec_state); | 356 debug.ScopeType.Global], exec_state); |
| 348 CheckScopeContent({}, 0, exec_state); | 357 CheckScopeContent({}, 0, exec_state); |
| 349 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); | 358 CheckScopeContent({a:1,x:2,y:3}, 2, exec_state); |
| 350 }; | 359 }; |
| 351 closure_1(1)(); | 360 closure_1(1)(); |
| 352 EndTest(); | 361 EndTest(); |
| 353 | 362 |
| 354 | 363 |
| 355 // Simple for-in loop over the keys of an object. | 364 // Simple for-in loop over the keys of an object. |
| 356 BeginTest("For loop 1"); | 365 BeginTest("For loop 1"); |
| 357 | 366 |
| 358 function for_loop_1() { | 367 function for_loop_1() { |
| 359 for (let x in {y:undefined}) { | 368 for (let x in {y:undefined}) { |
| 360 debugger; | 369 debugger; |
| 361 } | 370 } |
| 362 } | 371 } |
| 363 | 372 |
| 364 listener_delegate = function(exec_state) { | 373 listener_delegate = function(exec_state) { |
| 365 CheckScopeChain([debug.ScopeType.Block, | 374 CheckScopeChain([debug.ScopeType.Block, |
| 366 debug.ScopeType.Local, | 375 debug.ScopeType.Local, |
| 376 debug.ScopeType.Script, |
| 367 debug.ScopeType.Global], exec_state); | 377 debug.ScopeType.Global], exec_state); |
| 368 CheckScopeContent({x:'y'}, 0, exec_state); | 378 CheckScopeContent({x:'y'}, 0, exec_state); |
| 369 // The function scope contains a temporary iteration variable, but it is | 379 // The function scope contains a temporary iteration variable, but it is |
| 370 // hidden to the debugger. | 380 // hidden to the debugger. |
| 371 CheckScopeContent({}, 1, exec_state); | 381 CheckScopeContent({}, 1, exec_state); |
| 372 }; | 382 }; |
| 373 for_loop_1(); | 383 for_loop_1(); |
| 374 EndTest(); | 384 EndTest(); |
| 375 | 385 |
| 376 | 386 |
| 377 // For-in loop over the keys of an object with a block scoped let variable | 387 // For-in loop over the keys of an object with a block scoped let variable |
| 378 // shadowing the iteration variable. | 388 // shadowing the iteration variable. |
| 379 BeginTest("For loop 2"); | 389 BeginTest("For loop 2"); |
| 380 | 390 |
| 381 function for_loop_2() { | 391 function for_loop_2() { |
| 382 for (let x in {y:undefined}) { | 392 for (let x in {y:undefined}) { |
| 383 let x = 3; | 393 let x = 3; |
| 384 debugger; | 394 debugger; |
| 385 } | 395 } |
| 386 } | 396 } |
| 387 | 397 |
| 388 listener_delegate = function(exec_state) { | 398 listener_delegate = function(exec_state) { |
| 389 CheckScopeChain([debug.ScopeType.Block, | 399 CheckScopeChain([debug.ScopeType.Block, |
| 390 debug.ScopeType.Block, | 400 debug.ScopeType.Block, |
| 391 debug.ScopeType.Local, | 401 debug.ScopeType.Local, |
| 402 debug.ScopeType.Script, |
| 392 debug.ScopeType.Global], exec_state); | 403 debug.ScopeType.Global], exec_state); |
| 393 CheckScopeContent({x:3}, 0, exec_state); | 404 CheckScopeContent({x:3}, 0, exec_state); |
| 394 CheckScopeContent({x:'y'}, 1, exec_state); | 405 CheckScopeContent({x:'y'}, 1, exec_state); |
| 395 // The function scope contains a temporary iteration variable, hidden to the | 406 // The function scope contains a temporary iteration variable, hidden to the |
| 396 // debugger. | 407 // debugger. |
| 397 CheckScopeContent({}, 2, exec_state); | 408 CheckScopeContent({}, 2, exec_state); |
| 398 }; | 409 }; |
| 399 for_loop_2(); | 410 for_loop_2(); |
| 400 EndTest(); | 411 EndTest(); |
| 401 | 412 |
| 402 | 413 |
| 403 // Simple for loop. | 414 // Simple for loop. |
| 404 BeginTest("For loop 3"); | 415 BeginTest("For loop 3"); |
| 405 | 416 |
| 406 function for_loop_3() { | 417 function for_loop_3() { |
| 407 for (let x = 3; x < 4; ++x) { | 418 for (let x = 3; x < 4; ++x) { |
| 408 debugger; | 419 debugger; |
| 409 } | 420 } |
| 410 } | 421 } |
| 411 | 422 |
| 412 listener_delegate = function(exec_state) { | 423 listener_delegate = function(exec_state) { |
| 413 CheckScopeChain([debug.ScopeType.Block, | 424 CheckScopeChain([debug.ScopeType.Block, |
| 414 debug.ScopeType.Block, | 425 debug.ScopeType.Block, |
| 415 debug.ScopeType.Local, | 426 debug.ScopeType.Local, |
| 427 debug.ScopeType.Script, |
| 416 debug.ScopeType.Global], exec_state); | 428 debug.ScopeType.Global], exec_state); |
| 417 CheckScopeContent({x:3}, 0, exec_state); | 429 CheckScopeContent({x:3}, 0, exec_state); |
| 418 CheckScopeContent({x:3}, 1, exec_state); | 430 CheckScopeContent({x:3}, 1, exec_state); |
| 419 CheckScopeContent({}, 2, exec_state); | 431 CheckScopeContent({}, 2, exec_state); |
| 420 }; | 432 }; |
| 421 for_loop_3(); | 433 for_loop_3(); |
| 422 EndTest(); | 434 EndTest(); |
| 423 | 435 |
| 424 | 436 |
| 425 // For loop with a block scoped let variable shadowing the iteration variable. | 437 // For loop with a block scoped let variable shadowing the iteration variable. |
| 426 BeginTest("For loop 4"); | 438 BeginTest("For loop 4"); |
| 427 | 439 |
| 428 function for_loop_4() { | 440 function for_loop_4() { |
| 429 for (let x = 3; x < 4; ++x) { | 441 for (let x = 3; x < 4; ++x) { |
| 430 let x = 5; | 442 let x = 5; |
| 431 debugger; | 443 debugger; |
| 432 } | 444 } |
| 433 } | 445 } |
| 434 | 446 |
| 435 listener_delegate = function(exec_state) { | 447 listener_delegate = function(exec_state) { |
| 436 CheckScopeChain([debug.ScopeType.Block, | 448 CheckScopeChain([debug.ScopeType.Block, |
| 437 debug.ScopeType.Block, | 449 debug.ScopeType.Block, |
| 438 debug.ScopeType.Block, | 450 debug.ScopeType.Block, |
| 439 debug.ScopeType.Local, | 451 debug.ScopeType.Local, |
| 452 debug.ScopeType.Script, |
| 440 debug.ScopeType.Global], exec_state); | 453 debug.ScopeType.Global], exec_state); |
| 441 CheckScopeContent({x:5}, 0, exec_state); | 454 CheckScopeContent({x:5}, 0, exec_state); |
| 442 CheckScopeContent({x:3}, 1, exec_state); | 455 CheckScopeContent({x:3}, 1, exec_state); |
| 443 CheckScopeContent({x:3}, 2, exec_state); | 456 CheckScopeContent({x:3}, 2, exec_state); |
| 444 CheckScopeContent({}, 3, exec_state); | 457 CheckScopeContent({}, 3, exec_state); |
| 445 }; | 458 }; |
| 446 for_loop_4(); | 459 for_loop_4(); |
| 447 EndTest(); | 460 EndTest(); |
| 448 | 461 |
| 449 | 462 |
| 450 // For loop with two variable declarations. | 463 // For loop with two variable declarations. |
| 451 BeginTest("For loop 5"); | 464 BeginTest("For loop 5"); |
| 452 | 465 |
| 453 function for_loop_5() { | 466 function for_loop_5() { |
| 454 for (let x = 3, y = 5; x < 4; ++x) { | 467 for (let x = 3, y = 5; x < 4; ++x) { |
| 455 debugger; | 468 debugger; |
| 456 } | 469 } |
| 457 } | 470 } |
| 458 | 471 |
| 459 listener_delegate = function(exec_state) { | 472 listener_delegate = function(exec_state) { |
| 460 CheckScopeChain([debug.ScopeType.Block, | 473 CheckScopeChain([debug.ScopeType.Block, |
| 461 debug.ScopeType.Block, | 474 debug.ScopeType.Block, |
| 462 debug.ScopeType.Local, | 475 debug.ScopeType.Local, |
| 476 debug.ScopeType.Script, |
| 463 debug.ScopeType.Global], exec_state); | 477 debug.ScopeType.Global], exec_state); |
| 464 CheckScopeContent({x:3,y:5}, 0, exec_state); | 478 CheckScopeContent({x:3,y:5}, 0, exec_state); |
| 465 CheckScopeContent({x:3,y:5}, 1, exec_state); | 479 CheckScopeContent({x:3,y:5}, 1, exec_state); |
| 466 CheckScopeContent({}, 2, exec_state); | 480 CheckScopeContent({}, 2, exec_state); |
| 467 }; | 481 }; |
| 468 for_loop_5(); | 482 for_loop_5(); |
| 469 EndTest(); | 483 EndTest(); |
| OLD | NEW |