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 | 6 // Flags: --expose-debug-as debug --allow-natives-syntax |
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. |
9 | 9 |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 assertNull(exception, test_name + " / " + exception); | 52 assertNull(exception, test_name + " / " + exception); |
53 end_test_count++; | 53 end_test_count++; |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 // Check that two scope are the same. | 57 // Check that two scope are the same. |
58 function assertScopeMirrorEquals(scope1, scope2) { | 58 function assertScopeMirrorEquals(scope1, scope2) { |
59 assertEquals(scope1.scopeType(), scope2.scopeType()); | 59 assertEquals(scope1.scopeType(), scope2.scopeType()); |
60 assertEquals(scope1.frameIndex(), scope2.frameIndex()); | 60 assertEquals(scope1.frameIndex(), scope2.frameIndex()); |
61 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); | 61 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); |
62 assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value
()); | 62 assertPropertiesEqual(scope1.scopeObject().value(), |
| 63 scope2.scopeObject().value()); |
63 } | 64 } |
64 | 65 |
65 function CheckFastAllScopes(scopes, exec_state) | 66 function CheckFastAllScopes(scopes, exec_state) |
66 { | 67 { |
67 var fast_all_scopes = exec_state.frame().allScopes(true); | 68 var fast_all_scopes = exec_state.frame().allScopes(true); |
68 var length = fast_all_scopes.length; | 69 var length = fast_all_scopes.length; |
69 assertTrue(scopes.length >= length); | 70 assertTrue(scopes.length >= length); |
70 for (var i = 0; i < scopes.length && i < length; i++) { | 71 for (var i = 0; i < scopes.length && i < length; i++) { |
71 var scope = fast_all_scopes[length - i - 1]; | 72 var scope = fast_all_scopes[length - i - 1]; |
72 assertTrue(scope.isScope()); | 73 assertTrue(scope.isScope()); |
73 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); | 74 assertEquals(scopes[scopes.length - i - 1], scope.scopeType()); |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 // Check that the scope chain contains the expected types of scopes. | 79 // Check that the scope chain contains the expected types of scopes. |
79 function CheckScopeChain(scopes, exec_state) { | 80 function CheckScopeChain(scopes, exec_state) { |
80 var all_scopes = exec_state.frame().allScopes(); | 81 var all_scopes = exec_state.frame().allScopes(); |
81 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 82 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
82 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; | 83 assertEquals(scopes.length, all_scopes.length, |
| 84 "FrameMirror.allScopes length"); |
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 assertScopeMirrorEquals(all_scopes[i], scope); | 89 assertScopeMirrorEquals(all_scopes[i], scope); |
88 } | 90 } |
89 CheckFastAllScopes(scopes, exec_state); | 91 CheckFastAllScopes(scopes, exec_state); |
90 | |
91 // Get the debug command processor. | |
92 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
93 | |
94 // Send a scopes request and check the result. | |
95 var json; | |
96 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | |
97 var response_json = dcp.processDebugJSONRequest(request_json); | |
98 var response = JSON.parse(response_json); | |
99 assertEquals(scopes.length, response.body.scopes.length); | |
100 for (var i = 0; i < scopes.length; i++) { | |
101 assertEquals(i, response.body.scopes[i].index); | |
102 assertEquals(scopes[i], response.body.scopes[i].type); | |
103 if (scopes[i] == debug.ScopeType.Local || | |
104 scopes[i] == debug.ScopeType.Script || | |
105 scopes[i] == debug.ScopeType.Closure) { | |
106 assertTrue(response.body.scopes[i].object.ref < 0); | |
107 } else { | |
108 assertTrue(response.body.scopes[i].object.ref >= 0); | |
109 } | |
110 var found = false; | |
111 for (var j = 0; j < response.refs.length && !found; j++) { | |
112 found = response.refs[j].handle == response.body.scopes[i].object.ref; | |
113 } | |
114 assertTrue(found, "Scope object " + response.body.scopes[i].object.ref + " n
ot found"); | |
115 } | |
116 } | 92 } |
117 | 93 |
118 | 94 |
119 // Check that the scope chain contains the expected names of scopes. | 95 // Check that the scope chain contains the expected names of scopes. |
120 function CheckScopeChainNames(names, exec_state) { | 96 function CheckScopeChainNames(names, exec_state) { |
121 var all_scopes = exec_state.frame().allScopes(); | 97 var all_scopes = exec_state.frame().allScopes(); |
122 assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); | 98 assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length"); |
123 for (var i = 0; i < names.length; i++) { | 99 for (var i = 0; i < names.length; i++) { |
124 var scope = exec_state.frame().scope(i); | 100 var scope = exec_state.frame().scope(i); |
125 assertTrue(scope.isScope()); | 101 assertTrue(scope.isScope()); |
126 assertEquals(names[i], scope.details().name()) | 102 assertEquals(names[i], scope.details().name()) |
127 } | 103 } |
128 } | 104 } |
129 | 105 |
130 | 106 |
131 // Check that the scope contains at least minimum_content. For functions just | 107 // Check that the scope contains at least minimum_content. For functions just |
132 // check that there is a function. | 108 // check that there is a function. |
133 function CheckScopeContent(minimum_content, number, exec_state) { | 109 function CheckScopeContent(minimum_content, number, exec_state) { |
134 var scope = exec_state.frame().scope(number); | 110 var scope = exec_state.frame().scope(number); |
135 var minimum_count = 0; | 111 var minimum_count = 0; |
136 for (var p in minimum_content) { | 112 for (var p in minimum_content) { |
137 var property_mirror = scope.scopeObject().property(p); | 113 var property_mirror = scope.scopeObject().property(p); |
138 assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in
scope'); | 114 assertFalse(property_mirror.isUndefined(), |
| 115 'property ' + p + ' not found in scope'); |
139 if (typeof(minimum_content[p]) === 'function') { | 116 if (typeof(minimum_content[p]) === 'function') { |
140 assertTrue(property_mirror.value().isFunction()); | 117 assertTrue(property_mirror.value().isFunction()); |
141 } else { | 118 } else { |
142 assertEquals(minimum_content[p], property_mirror.value().value(), 'propert
y ' + p + ' has unexpected value'); | 119 assertEquals(minimum_content[p], property_mirror.value().value(), |
| 120 'property ' + p + ' has unexpected value'); |
143 } | 121 } |
144 minimum_count++; | 122 minimum_count++; |
145 } | 123 } |
146 | 124 |
147 // 'arguments' and might be exposed in the local and closure scope. Just | 125 // 'arguments' and might be exposed in the local and closure scope. Just |
148 // ignore this. | 126 // ignore this. |
149 var scope_size = scope.scopeObject().properties().length; | 127 var scope_size = scope.scopeObject().properties().length; |
150 if (!scope.scopeObject().property('arguments').isUndefined()) { | 128 if (!scope.scopeObject().property('arguments').isUndefined()) { |
151 scope_size--; | 129 scope_size--; |
152 } | 130 } |
153 // Ditto for 'this'. | 131 // Ditto for 'this'. |
154 if (!scope.scopeObject().property('this').isUndefined()) { | 132 if (!scope.scopeObject().property('this').isUndefined()) { |
155 scope_size--; | 133 scope_size--; |
156 } | 134 } |
157 // Temporary variables introduced by the parser have not been materialized. | 135 // Temporary variables introduced by the parser have not been materialized. |
158 assertTrue(scope.scopeObject().property('').isUndefined()); | 136 assertTrue(scope.scopeObject().property('').isUndefined()); |
159 | 137 |
160 if (scope_size < minimum_count) { | 138 if (scope_size < minimum_count) { |
161 print('Names found in scope:'); | 139 print('Names found in scope:'); |
162 var names = scope.scopeObject().propertyNames(); | 140 var names = scope.scopeObject().propertyNames(); |
163 for (var i = 0; i < names.length; i++) { | 141 for (var i = 0; i < names.length; i++) { |
164 print(names[i]); | 142 print(names[i]); |
165 } | 143 } |
166 } | 144 } |
167 assertTrue(scope_size >= minimum_count); | 145 assertTrue(scope_size >= minimum_count); |
168 | |
169 // Get the debug command processor. | |
170 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | |
171 | |
172 // Send a scope request for information on a single scope and check the | |
173 // result. | |
174 var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"
number":'; | |
175 request_json += scope.scopeIndex(); | |
176 request_json += '}}'; | |
177 var response_json = dcp.processDebugJSONRequest(request_json); | |
178 var response = JSON.parse(response_json); | |
179 assertEquals(scope.scopeType(), response.body.type); | |
180 assertEquals(number, response.body.index); | |
181 if (scope.scopeType() == debug.ScopeType.Local || | |
182 scope.scopeType() == debug.ScopeType.Script || | |
183 scope.scopeType() == debug.ScopeType.Closure) { | |
184 assertTrue(response.body.object.ref < 0); | |
185 } else { | |
186 assertTrue(response.body.object.ref >= 0); | |
187 } | |
188 var found = false; | |
189 for (var i = 0; i < response.refs.length && !found; i++) { | |
190 found = response.refs[i].handle == response.body.object.ref; | |
191 } | |
192 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); | |
193 } | 146 } |
194 | 147 |
195 // Check that the scopes have positions as expected. | 148 // Check that the scopes have positions as expected. |
196 function CheckScopeChainPositions(positions, exec_state) { | 149 function CheckScopeChainPositions(positions, exec_state) { |
197 var all_scopes = exec_state.frame().allScopes(); | 150 var all_scopes = exec_state.frame().allScopes(); |
198 assertTrue(positions.length <= all_scopes.length, "FrameMirror.allScopes lengt
h"); | 151 assertTrue(positions.length <= all_scopes.length, |
| 152 "FrameMirror.allScopes length"); |
199 for (var i = 0; i < positions.length; i++) { | 153 for (var i = 0; i < positions.length; i++) { |
200 var scope = exec_state.frame().scope(i); | 154 var scope = exec_state.frame().scope(i); |
201 assertTrue(scope.isScope()); | 155 assertTrue(scope.isScope()); |
202 var position = positions[i]; | 156 var position = positions[i]; |
203 if (!position) | 157 if (!position) |
204 continue; | 158 continue; |
205 | 159 |
206 print(`Checking position.start = ${position.start}, .end = ${position.end}`)
; | 160 print( |
| 161 `Checking position.start = ${position.start}, .end = ${position.end}`); |
207 assertEquals(position.start, scope.details().startPosition()) | 162 assertEquals(position.start, scope.details().startPosition()) |
208 assertEquals(position.end, scope.details().endPosition()) | 163 assertEquals(position.end, scope.details().endPosition()) |
209 } | 164 } |
210 } | 165 } |
211 | 166 |
212 // Simple empty local scope. | 167 // Simple empty local scope. |
213 BeginTest("Local 1"); | 168 BeginTest("Local 1"); |
214 | 169 |
215 function local_1() { | 170 function local_1() { |
216 debugger; | 171 debugger; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return f; | 339 return f; |
385 } | 340 } |
386 | 341 |
387 listener_delegate = function(exec_state) { | 342 listener_delegate = function(exec_state) { |
388 CheckScopeChain([debug.ScopeType.Local, | 343 CheckScopeChain([debug.ScopeType.Local, |
389 debug.ScopeType.Closure, | 344 debug.ScopeType.Closure, |
390 debug.ScopeType.Module, | 345 debug.ScopeType.Module, |
391 debug.ScopeType.Script, | 346 debug.ScopeType.Script, |
392 debug.ScopeType.Global], exec_state); | 347 debug.ScopeType.Global], exec_state); |
393 CheckScopeContent({a:1,x:3}, 1, exec_state); | 348 CheckScopeContent({a:1,x:3}, 1, exec_state); |
394 CheckScopeChainNames(["f", "closure_2", undefined, undefined, undefined], exec
_state) | 349 CheckScopeChainNames(["f", "closure_2", undefined, undefined, undefined], |
| 350 exec_state) |
395 }; | 351 }; |
396 closure_2(1, 2)(); | 352 closure_2(1, 2)(); |
397 EndTest(); | 353 EndTest(); |
398 | 354 |
399 | 355 |
400 // Simple closure formed by returning an inner function referering the outer | 356 // Simple closure formed by returning an inner function referering the outer |
401 // functions arguments. Using all arguments and locals from the outer function | 357 // functions arguments. Using all arguments and locals from the outer function |
402 // in the inner function makes these part of the debugger information on the | 358 // in the inner function makes these part of the debugger information on the |
403 // closure. | 359 // closure. |
404 BeginTest("Closure 3"); | 360 BeginTest("Closure 3"); |
405 | 361 |
406 function closure_3(a, b) { | 362 function closure_3(a, b) { |
407 var x = a + 2; | 363 var x = a + 2; |
408 var y = b + 2; | 364 var y = b + 2; |
409 function f() { | 365 function f() { |
410 debugger; | 366 debugger; |
411 return a + b + x + y; | 367 return a + b + x + y; |
412 }; | 368 }; |
413 return f; | 369 return f; |
414 } | 370 } |
415 | 371 |
416 listener_delegate = function(exec_state) { | 372 listener_delegate = function(exec_state) { |
417 CheckScopeChain([debug.ScopeType.Local, | 373 CheckScopeChain([debug.ScopeType.Local, |
418 debug.ScopeType.Closure, | 374 debug.ScopeType.Closure, |
419 debug.ScopeType.Module, | 375 debug.ScopeType.Module, |
420 debug.ScopeType.Script, | 376 debug.ScopeType.Script, |
421 debug.ScopeType.Global], exec_state); | 377 debug.ScopeType.Global], exec_state); |
422 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); | 378 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
423 CheckScopeChainNames(["f", "closure_3", undefined, undefined, undefined], exec
_state) | 379 CheckScopeChainNames(["f", "closure_3", undefined, undefined, undefined], |
| 380 exec_state) |
424 }; | 381 }; |
425 closure_3(1, 2)(); | 382 closure_3(1, 2)(); |
426 EndTest(); | 383 EndTest(); |
427 | 384 |
428 | 385 |
429 | 386 |
430 // Simple closure formed by returning an inner function referering the outer | 387 // Simple closure formed by returning an inner function referering the outer |
431 // functions arguments. Using all arguments and locals from the outer function | 388 // functions arguments. Using all arguments and locals from the outer function |
432 // in the inner function makes these part of the debugger information on the | 389 // in the inner function makes these part of the debugger information on the |
433 // closure. Use the inner function as well... | 390 // closure. Use the inner function as well... |
(...skipping 11 matching lines...) Expand all Loading... |
445 return f; | 402 return f; |
446 } | 403 } |
447 | 404 |
448 listener_delegate = function(exec_state) { | 405 listener_delegate = function(exec_state) { |
449 CheckScopeChain([debug.ScopeType.Local, | 406 CheckScopeChain([debug.ScopeType.Local, |
450 debug.ScopeType.Closure, | 407 debug.ScopeType.Closure, |
451 debug.ScopeType.Module, | 408 debug.ScopeType.Module, |
452 debug.ScopeType.Script, | 409 debug.ScopeType.Script, |
453 debug.ScopeType.Global], exec_state); | 410 debug.ScopeType.Global], exec_state); |
454 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 411 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
455 CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined], exec
_state) | 412 CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined], |
| 413 exec_state) |
456 }; | 414 }; |
457 closure_4(1, 2)(); | 415 closure_4(1, 2)(); |
458 EndTest(); | 416 EndTest(); |
459 | 417 |
460 | 418 |
461 | 419 |
462 // Simple closure formed by returning an inner function referering the outer | 420 // Simple closure formed by returning an inner function referering the outer |
463 // functions arguments. In the presence of eval all arguments and locals | 421 // functions arguments. In the presence of eval all arguments and locals |
464 // (including the inner function itself) from the outer function becomes part of | 422 // (including the inner function itself) from the outer function becomes part of |
465 // the debugger infformation on the closure. | 423 // the debugger infformation on the closure. |
(...skipping 10 matching lines...) Expand all Loading... |
476 return f; | 434 return f; |
477 } | 435 } |
478 | 436 |
479 listener_delegate = function(exec_state) { | 437 listener_delegate = function(exec_state) { |
480 CheckScopeChain([debug.ScopeType.Local, | 438 CheckScopeChain([debug.ScopeType.Local, |
481 debug.ScopeType.Closure, | 439 debug.ScopeType.Closure, |
482 debug.ScopeType.Module, | 440 debug.ScopeType.Module, |
483 debug.ScopeType.Script, | 441 debug.ScopeType.Script, |
484 debug.ScopeType.Global], exec_state); | 442 debug.ScopeType.Global], exec_state); |
485 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 443 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
486 CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined], exec
_state) | 444 CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined], |
| 445 exec_state) |
487 }; | 446 }; |
488 closure_5(1, 2)(); | 447 closure_5(1, 2)(); |
489 EndTest(); | 448 EndTest(); |
490 | 449 |
491 | 450 |
492 // Two closures. Due to optimizations only the parts actually used are provided | 451 // Two closures. Due to optimizations only the parts actually used are provided |
493 // through the debugger information. | 452 // through the debugger information. |
494 BeginTest("Closure 6"); | 453 BeginTest("Closure 6"); |
495 let some_global; | 454 let some_global; |
496 function closure_6(a, b) { | 455 function closure_6(a, b) { |
(...skipping 13 matching lines...) Expand all Loading... |
510 | 469 |
511 listener_delegate = function(exec_state) { | 470 listener_delegate = function(exec_state) { |
512 CheckScopeChain([debug.ScopeType.Local, | 471 CheckScopeChain([debug.ScopeType.Local, |
513 debug.ScopeType.Closure, | 472 debug.ScopeType.Closure, |
514 debug.ScopeType.Closure, | 473 debug.ScopeType.Closure, |
515 debug.ScopeType.Module, | 474 debug.ScopeType.Module, |
516 debug.ScopeType.Script, | 475 debug.ScopeType.Script, |
517 debug.ScopeType.Global], exec_state); | 476 debug.ScopeType.Global], exec_state); |
518 CheckScopeContent({a:1}, 1, exec_state); | 477 CheckScopeContent({a:1}, 1, exec_state); |
519 CheckScopeContent({f:function(){}}, 2, exec_state); | 478 CheckScopeContent({f:function(){}}, 2, exec_state); |
520 CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined, undef
ined], exec_state) | 479 CheckScopeChainNames( |
| 480 [undefined, "f", "closure_6", undefined, undefined, undefined], |
| 481 exec_state); |
521 }; | 482 }; |
522 closure_6(1, 2)(); | 483 closure_6(1, 2)(); |
523 EndTest(); | 484 EndTest(); |
524 | 485 |
525 | 486 |
526 // Two closures. In the presence of eval all information is provided as the | 487 // Two closures. In the presence of eval all information is provided as the |
527 // compiler cannot determine which parts are used. | 488 // compiler cannot determine which parts are used. |
528 BeginTest("Closure 7"); | 489 BeginTest("Closure 7"); |
529 function closure_7(a, b) { | 490 function closure_7(a, b) { |
530 var x = 3; | 491 var x = 3; |
(...skipping 17 matching lines...) Expand all Loading... |
548 listener_delegate = function(exec_state) { | 509 listener_delegate = function(exec_state) { |
549 CheckScopeChain([debug.ScopeType.Local, | 510 CheckScopeChain([debug.ScopeType.Local, |
550 debug.ScopeType.Closure, | 511 debug.ScopeType.Closure, |
551 debug.ScopeType.Closure, | 512 debug.ScopeType.Closure, |
552 debug.ScopeType.Module, | 513 debug.ScopeType.Module, |
553 debug.ScopeType.Script, | 514 debug.ScopeType.Script, |
554 debug.ScopeType.Global], exec_state); | 515 debug.ScopeType.Global], exec_state); |
555 CheckScopeContent({}, 0, exec_state); | 516 CheckScopeContent({}, 0, exec_state); |
556 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); | 517 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
557 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 2, exec_state); | 518 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 2, exec_state); |
558 CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined, undef
ined], exec_state) | 519 CheckScopeChainNames( |
| 520 [undefined, "f", "closure_7", undefined, undefined, undefined], |
| 521 exec_state); |
559 }; | 522 }; |
560 closure_7(1, 2)(); | 523 closure_7(1, 2)(); |
561 EndTest(); | 524 EndTest(); |
562 | 525 |
563 | 526 |
564 // Closure that may be optimized out. | 527 // Closure that may be optimized out. |
565 BeginTest("Closure 8"); | 528 BeginTest("Closure 8"); |
566 function closure_8() { | 529 function closure_8() { |
567 (function inner(x) { | 530 (function inner(x) { |
568 debugger; | 531 debugger; |
569 })(2); | 532 })(2); |
570 } | 533 } |
571 | 534 |
572 listener_delegate = function(exec_state) { | 535 listener_delegate = function(exec_state) { |
573 CheckScopeChain([debug.ScopeType.Local, | 536 CheckScopeChain([debug.ScopeType.Local, |
574 debug.ScopeType.Module, | 537 debug.ScopeType.Module, |
575 debug.ScopeType.Script, | 538 debug.ScopeType.Script, |
576 debug.ScopeType.Global], exec_state); | 539 debug.ScopeType.Global], exec_state); |
577 CheckScopeContent({x: 2}, 0, exec_state); | 540 CheckScopeContent({x: 2}, 0, exec_state); |
578 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state) | 541 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state); |
579 }; | 542 }; |
580 closure_8(); | 543 closure_8(); |
581 EndTest(); | 544 EndTest(); |
582 | 545 |
583 | 546 |
584 BeginTest("Closure 9"); | 547 BeginTest("Closure 9"); |
585 let closure_9 = Function(' \ | 548 let closure_9 = Function(' \ |
586 eval("var y = 1;"); \ | 549 eval("var y = 1;"); \ |
587 eval("var z = 1;"); \ | 550 eval("var z = 1;"); \ |
588 (function inner(x) { \ | 551 (function inner(x) { \ |
589 y++; \ | 552 y++; \ |
590 z++; \ | 553 z++; \ |
591 debugger; \ | 554 debugger; \ |
592 })(2); \ | 555 })(2); \ |
593 ') | 556 ') |
594 | 557 |
595 listener_delegate = function(exec_state) { | 558 listener_delegate = function(exec_state) { |
596 CheckScopeChain([debug.ScopeType.Local, | 559 CheckScopeChain([debug.ScopeType.Local, |
597 debug.ScopeType.Closure, | 560 debug.ScopeType.Closure, |
598 debug.ScopeType.Script, | 561 debug.ScopeType.Script, |
599 debug.ScopeType.Global], exec_state); | 562 debug.ScopeType.Global], exec_state); |
600 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state) | 563 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state); |
601 }; | 564 }; |
602 closure_9(); | 565 closure_9(); |
603 EndTest(); | 566 EndTest(); |
604 | 567 |
605 | 568 |
606 // Test global scope. | 569 // Test global scope. |
607 BeginTest("Global"); | 570 BeginTest("Global"); |
608 listener_delegate = function(exec_state) { | 571 listener_delegate = function(exec_state) { |
609 CheckScopeChain([debug.ScopeType.Module, debug.ScopeType.Script, debug.ScopeTy
pe.Global], exec_state); | 572 CheckScopeChain( |
610 CheckScopeChainNames([undefined, undefined, undefined], exec_state) | 573 [debug.ScopeType.Module, debug.ScopeType.Script, debug.ScopeType.Global], |
| 574 exec_state); |
| 575 CheckScopeChainNames([undefined, undefined, undefined], exec_state); |
611 }; | 576 }; |
612 debugger; | 577 debugger; |
613 EndTest(); | 578 EndTest(); |
614 | 579 |
615 | 580 |
616 BeginTest("Catch block 1"); | 581 BeginTest("Catch block 1"); |
617 function catch_block_1() { | 582 function catch_block_1() { |
618 try { | 583 try { |
619 throw 'Exception'; | 584 throw 'Exception'; |
620 } catch (e) { | 585 } catch (e) { |
621 debugger; | 586 debugger; |
622 } | 587 } |
623 }; | 588 }; |
624 | 589 |
625 | 590 |
626 listener_delegate = function(exec_state) { | 591 listener_delegate = function(exec_state) { |
627 CheckScopeChain([debug.ScopeType.Catch, | 592 CheckScopeChain([debug.ScopeType.Catch, |
628 debug.ScopeType.Local, | 593 debug.ScopeType.Local, |
629 debug.ScopeType.Module, | 594 debug.ScopeType.Module, |
630 debug.ScopeType.Script, | 595 debug.ScopeType.Script, |
631 debug.ScopeType.Global], exec_state); | 596 debug.ScopeType.Global], exec_state); |
632 CheckScopeContent({e:'Exception'}, 0, exec_state); | 597 CheckScopeContent({e:'Exception'}, 0, exec_state); |
633 CheckScopeChainNames(["catch_block_1", "catch_block_1", undefined, undefined,
undefined], exec_state) | 598 CheckScopeChainNames( |
| 599 ["catch_block_1", "catch_block_1", undefined, undefined, undefined], |
| 600 exec_state); |
634 }; | 601 }; |
635 catch_block_1(); | 602 catch_block_1(); |
636 EndTest(); | 603 EndTest(); |
637 | 604 |
638 | 605 |
639 BeginTest("Catch block 3"); | 606 BeginTest("Catch block 3"); |
640 function catch_block_3() { | 607 function catch_block_3() { |
641 eval("var y = 78;"); | 608 eval("var y = 78;"); |
642 try { | 609 try { |
643 throw 'Exception'; | 610 throw 'Exception'; |
644 } catch (e) { | 611 } catch (e) { |
645 debugger; | 612 debugger; |
646 } | 613 } |
647 }; | 614 }; |
648 | 615 |
649 | 616 |
650 listener_delegate = function(exec_state) { | 617 listener_delegate = function(exec_state) { |
651 CheckScopeChain([debug.ScopeType.Catch, | 618 CheckScopeChain([debug.ScopeType.Catch, |
652 debug.ScopeType.Local, | 619 debug.ScopeType.Local, |
653 debug.ScopeType.Module, | 620 debug.ScopeType.Module, |
654 debug.ScopeType.Script, | 621 debug.ScopeType.Script, |
655 debug.ScopeType.Global], exec_state); | 622 debug.ScopeType.Global], exec_state); |
656 CheckScopeContent({e:'Exception'}, 0, exec_state); | 623 CheckScopeContent({e:'Exception'}, 0, exec_state); |
657 CheckScopeContent({}, 1, exec_state); | 624 CheckScopeContent({}, 1, exec_state); |
658 CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined,
undefined], exec_state) | 625 CheckScopeChainNames( |
| 626 ["catch_block_3", "catch_block_3", undefined, undefined, undefined], |
| 627 exec_state); |
659 }; | 628 }; |
660 catch_block_3(); | 629 catch_block_3(); |
661 EndTest(); | 630 EndTest(); |
662 | 631 |
663 | 632 |
664 // Test catch in global scope. | 633 // Test catch in global scope. |
665 BeginTest("Catch block 5"); | 634 BeginTest("Catch block 5"); |
666 listener_delegate = function(exec_state) { | 635 listener_delegate = function(exec_state) { |
667 CheckScopeChain([debug.ScopeType.Catch, | 636 CheckScopeChain([debug.ScopeType.Catch, |
668 debug.ScopeType.Module, | 637 debug.ScopeType.Module, |
669 debug.ScopeType.Script, | 638 debug.ScopeType.Script, |
670 debug.ScopeType.Global], exec_state); | 639 debug.ScopeType.Global], exec_state); |
671 CheckScopeContent({e:'Exception'}, 0, exec_state); | 640 CheckScopeContent({e:'Exception'}, 0, exec_state); |
672 CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) | 641 CheckScopeChainNames([undefined, undefined, undefined, undefined], |
| 642 exec_state); |
673 }; | 643 }; |
674 | 644 |
675 try { | 645 try { |
676 throw 'Exception'; | 646 throw 'Exception'; |
677 } catch (e) { | 647 } catch (e) { |
678 debugger; | 648 debugger; |
679 } | 649 } |
680 | 650 |
681 EndTest(); | 651 EndTest(); |
682 | 652 |
683 | 653 |
684 // Closure inside catch in global code. | 654 // Closure inside catch in global code. |
685 BeginTest("Catch block 6"); | 655 BeginTest("Catch block 6"); |
686 listener_delegate = function(exec_state) { | 656 listener_delegate = function(exec_state) { |
687 CheckScopeChain([debug.ScopeType.Local, | 657 CheckScopeChain([debug.ScopeType.Local, |
688 debug.ScopeType.Catch, | 658 debug.ScopeType.Catch, |
689 debug.ScopeType.Module, | 659 debug.ScopeType.Module, |
690 debug.ScopeType.Script, | 660 debug.ScopeType.Script, |
691 debug.ScopeType.Global], exec_state); | 661 debug.ScopeType.Global], exec_state); |
692 CheckScopeContent({x: 2}, 0, exec_state); | 662 CheckScopeContent({x: 2}, 0, exec_state); |
693 CheckScopeContent({e:'Exception'}, 1, exec_state); | 663 CheckScopeContent({e:'Exception'}, 1, exec_state); |
694 CheckScopeChainNames([undefined, undefined, undefined, undefined, undefined],
exec_state) | 664 CheckScopeChainNames([undefined, undefined, undefined, undefined, undefined], |
| 665 exec_state); |
695 }; | 666 }; |
696 | 667 |
697 try { | 668 try { |
698 throw 'Exception'; | 669 throw 'Exception'; |
699 } catch (e) { | 670 } catch (e) { |
700 (function(x) { | 671 (function(x) { |
701 debugger; | 672 debugger; |
702 })(2); | 673 })(2); |
703 } | 674 } |
704 EndTest(); | 675 EndTest(); |
(...skipping 11 matching lines...) Expand all Loading... |
716 }; | 687 }; |
717 | 688 |
718 | 689 |
719 listener_delegate = function(exec_state) { | 690 listener_delegate = function(exec_state) { |
720 CheckScopeChain([debug.ScopeType.Catch, | 691 CheckScopeChain([debug.ScopeType.Catch, |
721 debug.ScopeType.Local, | 692 debug.ScopeType.Local, |
722 debug.ScopeType.Module, | 693 debug.ScopeType.Module, |
723 debug.ScopeType.Script, | 694 debug.ScopeType.Script, |
724 debug.ScopeType.Global], exec_state); | 695 debug.ScopeType.Global], exec_state); |
725 CheckScopeContent({e:'Exception'}, 0, exec_state); | 696 CheckScopeContent({e:'Exception'}, 0, exec_state); |
726 CheckScopeChainNames(["catch_block_7", "catch_block_7", undefined, undefined,
undefined], exec_state) | 697 CheckScopeChainNames( |
| 698 ["catch_block_7", "catch_block_7", undefined, undefined, undefined], |
| 699 exec_state); |
727 }; | 700 }; |
728 catch_block_7(); | 701 catch_block_7(); |
729 EndTest(); | 702 EndTest(); |
730 | 703 |
731 | 704 |
732 BeginTest("Classes and methods 1"); | 705 BeginTest("Classes and methods 1"); |
733 | 706 |
734 listener_delegate = function(exec_state) { | 707 listener_delegate = function(exec_state) { |
735 "use strict" | 708 "use strict" |
736 CheckScopeChain([debug.ScopeType.Local, | 709 CheckScopeChain([debug.ScopeType.Local, |
737 debug.ScopeType.Module, | 710 debug.ScopeType.Module, |
738 debug.ScopeType.Script, | 711 debug.ScopeType.Script, |
739 debug.ScopeType.Global], exec_state); | 712 debug.ScopeType.Global], exec_state); |
740 CheckScopeContent({}, 1, exec_state); | 713 CheckScopeContent({}, 1, exec_state); |
741 CheckScopeChainNames(["m", undefined, undefined, undefined], exec_state) | 714 CheckScopeChainNames(["m", undefined, undefined, undefined], exec_state); |
742 }; | 715 }; |
743 | 716 |
744 (function() { | 717 (function() { |
745 "use strict"; | 718 "use strict"; |
746 class C1 { | 719 class C1 { |
747 m() { | 720 m() { |
748 debugger; | 721 debugger; |
749 } | 722 } |
750 } | 723 } |
751 new C1().m(); | 724 new C1().m(); |
752 })(); | 725 })(); |
753 | 726 |
754 EndTest(); | 727 EndTest(); |
755 | 728 |
756 BeginTest("Scope positions"); | 729 BeginTest("Scope positions"); |
757 var code1 = "function f() { \n" + | 730 var code1 = "function f() { \n" + |
758 " var a = 1; \n" + | 731 " var a = 1; \n" + |
759 " function b() { \n" + | 732 " function b() { \n" + |
760 " debugger; \n" + | 733 " debugger; \n" + |
761 " return a + 1; \n" + | 734 " return a + 1; \n" + |
762 " } \n" + | 735 " } \n" + |
763 " b(); \n" + | 736 " b(); \n" + |
764 "} \n" + | 737 "} \n" + |
765 "f(); \n"; | 738 "f(); \n"; |
766 | 739 |
767 listener_delegate = function(exec_state) { | 740 listener_delegate = function(exec_state) { |
768 CheckScopeChainPositions([{start: 58, end: 118}, {start: 10, end: 162}], exec_
state); | 741 CheckScopeChainPositions([{start: 58, end: 118}, {start: 10, end: 162}], |
| 742 exec_state); |
769 } | 743 } |
770 eval(code1); | 744 eval(code1); |
771 EndTest(); | 745 EndTest(); |
772 | 746 |
773 | 747 |
774 BeginTest("Scope positions in for statement"); | 748 BeginTest("Scope positions in for statement"); |
775 var code3 = "function for_statement() { \n" + | 749 var code3 = "function for_statement() { \n" + |
776 " for (let i = 0; i < 1; i++) { \n" + | 750 " for (let i = 0; i < 1; i++) { \n" + |
777 " debugger; \n" + | 751 " debugger; \n" + |
778 " } \n" + | 752 " } \n" + |
779 "} \n" + | 753 "} \n" + |
780 "for_statement(); \n"; | 754 "for_statement(); \n"; |
781 | 755 |
782 listener_delegate = function(exec_state) { | 756 listener_delegate = function(exec_state) { |
783 CheckScopeChain([debug.ScopeType.Block, | 757 CheckScopeChain([debug.ScopeType.Block, |
784 debug.ScopeType.Local, | 758 debug.ScopeType.Local, |
785 debug.ScopeType.Module, | 759 debug.ScopeType.Module, |
786 debug.ScopeType.Script, | 760 debug.ScopeType.Script, |
787 debug.ScopeType.Global], exec_state); | 761 debug.ScopeType.Global], exec_state); |
788 CheckScopeChainPositions([{start: 52, end: 111}, {start: 22, end: 145}], exec_
state); | 762 CheckScopeChainPositions([{start: 52, end: 111}, {start: 22, end: 145}], |
| 763 exec_state); |
789 } | 764 } |
790 eval(code3); | 765 eval(code3); |
791 EndTest(); | 766 EndTest(); |
792 | 767 |
793 BeginTest("Scope positions in for statement with lexical block"); | 768 BeginTest("Scope positions in for statement with lexical block"); |
794 var code4 = "function for_statement() { \n" + | 769 var code4 = "function for_statement() { \n" + |
795 " for (let i = 0; i < 1; i++) { \n" + | 770 " for (let i = 0; i < 1; i++) { \n" + |
796 " let j; \n" + | 771 " let j; \n" + |
797 " debugger; \n" + | 772 " debugger; \n" + |
798 " } \n" + | 773 " } \n" + |
799 "} \n" + | 774 "} \n" + |
800 "for_statement(); \n"; | 775 "for_statement(); \n"; |
801 | 776 |
802 listener_delegate = function(exec_state) { | 777 listener_delegate = function(exec_state) { |
803 CheckScopeChain([debug.ScopeType.Block, | 778 CheckScopeChain([debug.ScopeType.Block, |
804 debug.ScopeType.Block, | 779 debug.ScopeType.Block, |
805 debug.ScopeType.Local, | 780 debug.ScopeType.Local, |
806 debug.ScopeType.Module, | 781 debug.ScopeType.Module, |
807 debug.ScopeType.Script, | 782 debug.ScopeType.Script, |
808 debug.ScopeType.Global], exec_state); | 783 debug.ScopeType.Global], exec_state); |
809 CheckScopeChainPositions([{start: 66, end: 147}, {start: 52, end: 147}, {start
: 22, end: 181}], exec_state); | 784 CheckScopeChainPositions([{start: 66, end: 147}, |
| 785 {start: 52, end: 147}, |
| 786 {start: 22, end: 181}], exec_state); |
810 } | 787 } |
811 eval(code4); | 788 eval(code4); |
812 EndTest(); | 789 EndTest(); |
813 | 790 |
814 BeginTest("Scope positions in lexical for each statement"); | 791 BeginTest("Scope positions in lexical for each statement"); |
815 var code5 = "function for_each_statement() { \n" + | 792 var code5 = "function for_each_statement() { \n" + |
816 " for (let i of [0]) { \n" + | 793 " for (let i of [0]) { \n" + |
817 " debugger; \n" + | 794 " debugger; \n" + |
818 " } \n" + | 795 " } \n" + |
819 "} \n" + | 796 "} \n" + |
820 "for_each_statement(); \n"; | 797 "for_each_statement(); \n"; |
821 | 798 |
822 listener_delegate = function(exec_state) { | 799 listener_delegate = function(exec_state) { |
823 CheckScopeChain([debug.ScopeType.Block, | 800 CheckScopeChain([debug.ScopeType.Block, |
824 debug.ScopeType.Local, | 801 debug.ScopeType.Local, |
825 debug.ScopeType.Module, | 802 debug.ScopeType.Module, |
826 debug.ScopeType.Script, | 803 debug.ScopeType.Script, |
827 debug.ScopeType.Global], exec_state); | 804 debug.ScopeType.Global], exec_state); |
828 CheckScopeChainPositions([{start: 55, end: 111}, {start: 27, end: 145}], exec_
state); | 805 CheckScopeChainPositions([{start: 55, end: 111}, {start: 27, end: 145}], |
| 806 exec_state); |
829 } | 807 } |
830 eval(code5); | 808 eval(code5); |
831 EndTest(); | 809 EndTest(); |
832 | 810 |
833 BeginTest("Scope positions in lexical for each statement with lexical block"); | 811 BeginTest("Scope positions in lexical for each statement with lexical block"); |
834 var code6 = "function for_each_statement() { \n" + | 812 var code6 = "function for_each_statement() { \n" + |
835 " for (let i of [0]) { \n" + | 813 " for (let i of [0]) { \n" + |
836 " let j; \n" + | 814 " let j; \n" + |
837 " debugger; \n" + | 815 " debugger; \n" + |
838 " } \n" + | 816 " } \n" + |
839 "} \n" + | 817 "} \n" + |
840 "for_each_statement(); \n"; | 818 "for_each_statement(); \n"; |
841 | 819 |
842 listener_delegate = function(exec_state) { | 820 listener_delegate = function(exec_state) { |
843 CheckScopeChain([debug.ScopeType.Block, | 821 CheckScopeChain([debug.ScopeType.Block, |
844 debug.ScopeType.Block, | 822 debug.ScopeType.Block, |
845 debug.ScopeType.Local, | 823 debug.ScopeType.Local, |
846 debug.ScopeType.Module, | 824 debug.ScopeType.Module, |
847 debug.ScopeType.Script, | 825 debug.ScopeType.Script, |
848 debug.ScopeType.Global], exec_state); | 826 debug.ScopeType.Global], exec_state); |
849 CheckScopeChainPositions([{start: 57, end: 147}, {start: 55, end: 147}, {start
: 27, end: 181}], exec_state); | 827 CheckScopeChainPositions([{start: 57, end: 147}, |
| 828 {start: 55, end: 147}, |
| 829 {start: 27, end: 181}], exec_state); |
850 } | 830 } |
851 eval(code6); | 831 eval(code6); |
852 EndTest(); | 832 EndTest(); |
853 | 833 |
854 BeginTest("Scope positions in non-lexical for each statement"); | 834 BeginTest("Scope positions in non-lexical for each statement"); |
855 var code7 = "function for_each_statement() { \n" + | 835 var code7 = "function for_each_statement() { \n" + |
856 " var i; \n" + | 836 " var i; \n" + |
857 " for (i of [0]) { \n" + | 837 " for (i of [0]) { \n" + |
858 " debugger; \n" + | 838 " debugger; \n" + |
859 " } \n" + | 839 " } \n" + |
860 "} \n" + | 840 "} \n" + |
861 "for_each_statement(); \n"; | 841 "for_each_statement(); \n"; |
862 | 842 |
863 listener_delegate = function(exec_state) { | 843 listener_delegate = function(exec_state) { |
864 CheckScopeChain([debug.ScopeType.Local, | 844 CheckScopeChain([debug.ScopeType.Local, |
865 debug.ScopeType.Module, | 845 debug.ScopeType.Module, |
866 debug.ScopeType.Script, | 846 debug.ScopeType.Script, |
867 debug.ScopeType.Global], exec_state); | 847 debug.ScopeType.Global], exec_state); |
868 CheckScopeChainPositions([{start: 27, end: 181}], exec_state); | 848 CheckScopeChainPositions([{start: 27, end: 181}], exec_state); |
869 } | 849 } |
870 eval(code7); | 850 eval(code7); |
871 EndTest(); | 851 EndTest(); |
872 | 852 |
873 BeginTest("Scope positions in non-lexical for each statement with lexical block"
); | 853 BeginTest( |
| 854 "Scope positions in non-lexical for each statement with lexical block"); |
874 var code8 = "function for_each_statement() { \n" + | 855 var code8 = "function for_each_statement() { \n" + |
875 " var i; \n" + | 856 " var i; \n" + |
876 " for (i of [0]) { \n" + | 857 " for (i of [0]) { \n" + |
877 " let j; \n" + | 858 " let j; \n" + |
878 " debugger; \n" + | 859 " debugger; \n" + |
879 " } \n" + | 860 " } \n" + |
880 "} \n" + | 861 "} \n" + |
881 "for_each_statement(); \n"; | 862 "for_each_statement(); \n"; |
882 | 863 |
883 listener_delegate = function(exec_state) { | 864 listener_delegate = function(exec_state) { |
884 CheckScopeChain([debug.ScopeType.Block, | 865 CheckScopeChain([debug.ScopeType.Block, |
885 debug.ScopeType.Local, | 866 debug.ScopeType.Local, |
886 debug.ScopeType.Module, | 867 debug.ScopeType.Module, |
887 debug.ScopeType.Script, | 868 debug.ScopeType.Script, |
888 debug.ScopeType.Global], exec_state); | 869 debug.ScopeType.Global], exec_state); |
889 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}], exec_
state); | 870 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}], |
| 871 exec_state); |
890 } | 872 } |
891 eval(code8); | 873 eval(code8); |
892 EndTest(); | 874 EndTest(); |
893 | 875 |
894 assertEquals(begin_test_count, break_count, | 876 assertEquals(begin_test_count, break_count, |
895 'one or more tests did not enter the debugger'); | 877 'one or more tests did not enter the debugger'); |
896 assertEquals(begin_test_count, end_test_count, | 878 assertEquals(begin_test_count, end_test_count, |
897 'one or more tests did not have its result checked'); | 879 'one or more tests did not have its result checked'); |
OLD | NEW |