OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 // MODULE | 5 // MODULE |
6 // Flags: --expose-debug-as debug --allow-natives-syntax --noanalyze-environment -liveness | 6 // Flags: --allow-natives-syntax --noanalyze-environment-liveness |
7 | 7 |
8 // These tests are copied from mjsunit/debug-scopes.js and adapted for modules. | 8 // These tests are copied from mjsunit/debug-scopes.js and adapted for modules. |
jgruber
2016/12/12 13:23:48
Nit: mjsunit -> debugger/
| |
9 | 9 |
10 | 10 |
11 var Debug = debug.Debug; | 11 var Debug = debug.Debug; |
12 | 12 |
13 var test_name; | 13 var test_name; |
14 var listener_delegate; | 14 var listener_delegate; |
15 var listener_called; | 15 var listener_called; |
16 var exception; | 16 var exception; |
17 var begin_test_count = 0; | 17 var begin_test_count = 0; |
18 var end_test_count = 0; | 18 var end_test_count = 0; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 scope2.scopeObject().value()); | 63 scope2.scopeObject().value()); |
64 } | 64 } |
65 | 65 |
66 function CheckFastAllScopes(scopes, exec_state) | 66 function CheckFastAllScopes(scopes, exec_state) |
67 { | 67 { |
68 var fast_all_scopes = exec_state.frame().allScopes(true); | 68 var fast_all_scopes = exec_state.frame().allScopes(true); |
69 var length = fast_all_scopes.length; | 69 var length = fast_all_scopes.length; |
70 assertTrue(scopes.length >= length); | 70 assertTrue(scopes.length >= length); |
71 for (var i = 0; i < scopes.length && i < length; i++) { | 71 for (var i = 0; i < scopes.length && i < length; i++) { |
72 var scope = fast_all_scopes[length - i - 1]; | 72 var scope = fast_all_scopes[length - i - 1]; |
73 assertTrue(scope.isScope()); | |
74 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); | 73 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 | 77 |
79 // Check that the scope chain contains the expected types of scopes. | 78 // Check that the scope chain contains the expected types of scopes. |
80 function CheckScopeChain(scopes, exec_state) { | 79 function CheckScopeChain(scopes, exec_state) { |
81 var all_scopes = exec_state.frame().allScopes(); | 80 var all_scopes = exec_state.frame().allScopes(); |
82 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 81 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
83 assertEquals(scopes.length, all_scopes.length, | 82 assertEquals(scopes.length, all_scopes.length, |
84 "FrameMirror.allScopes length"); | 83 "FrameMirror.allScopes length"); |
85 for (var i = 0; i < scopes.length; i++) { | 84 for (var i = 0; i < scopes.length; i++) { |
86 var scope = exec_state.frame().scope(i); | 85 var scope = exec_state.frame().scope(i); |
87 assertTrue(scope.isScope()); | |
88 assertEquals(scopes[i], scope.scopeType()); | 86 assertEquals(scopes[i], scope.scopeType()); |
89 assertScopeMirrorEquals(all_scopes[i], scope); | 87 assertScopeMirrorEquals(all_scopes[i], scope); |
90 } | 88 } |
91 CheckFastAllScopes(scopes, exec_state); | 89 CheckFastAllScopes(scopes, exec_state); |
92 } | 90 } |
93 | 91 |
94 | 92 |
95 // Check that the scope chain contains the expected names of scopes. | 93 // Check that the scope chain contains the expected names of scopes. |
96 function CheckScopeChainNames(names, exec_state) { | 94 function CheckScopeChainNames(names, exec_state) { |
97 var all_scopes = exec_state.frame().allScopes(); | 95 var all_scopes = exec_state.frame().allScopes(); |
98 assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); | 96 assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); |
99 for (var i = 0; i < names.length; i++) { | 97 for (var i = 0; i < names.length; i++) { |
100 var scope = exec_state.frame().scope(i); | 98 var scope = exec_state.frame().scope(i); |
101 assertTrue(scope.isScope()); | |
102 assertEquals(names[i], scope.details().name()) | 99 assertEquals(names[i], scope.details().name()) |
103 } | 100 } |
104 } | 101 } |
105 | 102 |
106 | 103 |
107 // Check that the scope contains at least minimum_content. For functions just | 104 // Check that the scope contains at least minimum_content. For functions just |
108 // check that there is a function. | 105 // check that there is a function. |
109 function CheckScopeContent(minimum_content, number, exec_state) { | 106 function CheckScopeContent(minimum_content, number, exec_state) { |
110 var scope = exec_state.frame().scope(number); | 107 var scope = exec_state.frame().scope(number); |
111 var minimum_count = 0; | 108 var minimum_count = 0; |
112 for (var p in minimum_content) { | 109 for (var p in minimum_content) { |
113 var property_mirror = scope.scopeObject().property(p); | 110 var property_mirror = scope.scopeObject().property(p); |
114 assertFalse(property_mirror.isUndefined(), | 111 assertFalse(property_mirror.isUndefined(), |
115 'property ' + p + ' not found in scope'); | 112 'property ' + p + ' not found in scope'); |
116 if (typeof(minimum_content[p]) === 'function') { | 113 assertEquals(minimum_content[p], property_mirror.value().value(), |
117 assertTrue(property_mirror.value().isFunction()); | 114 'property ' + p + ' has unexpected value'); |
118 } else { | |
119 assertEquals(minimum_content[p], property_mirror.value().value(), | |
120 'property ' + p + ' has unexpected value'); | |
121 } | |
122 minimum_count++; | 115 minimum_count++; |
123 } | 116 } |
124 | 117 |
125 // 'arguments' and might be exposed in the local and closure scope. Just | 118 // 'arguments' and might be exposed in the local and closure scope. Just |
126 // ignore this. | 119 // ignore this. |
127 var scope_size = scope.scopeObject().properties().length; | 120 var scope_size = scope.scopeObject().properties().length; |
128 if (!scope.scopeObject().property('arguments').isUndefined()) { | 121 if (!scope.scopeObject().property('arguments').isUndefined()) { |
129 scope_size--; | 122 scope_size--; |
130 } | 123 } |
131 // Ditto for 'this'. | 124 // Ditto for 'this'. |
(...skipping 13 matching lines...) Expand all Loading... | |
145 assertTrue(scope_size >= minimum_count); | 138 assertTrue(scope_size >= minimum_count); |
146 } | 139 } |
147 | 140 |
148 // Check that the scopes have positions as expected. | 141 // Check that the scopes have positions as expected. |
149 function CheckScopeChainPositions(positions, exec_state) { | 142 function CheckScopeChainPositions(positions, exec_state) { |
150 var all_scopes = exec_state.frame().allScopes(); | 143 var all_scopes = exec_state.frame().allScopes(); |
151 assertTrue(positions.length <= all_scopes.length, | 144 assertTrue(positions.length <= all_scopes.length, |
152 "FrameMirror.allScopes length"); | 145 "FrameMirror.allScopes length"); |
153 for (var i = 0; i < positions.length; i++) { | 146 for (var i = 0; i < positions.length; i++) { |
154 var scope = exec_state.frame().scope(i); | 147 var scope = exec_state.frame().scope(i); |
155 assertTrue(scope.isScope()); | |
156 var position = positions[i]; | 148 var position = positions[i]; |
157 if (!position) | 149 if (!position) |
158 continue; | 150 continue; |
159 | 151 |
160 print( | 152 print( |
161 `Checking position.start = ${position.start}, .end = ${position.end}`); | 153 `Checking position.start = ${position.start}, .end = ${position.end}`); |
162 assertEquals(position.start, scope.details().startPosition()) | 154 assertEquals(position.start, scope.details().startPosition()) |
163 assertEquals(position.end, scope.details().endPosition()) | 155 assertEquals(position.end, scope.details().endPosition()) |
164 } | 156 } |
165 } | 157 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 }; | 393 }; |
402 return f; | 394 return f; |
403 } | 395 } |
404 | 396 |
405 listener_delegate = function(exec_state) { | 397 listener_delegate = function(exec_state) { |
406 CheckScopeChain([debug.ScopeType.Local, | 398 CheckScopeChain([debug.ScopeType.Local, |
407 debug.ScopeType.Closure, | 399 debug.ScopeType.Closure, |
408 debug.ScopeType.Module, | 400 debug.ScopeType.Module, |
409 debug.ScopeType.Script, | 401 debug.ScopeType.Script, |
410 debug.ScopeType.Global], exec_state); | 402 debug.ScopeType.Global], exec_state); |
411 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 403 CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 1, exec_state); |
412 CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined], | 404 CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined], |
413 exec_state) | 405 exec_state) |
414 }; | 406 }; |
415 closure_4(1, 2)(); | 407 closure_4(1, 2)(); |
416 EndTest(); | 408 EndTest(); |
417 | 409 |
418 | 410 |
419 | 411 |
420 // Simple closure formed by returning an inner function referering the outer | 412 // Simple closure formed by returning an inner function referering the outer |
421 // functions arguments. In the presence of eval all arguments and locals | 413 // functions arguments. In the presence of eval all arguments and locals |
(...skipping 11 matching lines...) Expand all Loading... | |
433 }; | 425 }; |
434 return f; | 426 return f; |
435 } | 427 } |
436 | 428 |
437 listener_delegate = function(exec_state) { | 429 listener_delegate = function(exec_state) { |
438 CheckScopeChain([debug.ScopeType.Local, | 430 CheckScopeChain([debug.ScopeType.Local, |
439 debug.ScopeType.Closure, | 431 debug.ScopeType.Closure, |
440 debug.ScopeType.Module, | 432 debug.ScopeType.Module, |
441 debug.ScopeType.Script, | 433 debug.ScopeType.Script, |
442 debug.ScopeType.Global], exec_state); | 434 debug.ScopeType.Global], exec_state); |
443 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 435 CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 1, exec_state); |
444 CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined], | 436 CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined], |
445 exec_state) | 437 exec_state) |
446 }; | 438 }; |
447 closure_5(1, 2)(); | 439 closure_5(1, 2)(); |
448 EndTest(); | 440 EndTest(); |
449 | 441 |
450 | 442 |
451 // Two closures. Due to optimizations only the parts actually used are provided | 443 // Two closures. Due to optimizations only the parts actually used are provided |
452 // through the debugger information. | 444 // through the debugger information. |
453 BeginTest("Closure 6"); | 445 BeginTest("Closure 6"); |
(...skipping 14 matching lines...) Expand all Loading... | |
468 } | 460 } |
469 | 461 |
470 listener_delegate = function(exec_state) { | 462 listener_delegate = function(exec_state) { |
471 CheckScopeChain([debug.ScopeType.Local, | 463 CheckScopeChain([debug.ScopeType.Local, |
472 debug.ScopeType.Closure, | 464 debug.ScopeType.Closure, |
473 debug.ScopeType.Closure, | 465 debug.ScopeType.Closure, |
474 debug.ScopeType.Module, | 466 debug.ScopeType.Module, |
475 debug.ScopeType.Script, | 467 debug.ScopeType.Script, |
476 debug.ScopeType.Global], exec_state); | 468 debug.ScopeType.Global], exec_state); |
477 CheckScopeContent({a:1}, 1, exec_state); | 469 CheckScopeContent({a:1}, 1, exec_state); |
478 CheckScopeContent({f:function(){}}, 2, exec_state); | 470 CheckScopeContent({f:undefined}, 2, exec_state); |
479 CheckScopeChainNames( | 471 CheckScopeChainNames( |
480 [undefined, "f", "closure_6", undefined, undefined, undefined], | 472 [undefined, "f", "closure_6", undefined, undefined, undefined], |
481 exec_state); | 473 exec_state); |
482 }; | 474 }; |
483 closure_6(1, 2)(); | 475 closure_6(1, 2)(); |
484 EndTest(); | 476 EndTest(); |
485 | 477 |
486 | 478 |
487 // Two closures. In the presence of eval all information is provided as the | 479 // Two closures. In the presence of eval all information is provided as the |
488 // compiler cannot determine which parts are used. | 480 // compiler cannot determine which parts are used. |
(...skipping 19 matching lines...) Expand all Loading... | |
508 | 500 |
509 listener_delegate = function(exec_state) { | 501 listener_delegate = function(exec_state) { |
510 CheckScopeChain([debug.ScopeType.Local, | 502 CheckScopeChain([debug.ScopeType.Local, |
511 debug.ScopeType.Closure, | 503 debug.ScopeType.Closure, |
512 debug.ScopeType.Closure, | 504 debug.ScopeType.Closure, |
513 debug.ScopeType.Module, | 505 debug.ScopeType.Module, |
514 debug.ScopeType.Script, | 506 debug.ScopeType.Script, |
515 debug.ScopeType.Global], exec_state); | 507 debug.ScopeType.Global], exec_state); |
516 CheckScopeContent({}, 0, exec_state); | 508 CheckScopeContent({}, 0, exec_state); |
517 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); | 509 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
518 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 2, exec_state); | 510 CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 2, exec_state); |
519 CheckScopeChainNames( | 511 CheckScopeChainNames( |
520 [undefined, "f", "closure_7", undefined, undefined, undefined], | 512 [undefined, "f", "closure_7", undefined, undefined, undefined], |
521 exec_state); | 513 exec_state); |
522 }; | 514 }; |
523 closure_7(1, 2)(); | 515 closure_7(1, 2)(); |
524 EndTest(); | 516 EndTest(); |
525 | 517 |
526 | 518 |
527 // Closure that may be optimized out. | 519 // Closure that may be optimized out. |
528 BeginTest("Closure 8"); | 520 BeginTest("Closure 8"); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}], | 862 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}], |
871 exec_state); | 863 exec_state); |
872 } | 864 } |
873 eval(code8); | 865 eval(code8); |
874 EndTest(); | 866 EndTest(); |
875 | 867 |
876 assertEquals(begin_test_count, break_count, | 868 assertEquals(begin_test_count, break_count, |
877 'one or more tests did not enter the debugger'); | 869 'one or more tests did not enter the debugger'); |
878 assertEquals(begin_test_count, end_test_count, | 870 assertEquals(begin_test_count, end_test_count, |
879 'one or more tests did not have its result checked'); | 871 'one or more tests did not have its result checked'); |
OLD | NEW |