Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 --harmony-scoping | 28 // Flags: --expose-debug-as debug --harmony-scoping |
| 29 // The functions used for testing backtraces. They are at the top to make the | 29 // The functions used for testing backtraces. They are at the top to make the |
| 30 // testing of source line/column easier. | 30 // testing of source line/column easier. |
| 31 | 31 |
| 32 // TODO(ES6): properly activate extended mode | |
| 33 "use strict"; | |
| 32 | 34 |
| 33 // Get the Debug object exposed from the debug context global object. | 35 // Get the Debug object exposed from the debug context global object. |
| 34 Debug = debug.Debug; | 36 var Debug = debug.Debug; |
| 35 | 37 |
| 36 var test_name; | 38 var test_name; |
| 37 var listener_delegate; | 39 var listener_delegate; |
| 38 var listener_called; | 40 var listener_called; |
| 39 var exception; | 41 var exception; |
| 40 var begin_test_count = 0; | 42 var begin_test_count = 0; |
| 41 var end_test_count = 0; | 43 var end_test_count = 0; |
| 42 var break_count = 0; | 44 var break_count = 0; |
| 43 | 45 |
| 44 | 46 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 } | 79 } |
| 78 | 80 |
| 79 | 81 |
| 80 // Check that the scope chain contains the expected types of scopes. | 82 // Check that the scope chain contains the expected types of scopes. |
| 81 function CheckScopeChain(scopes, exec_state) { | 83 function CheckScopeChain(scopes, exec_state) { |
| 82 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 84 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
| 83 for (var i = 0; i < scopes.length; i++) { | 85 for (var i = 0; i < scopes.length; i++) { |
| 84 var scope = exec_state.frame().scope(i); | 86 var scope = exec_state.frame().scope(i); |
| 85 assertTrue(scope.isScope()); | 87 assertTrue(scope.isScope()); |
| 86 assertEquals(scopes[i], scope.scopeType()); | 88 assertEquals(scopes[i], scope.scopeType()); |
| 87 | |
| 88 // Check the global object when hitting the global scope. | |
| 89 if (scopes[i] == debug.ScopeType.Global) { | |
| 90 // Objects don't have same class (one is "global", other is "Object", | |
| 91 // so just check the properties directly. | |
| 92 assertPropertiesEqual(this, scope.scopeObject().value()); | |
|
rossberg
2011/11/08 15:02:46
You can still get the global object by defining s.
Steven
2011/11/08 16:13:49
Done.
| |
| 93 } | |
| 94 } | 89 } |
| 95 | 90 |
| 96 // Get the debug command processor. | 91 // Get the debug command processor. |
| 97 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 92 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
| 98 | 93 |
| 99 // Send a scopes request and check the result. | 94 // Send a scopes request and check the result. |
| 100 var json; | 95 var json; |
| 101 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | 96 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
| 102 var response_json = dcp.processDebugJSONRequest(request_json); | 97 var response_json = dcp.processDebugJSONRequest(request_json); |
| 103 var response = JSON.parse(response_json); | 98 var response = JSON.parse(response_json); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 CheckScopeChain([debug.ScopeType.Block, | 317 CheckScopeChain([debug.ScopeType.Block, |
| 323 debug.ScopeType.Local, | 318 debug.ScopeType.Local, |
| 324 debug.ScopeType.Global], exec_state); | 319 debug.ScopeType.Global], exec_state); |
| 325 CheckScopeContent({x:8}, 0, exec_state); | 320 CheckScopeContent({x:8}, 0, exec_state); |
| 326 CheckScopeContent({a:1}, 1, exec_state); | 321 CheckScopeContent({a:1}, 1, exec_state); |
| 327 }; | 322 }; |
| 328 local_7(1); | 323 local_7(1); |
| 329 EndTest(); | 324 EndTest(); |
| 330 | 325 |
| 331 | 326 |
| 332 // Single empty with block. | |
| 333 BeginTest("With block 1"); | |
| 334 | |
| 335 function with_block_1() { | |
| 336 with({}) { | |
| 337 debugger; | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 listener_delegate = function(exec_state) { | |
| 342 CheckScopeChain([debug.ScopeType.With, | |
| 343 debug.ScopeType.Local, | |
| 344 debug.ScopeType.Global], exec_state); | |
| 345 CheckScopeContent({}, 0, exec_state); | |
| 346 CheckScopeContent({}, 1, exec_state); | |
| 347 }; | |
| 348 with_block_1(); | |
| 349 EndTest(); | |
| 350 | |
| 351 | |
| 352 // Nested empty with blocks. | |
| 353 BeginTest("With block 2"); | |
| 354 | |
| 355 function with_block_2() { | |
| 356 with({}) { | |
| 357 with({}) { | |
| 358 debugger; | |
| 359 } | |
| 360 } | |
| 361 } | |
| 362 | |
| 363 listener_delegate = function(exec_state) { | |
| 364 CheckScopeChain([debug.ScopeType.With, | |
| 365 debug.ScopeType.With, | |
| 366 debug.ScopeType.Local, | |
| 367 debug.ScopeType.Global], exec_state); | |
| 368 CheckScopeContent({}, 0, exec_state); | |
| 369 CheckScopeContent({}, 1, exec_state); | |
| 370 CheckScopeContent({}, 2, exec_state); | |
| 371 }; | |
| 372 with_block_2(); | |
| 373 EndTest(); | |
| 374 | |
| 375 | |
| 376 // With block using an in-place object literal. | |
| 377 BeginTest("With block 3"); | |
| 378 | |
| 379 function with_block_3() { | |
| 380 with({a:1,b:2}) { | |
| 381 debugger; | |
| 382 } | |
| 383 } | |
| 384 | |
| 385 listener_delegate = function(exec_state) { | |
| 386 CheckScopeChain([debug.ScopeType.With, | |
| 387 debug.ScopeType.Local, | |
| 388 debug.ScopeType.Global], exec_state); | |
| 389 CheckScopeContent({a:1,b:2}, 0, exec_state); | |
| 390 }; | |
| 391 with_block_3(); | |
| 392 EndTest(); | |
| 393 | |
| 394 | |
| 395 // Nested with blocks using in-place object literals. | |
| 396 BeginTest("With block 4"); | |
| 397 | |
| 398 function with_block_4() { | |
| 399 with({a:1,b:2}) { | |
| 400 with({a:2,b:1}) { | |
| 401 debugger; | |
| 402 } | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 listener_delegate = function(exec_state) { | |
| 407 CheckScopeChain([debug.ScopeType.With, | |
| 408 debug.ScopeType.With, | |
| 409 debug.ScopeType.Local, | |
| 410 debug.ScopeType.Global], exec_state); | |
| 411 CheckScopeContent({a:2,b:1}, 0, exec_state); | |
| 412 CheckScopeContent({a:1,b:2}, 1, exec_state); | |
| 413 }; | |
| 414 with_block_4(); | |
| 415 EndTest(); | |
| 416 | |
| 417 | |
| 418 // With block and a block local variable. | |
| 419 BeginTest("With block 5"); | |
| 420 | |
| 421 function with_block_5() { | |
| 422 with({a:1}) { | |
| 423 let a = 2; | |
| 424 debugger; | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 listener_delegate = function(exec_state) { | |
| 429 CheckScopeChain([debug.ScopeType.Block, | |
| 430 debug.ScopeType.With, | |
| 431 debug.ScopeType.Local, | |
| 432 debug.ScopeType.Global], exec_state); | |
| 433 CheckScopeContent({a:2}, 0, exec_state); | |
| 434 CheckScopeContent({a:1}, 1, exec_state); | |
| 435 }; | |
| 436 with_block_5(); | |
| 437 EndTest(); | |
| 438 | |
| 439 | |
| 440 // Simple closure formed by returning an inner function referering to an outer | 327 // Simple closure formed by returning an inner function referering to an outer |
| 441 // block local variable and an outer function's parameter. | 328 // block local variable and an outer function's parameter. |
| 442 BeginTest("Closure 1"); | 329 BeginTest("Closure 1"); |
| 443 | 330 |
| 444 function closure_1(a) { | 331 function closure_1(a) { |
| 445 var x = 2; | 332 var x = 2; |
| 446 let y = 3; | 333 let y = 3; |
| 447 if (true) { | 334 if (true) { |
| 448 let z = 4; | 335 let z = 4; |
| 449 function f() { | 336 function f() { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 | 453 |
| 567 listener_delegate = function(exec_state) { | 454 listener_delegate = function(exec_state) { |
| 568 CheckScopeChain([debug.ScopeType.Block, | 455 CheckScopeChain([debug.ScopeType.Block, |
| 569 debug.ScopeType.Local, | 456 debug.ScopeType.Local, |
| 570 debug.ScopeType.Global], exec_state); | 457 debug.ScopeType.Global], exec_state); |
| 571 CheckScopeContent({x:3,y:5}, 0, exec_state); | 458 CheckScopeContent({x:3,y:5}, 0, exec_state); |
| 572 CheckScopeContent({}, 1, exec_state); | 459 CheckScopeContent({}, 1, exec_state); |
| 573 }; | 460 }; |
| 574 for_loop_5(); | 461 for_loop_5(); |
| 575 EndTest(); | 462 EndTest(); |
| OLD | NEW |