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 24 matching lines...) Expand all Loading... | |
69 } | 71 } |
70 | 72 |
71 | 73 |
72 // Check result of a test. | 74 // Check result of a test. |
73 function EndTest() { | 75 function EndTest() { |
74 assertTrue(listener_called, "listerner not called for " + test_name); | 76 assertTrue(listener_called, "listerner not called for " + test_name); |
75 assertNull(exception, test_name); | 77 assertNull(exception, test_name); |
76 end_test_count++; | 78 end_test_count++; |
77 } | 79 } |
78 | 80 |
81 var global_object = this; | |
79 | 82 |
80 // Check that the scope chain contains the expected types of scopes. | 83 // Check that the scope chain contains the expected types of scopes. |
81 function CheckScopeChain(scopes, exec_state) { | 84 function CheckScopeChain(scopes, exec_state) { |
82 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 85 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
83 for (var i = 0; i < scopes.length; i++) { | 86 for (var i = 0; i < scopes.length; i++) { |
84 var scope = exec_state.frame().scope(i); | 87 var scope = exec_state.frame().scope(i); |
85 assertTrue(scope.isScope()); | 88 assertTrue(scope.isScope()); |
86 assertEquals(scopes[i], scope.scopeType()); | 89 assertEquals(scopes[i], scope.scopeType()); |
90 } | |
87 | 91 |
88 // Check the global object when hitting the global scope. | 92 // Check the global object when hitting the global scope. |
rossberg
2011/11/09 12:15:29
Reinserted at the wrong place. ;-)
| |
89 if (scopes[i] == debug.ScopeType.Global) { | 93 if (scopes[i] == debug.ScopeType.Global) { |
90 // Objects don't have same class (one is "global", other is "Object", | 94 // Objects don't have same class (one is "global", other is "Object", |
91 // so just check the properties directly. | 95 // so just check the properties directly. |
92 assertPropertiesEqual(this, scope.scopeObject().value()); | 96 assertPropertiesEqual(global_object, scope.scopeObject().value()); |
93 } | |
94 } | 97 } |
95 | 98 |
96 // Get the debug command processor. | 99 // Get the debug command processor. |
97 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 100 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
98 | 101 |
99 // Send a scopes request and check the result. | 102 // Send a scopes request and check the result. |
100 var json; | 103 var json; |
101 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | 104 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
102 var response_json = dcp.processDebugJSONRequest(request_json); | 105 var response_json = dcp.processDebugJSONRequest(request_json); |
103 var response = JSON.parse(response_json); | 106 var response = JSON.parse(response_json); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 CheckScopeChain([debug.ScopeType.Block, | 325 CheckScopeChain([debug.ScopeType.Block, |
323 debug.ScopeType.Local, | 326 debug.ScopeType.Local, |
324 debug.ScopeType.Global], exec_state); | 327 debug.ScopeType.Global], exec_state); |
325 CheckScopeContent({x:8}, 0, exec_state); | 328 CheckScopeContent({x:8}, 0, exec_state); |
326 CheckScopeContent({a:1}, 1, exec_state); | 329 CheckScopeContent({a:1}, 1, exec_state); |
327 }; | 330 }; |
328 local_7(1); | 331 local_7(1); |
329 EndTest(); | 332 EndTest(); |
330 | 333 |
331 | 334 |
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 | 335 // Simple closure formed by returning an inner function referering to an outer |
441 // block local variable and an outer function's parameter. | 336 // block local variable and an outer function's parameter. |
442 BeginTest("Closure 1"); | 337 BeginTest("Closure 1"); |
443 | 338 |
444 function closure_1(a) { | 339 function closure_1(a) { |
445 var x = 2; | 340 var x = 2; |
446 let y = 3; | 341 let y = 3; |
447 if (true) { | 342 if (true) { |
448 let z = 4; | 343 let z = 4; |
449 function f() { | 344 function f() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 | 461 |
567 listener_delegate = function(exec_state) { | 462 listener_delegate = function(exec_state) { |
568 CheckScopeChain([debug.ScopeType.Block, | 463 CheckScopeChain([debug.ScopeType.Block, |
569 debug.ScopeType.Local, | 464 debug.ScopeType.Local, |
570 debug.ScopeType.Global], exec_state); | 465 debug.ScopeType.Global], exec_state); |
571 CheckScopeContent({x:3,y:5}, 0, exec_state); | 466 CheckScopeContent({x:3,y:5}, 0, exec_state); |
572 CheckScopeContent({}, 1, exec_state); | 467 CheckScopeContent({}, 1, exec_state); |
573 }; | 468 }; |
574 for_loop_5(); | 469 for_loop_5(); |
575 EndTest(); | 470 EndTest(); |
OLD | NEW |