OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // modification, are permitted provided that the following conditions are | 3 // found in the LICENSE file. |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
27 | 4 |
| 5 // MODULE |
28 // Flags: --expose-debug-as debug --allow-natives-syntax | 6 // Flags: --expose-debug-as debug --allow-natives-syntax |
29 // The functions used for testing backtraces. They are at the top to make the | |
30 // testing of source line/column easier. | |
31 | 7 |
32 // Get the Debug object exposed from the debug context global object. | 8 // These tests are copied from mjsunit/debug-scopes.js and adapted for modules. |
| 9 |
| 10 |
33 var Debug = debug.Debug; | 11 var Debug = debug.Debug; |
34 | 12 |
35 var test_name; | 13 var test_name; |
36 var listener_delegate; | 14 var listener_delegate; |
37 var listener_called; | 15 var listener_called; |
38 var exception; | 16 var exception; |
39 var begin_test_count = 0; | 17 var begin_test_count = 0; |
40 var end_test_count = 0; | 18 var end_test_count = 0; |
41 var break_count = 0; | 19 var break_count = 0; |
42 | 20 |
(...skipping 20 matching lines...) Expand all Loading... |
63 test_name = name; | 41 test_name = name; |
64 listener_delegate = null; | 42 listener_delegate = null; |
65 listener_called = false; | 43 listener_called = false; |
66 exception = null; | 44 exception = null; |
67 begin_test_count++; | 45 begin_test_count++; |
68 } | 46 } |
69 | 47 |
70 | 48 |
71 // Check result of a test. | 49 // Check result of a test. |
72 function EndTest() { | 50 function EndTest() { |
73 assertTrue(listener_called, "listerner not called for " + test_name); | 51 assertTrue(listener_called, "listener not called for " + test_name); |
74 assertNull(exception, test_name + " / " + exception); | 52 assertNull(exception, test_name + " / " + exception); |
75 end_test_count++; | 53 end_test_count++; |
76 } | 54 } |
77 | 55 |
78 | 56 |
79 // Check that two scope are the same. | 57 // Check that two scope are the same. |
80 function assertScopeMirrorEquals(scope1, scope2) { | 58 function assertScopeMirrorEquals(scope1, scope2) { |
81 assertEquals(scope1.scopeType(), scope2.scopeType()); | 59 assertEquals(scope1.scopeType(), scope2.scopeType()); |
82 assertEquals(scope1.frameIndex(), scope2.frameIndex()); | 60 assertEquals(scope1.frameIndex(), scope2.frameIndex()); |
83 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); | 61 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); |
(...skipping 16 matching lines...) Expand all Loading... |
100 // Check that the scope chain contains the expected types of scopes. | 78 // Check that the scope chain contains the expected types of scopes. |
101 function CheckScopeChain(scopes, exec_state) { | 79 function CheckScopeChain(scopes, exec_state) { |
102 var all_scopes = exec_state.frame().allScopes(); | 80 var all_scopes = exec_state.frame().allScopes(); |
103 assertEquals(scopes.length, exec_state.frame().scopeCount()); | 81 assertEquals(scopes.length, exec_state.frame().scopeCount()); |
104 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; | 82 assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length")
; |
105 for (var i = 0; i < scopes.length; i++) { | 83 for (var i = 0; i < scopes.length; i++) { |
106 var scope = exec_state.frame().scope(i); | 84 var scope = exec_state.frame().scope(i); |
107 assertTrue(scope.isScope()); | 85 assertTrue(scope.isScope()); |
108 assertEquals(scopes[i], scope.scopeType()); | 86 assertEquals(scopes[i], scope.scopeType()); |
109 assertScopeMirrorEquals(all_scopes[i], scope); | 87 assertScopeMirrorEquals(all_scopes[i], scope); |
110 | |
111 // Check the global object when hitting the global scope. | |
112 if (scopes[i] == debug.ScopeType.Global) { | |
113 // Objects don't have same class (one is "global", other is "Object", | |
114 // so just check the properties directly. | |
115 assertPropertiesEqual(this, scope.scopeObject().value()); | |
116 } | |
117 } | 88 } |
118 CheckFastAllScopes(scopes, exec_state); | 89 CheckFastAllScopes(scopes, exec_state); |
119 | 90 |
120 // Get the debug command processor. | 91 // Get the debug command processor. |
121 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); | 92 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); |
122 | 93 |
123 // Send a scopes request and check the result. | 94 // Send a scopes request and check the result. |
124 var json; | 95 var json; |
125 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; | 96 var request_json = '{"seq":0,"type":"request","command":"scopes"}'; |
126 var response_json = dcp.processDebugJSONRequest(request_json); | 97 var response_json = dcp.processDebugJSONRequest(request_json); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 var found = false; | 188 var found = false; |
218 for (var i = 0; i < response.refs.length && !found; i++) { | 189 for (var i = 0; i < response.refs.length && !found; i++) { |
219 found = response.refs[i].handle == response.body.object.ref; | 190 found = response.refs[i].handle == response.body.object.ref; |
220 } | 191 } |
221 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); | 192 assertTrue(found, "Scope object " + response.body.object.ref + " not found"); |
222 } | 193 } |
223 | 194 |
224 // Check that the scopes have positions as expected. | 195 // Check that the scopes have positions as expected. |
225 function CheckScopeChainPositions(positions, exec_state) { | 196 function CheckScopeChainPositions(positions, exec_state) { |
226 var all_scopes = exec_state.frame().allScopes(); | 197 var all_scopes = exec_state.frame().allScopes(); |
227 assertEquals(positions.length, all_scopes.length, "FrameMirror.allScopes lengt
h"); | 198 assertTrue(positions.length <= all_scopes.length, "FrameMirror.allScopes lengt
h"); |
228 for (var i = 0; i < positions.length; i++) { | 199 for (var i = 0; i < positions.length; i++) { |
229 var scope = exec_state.frame().scope(i); | 200 var scope = exec_state.frame().scope(i); |
230 assertTrue(scope.isScope()); | 201 assertTrue(scope.isScope()); |
231 var position = positions[i]; | 202 var position = positions[i]; |
232 if (!position) | 203 if (!position) |
233 continue; | 204 continue; |
234 | 205 |
| 206 print(`Checking position.start = ${position.start}, .end = ${position.end}`)
; |
235 assertEquals(position.start, scope.details().startPosition()) | 207 assertEquals(position.start, scope.details().startPosition()) |
236 assertEquals(position.end, scope.details().endPosition()) | 208 assertEquals(position.end, scope.details().endPosition()) |
237 } | 209 } |
238 } | 210 } |
239 | 211 |
240 // Simple empty local scope. | 212 // Simple empty local scope. |
241 BeginTest("Local 1"); | 213 BeginTest("Local 1"); |
242 | 214 |
243 function local_1() { | 215 function local_1() { |
244 debugger; | 216 debugger; |
245 } | 217 } |
246 | 218 |
247 listener_delegate = function(exec_state) { | 219 listener_delegate = function(exec_state) { |
248 CheckScopeChain([debug.ScopeType.Local, | 220 CheckScopeChain([debug.ScopeType.Local, |
| 221 debug.ScopeType.Module, |
249 debug.ScopeType.Script, | 222 debug.ScopeType.Script, |
250 debug.ScopeType.Global], exec_state); | 223 debug.ScopeType.Global], exec_state); |
251 CheckScopeContent({}, 0, exec_state); | 224 CheckScopeContent({}, 0, exec_state); |
252 }; | 225 }; |
253 local_1(); | 226 local_1(); |
254 EndTest(); | 227 EndTest(); |
255 | 228 |
256 | 229 |
257 // Local scope with a parameter. | 230 // Local scope with a parameter. |
258 BeginTest("Local 2"); | 231 BeginTest("Local 2"); |
259 | 232 |
260 function local_2(a) { | 233 function local_2(a) { |
261 debugger; | 234 debugger; |
262 } | 235 } |
263 | 236 |
264 listener_delegate = function(exec_state) { | 237 listener_delegate = function(exec_state) { |
265 CheckScopeChain([debug.ScopeType.Local, | 238 CheckScopeChain([debug.ScopeType.Local, |
| 239 debug.ScopeType.Module, |
266 debug.ScopeType.Script, | 240 debug.ScopeType.Script, |
267 debug.ScopeType.Global], exec_state); | 241 debug.ScopeType.Global], exec_state); |
268 CheckScopeContent({a:1}, 0, exec_state); | 242 CheckScopeContent({a:1}, 0, exec_state); |
269 }; | 243 }; |
270 local_2(1); | 244 local_2(1); |
271 EndTest(); | 245 EndTest(); |
272 | 246 |
273 | 247 |
274 // Local scope with a parameter and a local variable. | 248 // Local scope with a parameter and a local variable. |
275 BeginTest("Local 3"); | 249 BeginTest("Local 3"); |
276 | 250 |
277 function local_3(a) { | 251 function local_3(a) { |
278 var x = 3; | 252 var x = 3; |
279 debugger; | 253 debugger; |
280 } | 254 } |
281 | 255 |
282 listener_delegate = function(exec_state) { | 256 listener_delegate = function(exec_state) { |
283 CheckScopeChain([debug.ScopeType.Local, | 257 CheckScopeChain([debug.ScopeType.Local, |
| 258 debug.ScopeType.Module, |
284 debug.ScopeType.Script, | 259 debug.ScopeType.Script, |
285 debug.ScopeType.Global], exec_state); | 260 debug.ScopeType.Global], exec_state); |
286 CheckScopeContent({a:1,x:3}, 0, exec_state); | 261 CheckScopeContent({a:1,x:3}, 0, exec_state); |
287 }; | 262 }; |
288 local_3(1); | 263 local_3(1); |
289 EndTest(); | 264 EndTest(); |
290 | 265 |
291 | 266 |
292 // Local scope with parameters and local variables. | 267 // Local scope with parameters and local variables. |
293 BeginTest("Local 4"); | 268 BeginTest("Local 4"); |
294 | 269 |
295 function local_4(a, b) { | 270 function local_4(a, b) { |
296 var x = 3; | 271 var x = 3; |
297 var y = 4; | 272 var y = 4; |
298 debugger; | 273 debugger; |
299 } | 274 } |
300 | 275 |
301 listener_delegate = function(exec_state) { | 276 listener_delegate = function(exec_state) { |
302 CheckScopeChain([debug.ScopeType.Local, | 277 CheckScopeChain([debug.ScopeType.Local, |
| 278 debug.ScopeType.Module, |
303 debug.ScopeType.Script, | 279 debug.ScopeType.Script, |
304 debug.ScopeType.Global], exec_state); | 280 debug.ScopeType.Global], exec_state); |
305 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); | 281 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); |
306 }; | 282 }; |
307 local_4(1, 2); | 283 local_4(1, 2); |
308 EndTest(); | 284 EndTest(); |
309 | 285 |
310 | 286 |
311 // Empty local scope with use of eval. | 287 // Empty local scope with use of eval. |
312 BeginTest("Local 5"); | 288 BeginTest("Local 5"); |
313 | 289 |
314 function local_5() { | 290 function local_5() { |
315 eval(''); | 291 eval(''); |
316 debugger; | 292 debugger; |
317 } | 293 } |
318 | 294 |
319 listener_delegate = function(exec_state) { | 295 listener_delegate = function(exec_state) { |
320 CheckScopeChain([debug.ScopeType.Local, | 296 CheckScopeChain([debug.ScopeType.Local, |
| 297 debug.ScopeType.Module, |
321 debug.ScopeType.Script, | 298 debug.ScopeType.Script, |
322 debug.ScopeType.Global], exec_state); | 299 debug.ScopeType.Global], exec_state); |
323 CheckScopeContent({}, 0, exec_state); | 300 CheckScopeContent({}, 0, exec_state); |
324 }; | 301 }; |
325 local_5(); | 302 local_5(); |
326 EndTest(); | 303 EndTest(); |
327 | 304 |
328 | 305 |
329 // Local introducing local variable using eval. | 306 // Local introducing local variable using eval. |
330 BeginTest("Local 6"); | 307 BeginTest("Local 6"); |
331 | 308 |
332 function local_6() { | 309 function local_6() { |
333 eval('var i = 5'); | 310 eval('var i = 5'); |
334 debugger; | 311 debugger; |
335 } | 312 } |
336 | 313 |
337 listener_delegate = function(exec_state) { | 314 listener_delegate = function(exec_state) { |
338 CheckScopeChain([debug.ScopeType.Local, | 315 CheckScopeChain([debug.ScopeType.Local, |
| 316 debug.ScopeType.Module, |
339 debug.ScopeType.Script, | 317 debug.ScopeType.Script, |
340 debug.ScopeType.Global], exec_state); | 318 debug.ScopeType.Global], exec_state); |
341 CheckScopeContent({i:5}, 0, exec_state); | 319 CheckScopeContent({}, 0, exec_state); |
342 }; | 320 }; |
343 local_6(); | 321 local_6(); |
344 EndTest(); | 322 EndTest(); |
345 | 323 |
346 | 324 |
347 // Local scope with parameters, local variables and local variable introduced | 325 // Local scope with parameters and local variables. |
348 // using eval. | |
349 BeginTest("Local 7"); | 326 BeginTest("Local 7"); |
350 | 327 |
351 function local_7(a, b) { | 328 function local_7(a, b) { |
352 var x = 3; | 329 var x = 3; |
353 var y = 4; | 330 var y = 4; |
354 eval('var i = 5'); | 331 eval('var i = 5'); |
355 eval('var j = 6'); | 332 eval('var j = 6'); |
356 debugger; | 333 debugger; |
357 } | 334 } |
358 | 335 |
359 listener_delegate = function(exec_state) { | 336 listener_delegate = function(exec_state) { |
360 CheckScopeChain([debug.ScopeType.Local, | 337 CheckScopeChain([debug.ScopeType.Local, |
| 338 debug.ScopeType.Module, |
361 debug.ScopeType.Script, | 339 debug.ScopeType.Script, |
362 debug.ScopeType.Global], exec_state); | 340 debug.ScopeType.Global], exec_state); |
363 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); | 341 CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state); |
364 }; | 342 }; |
365 local_7(1, 2); | 343 local_7(1, 2); |
366 EndTest(); | 344 EndTest(); |
367 | 345 |
368 | 346 |
369 // Single empty with block. | |
370 BeginTest("With 1"); | |
371 | |
372 function with_1() { | |
373 with({}) { | |
374 debugger; | |
375 } | |
376 } | |
377 | |
378 listener_delegate = function(exec_state) { | |
379 CheckScopeChain([debug.ScopeType.With, | |
380 debug.ScopeType.Local, | |
381 debug.ScopeType.Script, | |
382 debug.ScopeType.Global], exec_state); | |
383 CheckScopeContent({}, 0, exec_state); | |
384 }; | |
385 with_1(); | |
386 EndTest(); | |
387 | |
388 | |
389 // Nested empty with blocks. | |
390 BeginTest("With 2"); | |
391 | |
392 function with_2() { | |
393 with({}) { | |
394 with({}) { | |
395 debugger; | |
396 } | |
397 } | |
398 } | |
399 | |
400 listener_delegate = function(exec_state) { | |
401 CheckScopeChain([debug.ScopeType.With, | |
402 debug.ScopeType.With, | |
403 debug.ScopeType.Local, | |
404 debug.ScopeType.Script, | |
405 debug.ScopeType.Global], exec_state); | |
406 CheckScopeContent({}, 0, exec_state); | |
407 CheckScopeContent({}, 1, exec_state); | |
408 }; | |
409 with_2(); | |
410 EndTest(); | |
411 | |
412 | |
413 // With block using an in-place object literal. | |
414 BeginTest("With 3"); | |
415 | |
416 function with_3() { | |
417 with({a:1,b:2}) { | |
418 debugger; | |
419 } | |
420 } | |
421 | |
422 listener_delegate = function(exec_state) { | |
423 CheckScopeChain([debug.ScopeType.With, | |
424 debug.ScopeType.Local, | |
425 debug.ScopeType.Script, | |
426 debug.ScopeType.Global], exec_state); | |
427 CheckScopeContent({a:1,b:2}, 0, exec_state); | |
428 }; | |
429 with_3(); | |
430 EndTest(); | |
431 | |
432 | |
433 // Nested with blocks using in-place object literals. | |
434 BeginTest("With 4"); | |
435 | |
436 function with_4() { | |
437 with({a:1,b:2}) { | |
438 with({a:2,b:1}) { | |
439 debugger; | |
440 } | |
441 } | |
442 } | |
443 | |
444 listener_delegate = function(exec_state) { | |
445 CheckScopeChain([debug.ScopeType.With, | |
446 debug.ScopeType.With, | |
447 debug.ScopeType.Local, | |
448 debug.ScopeType.Script, | |
449 debug.ScopeType.Global], exec_state); | |
450 CheckScopeContent({a:2,b:1}, 0, exec_state); | |
451 CheckScopeContent({a:1,b:2}, 1, exec_state); | |
452 }; | |
453 with_4(); | |
454 EndTest(); | |
455 | |
456 | |
457 // Nested with blocks using existing object. | |
458 BeginTest("With 5"); | |
459 | |
460 var with_object = {c:3,d:4}; | |
461 function with_5() { | |
462 with(with_object) { | |
463 with(with_object) { | |
464 debugger; | |
465 } | |
466 } | |
467 } | |
468 | |
469 listener_delegate = function(exec_state) { | |
470 CheckScopeChain([debug.ScopeType.With, | |
471 debug.ScopeType.With, | |
472 debug.ScopeType.Local, | |
473 debug.ScopeType.Script, | |
474 debug.ScopeType.Global], exec_state); | |
475 CheckScopeContent(with_object, 0, exec_state); | |
476 CheckScopeContent(with_object, 1, exec_state); | |
477 assertEquals(exec_state.frame().scope(0).scopeObject(), exec_state.frame().sco
pe(1).scopeObject()); | |
478 assertEquals(with_object, exec_state.frame().scope(1).scopeObject().value()); | |
479 }; | |
480 with_5(); | |
481 EndTest(); | |
482 | |
483 | |
484 // Nested with blocks using existing object in global code. | |
485 BeginTest("With 6"); | |
486 listener_delegate = function(exec_state) { | |
487 CheckScopeChain([debug.ScopeType.With, | |
488 debug.ScopeType.With, | |
489 debug.ScopeType.Script, | |
490 debug.ScopeType.Global], exec_state); | |
491 CheckScopeContent(with_object, 0, exec_state); | |
492 CheckScopeContent(with_object, 1, exec_state); | |
493 assertEquals(exec_state.frame().scope(0).scopeObject(), exec_state.frame().sco
pe(1).scopeObject()); | |
494 assertEquals(with_object, exec_state.frame().scope(1).scopeObject().value()); | |
495 }; | |
496 | |
497 var with_object = {c:3,d:4}; | |
498 with(with_object) { | |
499 with(with_object) { | |
500 debugger; | |
501 } | |
502 } | |
503 EndTest(); | |
504 | |
505 | |
506 // With block in function that is marked for optimization while being executed. | |
507 BeginTest("With 7"); | |
508 | |
509 function with_7() { | |
510 with({}) { | |
511 %OptimizeFunctionOnNextCall(with_7); | |
512 debugger; | |
513 } | |
514 } | |
515 | |
516 listener_delegate = function(exec_state) { | |
517 CheckScopeChain([debug.ScopeType.With, | |
518 debug.ScopeType.Local, | |
519 debug.ScopeType.Script, | |
520 debug.ScopeType.Global], exec_state); | |
521 CheckScopeContent({}, 0, exec_state); | |
522 }; | |
523 with_7(); | |
524 EndTest(); | |
525 | |
526 | |
527 // Simple closure formed by returning an inner function referering the outer | 347 // Simple closure formed by returning an inner function referering the outer |
528 // functions arguments. | 348 // functions arguments. |
529 BeginTest("Closure 1"); | 349 BeginTest("Closure 1"); |
530 | 350 |
531 function closure_1(a) { | 351 function closure_1(a) { |
532 function f() { | 352 function f() { |
533 debugger; | 353 debugger; |
534 return a; | 354 return a; |
535 }; | 355 }; |
536 return f; | 356 return f; |
537 } | 357 } |
538 | 358 |
539 listener_delegate = function(exec_state) { | 359 listener_delegate = function(exec_state) { |
540 CheckScopeChain([debug.ScopeType.Local, | 360 CheckScopeChain([debug.ScopeType.Local, |
541 debug.ScopeType.Closure, | 361 debug.ScopeType.Closure, |
| 362 debug.ScopeType.Module, |
542 debug.ScopeType.Script, | 363 debug.ScopeType.Script, |
543 debug.ScopeType.Global], exec_state); | 364 debug.ScopeType.Global], exec_state); |
544 CheckScopeContent({a:1}, 1, exec_state); | 365 CheckScopeContent({a:1}, 1, exec_state); |
545 CheckScopeChainNames(["f", "closure_1", undefined, undefined], exec_state) | 366 CheckScopeChainNames(["f", "closure_1", undefined, undefined, undefined], exec
_state) |
546 }; | 367 }; |
547 closure_1(1)(); | 368 closure_1(1)(); |
548 EndTest(); | 369 EndTest(); |
549 | 370 |
550 | 371 |
551 // Simple closure formed by returning an inner function referering the outer | 372 // Simple closure formed by returning an inner function referering the outer |
552 // functions arguments. Due to VM optimizations parts of the actual closure is | 373 // functions arguments. Due to VM optimizations parts of the actual closure is |
553 // missing from the debugger information. | 374 // missing from the debugger information. |
554 BeginTest("Closure 2"); | 375 BeginTest("Closure 2"); |
555 | 376 |
556 function closure_2(a, b) { | 377 function closure_2(a, b) { |
557 var x = a + 2; | 378 var x = a + 2; |
558 var y = b + 2; | 379 var y = b + 2; |
559 function f() { | 380 function f() { |
560 debugger; | 381 debugger; |
561 return a + x; | 382 return a + x; |
562 }; | 383 }; |
563 return f; | 384 return f; |
564 } | 385 } |
565 | 386 |
566 listener_delegate = function(exec_state) { | 387 listener_delegate = function(exec_state) { |
567 CheckScopeChain([debug.ScopeType.Local, | 388 CheckScopeChain([debug.ScopeType.Local, |
568 debug.ScopeType.Closure, | 389 debug.ScopeType.Closure, |
| 390 debug.ScopeType.Module, |
569 debug.ScopeType.Script, | 391 debug.ScopeType.Script, |
570 debug.ScopeType.Global], exec_state); | 392 debug.ScopeType.Global], exec_state); |
571 CheckScopeContent({a:1,x:3}, 1, exec_state); | 393 CheckScopeContent({a:1,x:3}, 1, exec_state); |
572 CheckScopeChainNames(["f", "closure_2", undefined, undefined], exec_state) | 394 CheckScopeChainNames(["f", "closure_2", undefined, undefined, undefined], exec
_state) |
573 }; | 395 }; |
574 closure_2(1, 2)(); | 396 closure_2(1, 2)(); |
575 EndTest(); | 397 EndTest(); |
576 | 398 |
577 | 399 |
578 // Simple closure formed by returning an inner function referering the outer | 400 // Simple closure formed by returning an inner function referering the outer |
579 // functions arguments. Using all arguments and locals from the outer function | 401 // functions arguments. Using all arguments and locals from the outer function |
580 // in the inner function makes these part of the debugger information on the | 402 // in the inner function makes these part of the debugger information on the |
581 // closure. | 403 // closure. |
582 BeginTest("Closure 3"); | 404 BeginTest("Closure 3"); |
583 | 405 |
584 function closure_3(a, b) { | 406 function closure_3(a, b) { |
585 var x = a + 2; | 407 var x = a + 2; |
586 var y = b + 2; | 408 var y = b + 2; |
587 function f() { | 409 function f() { |
588 debugger; | 410 debugger; |
589 return a + b + x + y; | 411 return a + b + x + y; |
590 }; | 412 }; |
591 return f; | 413 return f; |
592 } | 414 } |
593 | 415 |
594 listener_delegate = function(exec_state) { | 416 listener_delegate = function(exec_state) { |
595 CheckScopeChain([debug.ScopeType.Local, | 417 CheckScopeChain([debug.ScopeType.Local, |
596 debug.ScopeType.Closure, | 418 debug.ScopeType.Closure, |
| 419 debug.ScopeType.Module, |
597 debug.ScopeType.Script, | 420 debug.ScopeType.Script, |
598 debug.ScopeType.Global], exec_state); | 421 debug.ScopeType.Global], exec_state); |
599 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); | 422 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
600 CheckScopeChainNames(["f", "closure_3", undefined, undefined], exec_state) | 423 CheckScopeChainNames(["f", "closure_3", undefined, undefined, undefined], exec
_state) |
601 }; | 424 }; |
602 closure_3(1, 2)(); | 425 closure_3(1, 2)(); |
603 EndTest(); | 426 EndTest(); |
604 | 427 |
605 | 428 |
606 | 429 |
607 // Simple closure formed by returning an inner function referering the outer | 430 // Simple closure formed by returning an inner function referering the outer |
608 // functions arguments. Using all arguments and locals from the outer function | 431 // functions arguments. Using all arguments and locals from the outer function |
609 // in the inner function makes these part of the debugger information on the | 432 // in the inner function makes these part of the debugger information on the |
610 // closure. Use the inner function as well... | 433 // closure. Use the inner function as well... |
611 BeginTest("Closure 4"); | 434 BeginTest("Closure 4"); |
612 | 435 |
613 function closure_4(a, b) { | 436 function closure_4(a, b) { |
614 var x = a + 2; | 437 var x = a + 2; |
615 var y = b + 2; | 438 var y = b + 2; |
616 function f() { | 439 function f() { |
617 debugger; | 440 debugger; |
618 if (f) { | 441 if (f) { |
619 return a + b + x + y; | 442 return a + b + x + y; |
620 } | 443 } |
621 }; | 444 }; |
622 return f; | 445 return f; |
623 } | 446 } |
624 | 447 |
625 listener_delegate = function(exec_state) { | 448 listener_delegate = function(exec_state) { |
626 CheckScopeChain([debug.ScopeType.Local, | 449 CheckScopeChain([debug.ScopeType.Local, |
627 debug.ScopeType.Closure, | 450 debug.ScopeType.Closure, |
| 451 debug.ScopeType.Module, |
628 debug.ScopeType.Script, | 452 debug.ScopeType.Script, |
629 debug.ScopeType.Global], exec_state); | 453 debug.ScopeType.Global], exec_state); |
630 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 454 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
631 CheckScopeChainNames(["f", "closure_4", undefined, undefined], exec_state) | 455 CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined], exec
_state) |
632 }; | 456 }; |
633 closure_4(1, 2)(); | 457 closure_4(1, 2)(); |
634 EndTest(); | 458 EndTest(); |
635 | 459 |
636 | 460 |
637 | 461 |
638 // Simple closure formed by returning an inner function referering the outer | 462 // Simple closure formed by returning an inner function referering the outer |
639 // functions arguments. In the presence of eval all arguments and locals | 463 // functions arguments. In the presence of eval all arguments and locals |
640 // (including the inner function itself) from the outer function becomes part of | 464 // (including the inner function itself) from the outer function becomes part of |
641 // the debugger infformation on the closure. | 465 // the debugger infformation on the closure. |
642 BeginTest("Closure 5"); | 466 BeginTest("Closure 5"); |
643 | 467 |
644 function closure_5(a, b) { | 468 function closure_5(a, b) { |
645 var x = 3; | 469 var x = 3; |
646 var y = 4; | 470 var y = 4; |
647 function f() { | 471 function f() { |
648 eval(''); | 472 eval(''); |
649 debugger; | 473 debugger; |
650 return 1; | 474 return 1; |
651 }; | 475 }; |
652 return f; | 476 return f; |
653 } | 477 } |
654 | 478 |
655 listener_delegate = function(exec_state) { | 479 listener_delegate = function(exec_state) { |
656 CheckScopeChain([debug.ScopeType.Local, | 480 CheckScopeChain([debug.ScopeType.Local, |
657 debug.ScopeType.Closure, | 481 debug.ScopeType.Closure, |
| 482 debug.ScopeType.Module, |
658 debug.ScopeType.Script, | 483 debug.ScopeType.Script, |
659 debug.ScopeType.Global], exec_state); | 484 debug.ScopeType.Global], exec_state); |
660 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); | 485 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state); |
661 CheckScopeChainNames(["f", "closure_5", undefined, undefined], exec_state) | 486 CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined], exec
_state) |
662 }; | 487 }; |
663 closure_5(1, 2)(); | 488 closure_5(1, 2)(); |
664 EndTest(); | 489 EndTest(); |
665 | 490 |
666 | 491 |
667 // Two closures. Due to optimizations only the parts actually used are provided | 492 // Two closures. Due to optimizations only the parts actually used are provided |
668 // through the debugger information. | 493 // through the debugger information. |
669 BeginTest("Closure 6"); | 494 BeginTest("Closure 6"); |
| 495 let some_global; |
670 function closure_6(a, b) { | 496 function closure_6(a, b) { |
671 function f(a, b) { | 497 function f(a, b) { |
672 var x = 3; | 498 var x = 3; |
673 var y = 4; | 499 var y = 4; |
674 return function() { | 500 return function() { |
675 var x = 3; | 501 var x = 3; |
676 var y = 4; | 502 var y = 4; |
677 debugger; | 503 debugger; |
678 some_global = a; | 504 some_global = a; |
679 return f; | 505 return f; |
680 }; | 506 }; |
681 } | 507 } |
682 return f(a, b); | 508 return f(a, b); |
683 } | 509 } |
684 | 510 |
685 listener_delegate = function(exec_state) { | 511 listener_delegate = function(exec_state) { |
686 CheckScopeChain([debug.ScopeType.Local, | 512 CheckScopeChain([debug.ScopeType.Local, |
687 debug.ScopeType.Closure, | 513 debug.ScopeType.Closure, |
688 debug.ScopeType.Closure, | 514 debug.ScopeType.Closure, |
| 515 debug.ScopeType.Module, |
689 debug.ScopeType.Script, | 516 debug.ScopeType.Script, |
690 debug.ScopeType.Global], exec_state); | 517 debug.ScopeType.Global], exec_state); |
691 CheckScopeContent({a:1}, 1, exec_state); | 518 CheckScopeContent({a:1}, 1, exec_state); |
692 CheckScopeContent({f:function(){}}, 2, exec_state); | 519 CheckScopeContent({f:function(){}}, 2, exec_state); |
693 CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined], exec
_state) | 520 CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined, undef
ined], exec_state) |
694 }; | 521 }; |
695 closure_6(1, 2)(); | 522 closure_6(1, 2)(); |
696 EndTest(); | 523 EndTest(); |
697 | 524 |
698 | 525 |
699 // Two closures. In the presence of eval all information is provided as the | 526 // Two closures. In the presence of eval all information is provided as the |
700 // compiler cannot determine which parts are used. | 527 // compiler cannot determine which parts are used. |
701 BeginTest("Closure 7"); | 528 BeginTest("Closure 7"); |
702 function closure_7(a, b) { | 529 function closure_7(a, b) { |
703 var x = 3; | 530 var x = 3; |
(...skipping 11 matching lines...) Expand all Loading... |
715 return f; | 542 return f; |
716 }; | 543 }; |
717 } | 544 } |
718 return f(a, b); | 545 return f(a, b); |
719 } | 546 } |
720 | 547 |
721 listener_delegate = function(exec_state) { | 548 listener_delegate = function(exec_state) { |
722 CheckScopeChain([debug.ScopeType.Local, | 549 CheckScopeChain([debug.ScopeType.Local, |
723 debug.ScopeType.Closure, | 550 debug.ScopeType.Closure, |
724 debug.ScopeType.Closure, | 551 debug.ScopeType.Closure, |
| 552 debug.ScopeType.Module, |
725 debug.ScopeType.Script, | 553 debug.ScopeType.Script, |
726 debug.ScopeType.Global], exec_state); | 554 debug.ScopeType.Global], exec_state); |
727 CheckScopeContent({}, 0, exec_state); | 555 CheckScopeContent({}, 0, exec_state); |
728 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 1, exec_state); | 556 CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state); |
729 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 2, exec_state); | 557 CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 2, exec_state); |
730 CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined], exec
_state) | 558 CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined, undef
ined], exec_state) |
731 }; | 559 }; |
732 closure_7(1, 2)(); | 560 closure_7(1, 2)(); |
733 EndTest(); | 561 EndTest(); |
734 | 562 |
735 | 563 |
736 // Closure that may be optimized out. | 564 // Closure that may be optimized out. |
737 BeginTest("Closure 8"); | 565 BeginTest("Closure 8"); |
738 function closure_8() { | 566 function closure_8() { |
739 (function inner(x) { | 567 (function inner(x) { |
740 debugger; | 568 debugger; |
741 })(2); | 569 })(2); |
742 } | 570 } |
743 | 571 |
744 listener_delegate = function(exec_state) { | 572 listener_delegate = function(exec_state) { |
745 CheckScopeChain([debug.ScopeType.Local, | 573 CheckScopeChain([debug.ScopeType.Local, |
| 574 debug.ScopeType.Module, |
746 debug.ScopeType.Script, | 575 debug.ScopeType.Script, |
747 debug.ScopeType.Global], exec_state); | 576 debug.ScopeType.Global], exec_state); |
748 CheckScopeContent({x: 2}, 0, exec_state); | 577 CheckScopeContent({x: 2}, 0, exec_state); |
749 CheckScopeChainNames(["inner", undefined, undefined], exec_state) | 578 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state) |
750 }; | 579 }; |
751 closure_8(); | 580 closure_8(); |
752 EndTest(); | 581 EndTest(); |
753 | 582 |
754 | 583 |
755 BeginTest("Closure 9"); | 584 BeginTest("Closure 9"); |
756 function closure_9() { | 585 let closure_9 = Function(' \ |
757 eval("var y = 1;"); | 586 eval("var y = 1;"); \ |
758 eval("var z = 1;"); | 587 eval("var z = 1;"); \ |
759 (function inner(x) { | 588 (function inner(x) { \ |
760 y++; | 589 y++; \ |
761 z++; | 590 z++; \ |
762 debugger; | 591 debugger; \ |
763 })(2); | 592 })(2); \ |
764 } | 593 ') |
765 | 594 |
766 listener_delegate = function(exec_state) { | 595 listener_delegate = function(exec_state) { |
767 CheckScopeChain([debug.ScopeType.Local, | 596 CheckScopeChain([debug.ScopeType.Local, |
768 debug.ScopeType.Closure, | 597 debug.ScopeType.Closure, |
769 debug.ScopeType.Script, | 598 debug.ScopeType.Script, |
770 debug.ScopeType.Global], exec_state); | 599 debug.ScopeType.Global], exec_state); |
771 CheckScopeChainNames(["inner", "closure_9", undefined, undefined], exec_state) | 600 CheckScopeChainNames(["inner", undefined, undefined, undefined], exec_state) |
772 }; | 601 }; |
773 closure_9(); | 602 closure_9(); |
774 EndTest(); | 603 EndTest(); |
775 | 604 |
776 | 605 |
777 // Test a mixture of scopes. | |
778 BeginTest("The full monty"); | |
779 function the_full_monty(a, b) { | |
780 var x = 3; | |
781 var y = 4; | |
782 eval('var i = 5'); | |
783 eval('var j = 6'); | |
784 function f(a, b) { | |
785 var x = 9; | |
786 var y = 10; | |
787 eval('var i = 11'); | |
788 eval('var j = 12'); | |
789 with ({j:13}){ | |
790 return function() { | |
791 var x = 14; | |
792 with ({a:15}) { | |
793 with ({b:16}) { | |
794 debugger; | |
795 some_global = a; | |
796 return f; | |
797 } | |
798 } | |
799 }; | |
800 } | |
801 } | |
802 return f(a, b); | |
803 } | |
804 | |
805 listener_delegate = function(exec_state) { | |
806 CheckScopeChain([debug.ScopeType.With, | |
807 debug.ScopeType.With, | |
808 debug.ScopeType.Local, | |
809 debug.ScopeType.With, | |
810 debug.ScopeType.Closure, | |
811 debug.ScopeType.Closure, | |
812 debug.ScopeType.Script, | |
813 debug.ScopeType.Global], exec_state); | |
814 CheckScopeContent({b:16}, 0, exec_state); | |
815 CheckScopeContent({a:15}, 1, exec_state); | |
816 CheckScopeContent({x:14}, 2, exec_state); | |
817 CheckScopeContent({j:13}, 3, exec_state); | |
818 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); | |
819 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state); | |
820 CheckScopeChainNames([undefined, undefined, undefined, "f", "f", "the_full_mon
ty", undefined, undefined], exec_state) | |
821 }; | |
822 the_full_monty(1, 2)(); | |
823 EndTest(); | |
824 | |
825 | |
826 BeginTest("Closure inside With 1"); | |
827 function closure_in_with_1() { | |
828 with({x:1}) { | |
829 (function inner(x) { | |
830 debugger; | |
831 })(2); | |
832 } | |
833 } | |
834 | |
835 listener_delegate = function(exec_state) { | |
836 CheckScopeChain([debug.ScopeType.Local, | |
837 debug.ScopeType.With, | |
838 debug.ScopeType.Script, | |
839 debug.ScopeType.Global], exec_state); | |
840 CheckScopeContent({x: 2}, 0, exec_state); | |
841 CheckScopeContent({x: 1}, 1, exec_state); | |
842 }; | |
843 closure_in_with_1(); | |
844 EndTest(); | |
845 | |
846 | |
847 BeginTest("Closure inside With 2"); | |
848 function closure_in_with_2() { | |
849 with({x:1}) { | |
850 (function inner(x) { | |
851 with({x:3}) { | |
852 debugger; | |
853 } | |
854 })(2); | |
855 } | |
856 } | |
857 | |
858 listener_delegate = function(exec_state) { | |
859 CheckScopeChain([debug.ScopeType.With, | |
860 debug.ScopeType.Local, | |
861 debug.ScopeType.With, | |
862 debug.ScopeType.Script, | |
863 debug.ScopeType.Global], exec_state); | |
864 CheckScopeContent({x: 3}, 0, exec_state); | |
865 CheckScopeContent({x: 2}, 1, exec_state); | |
866 CheckScopeContent({x: 1}, 2, exec_state); | |
867 CheckScopeChainNames(["inner", "inner", "closure_in_with_2", undefined, undefi
ned], exec_state) | |
868 }; | |
869 closure_in_with_2(); | |
870 EndTest(); | |
871 | |
872 | |
873 BeginTest("Closure inside With 3"); | |
874 function createClosure(a) { | |
875 var b = a + 1; | |
876 return function closure() { | |
877 var c = b; | |
878 (function inner(x) { | |
879 with({x:c}) { | |
880 debugger; | |
881 } | |
882 })(2); | |
883 }; | |
884 } | |
885 | |
886 function closure_in_with_3() { | |
887 var f = createClosure(0); | |
888 f(); | |
889 } | |
890 | |
891 listener_delegate = function(exec_state) { | |
892 CheckScopeChain([debug.ScopeType.With, | |
893 debug.ScopeType.Local, | |
894 debug.ScopeType.Closure, | |
895 debug.ScopeType.Closure, | |
896 debug.ScopeType.Script, | |
897 debug.ScopeType.Global], exec_state); | |
898 CheckScopeChainNames(["inner", "inner", "closure", "createClosure", undefined,
undefined], exec_state) | |
899 } | |
900 closure_in_with_3(); | |
901 EndTest(); | |
902 | |
903 | |
904 BeginTest("Closure inside With 4"); | |
905 listener_delegate = function(exec_state) { | |
906 CheckScopeChain([debug.ScopeType.Local, | |
907 debug.ScopeType.With, | |
908 debug.ScopeType.Script, | |
909 debug.ScopeType.Global], exec_state); | |
910 CheckScopeContent({x: 2}, 0, exec_state); | |
911 CheckScopeContent({x: 1}, 1, exec_state); | |
912 CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) | |
913 }; | |
914 | |
915 with({x:1}) { | |
916 (function(x) { | |
917 debugger; | |
918 })(2); | |
919 } | |
920 EndTest(); | |
921 | |
922 | |
923 // Test global scope. | 606 // Test global scope. |
924 BeginTest("Global"); | 607 BeginTest("Global"); |
925 listener_delegate = function(exec_state) { | 608 listener_delegate = function(exec_state) { |
926 CheckScopeChain([debug.ScopeType.Script, debug.ScopeType.Global], exec_state); | 609 CheckScopeChain([debug.ScopeType.Module, debug.ScopeType.Script, debug.ScopeTy
pe.Global], exec_state); |
927 CheckScopeChainNames([undefined, undefined], exec_state) | 610 CheckScopeChainNames([undefined, undefined, undefined], exec_state) |
928 }; | 611 }; |
929 debugger; | 612 debugger; |
930 EndTest(); | 613 EndTest(); |
931 | 614 |
932 | 615 |
933 BeginTest("Catch block 1"); | 616 BeginTest("Catch block 1"); |
934 function catch_block_1() { | 617 function catch_block_1() { |
935 try { | 618 try { |
936 throw 'Exception'; | 619 throw 'Exception'; |
937 } catch (e) { | 620 } catch (e) { |
938 debugger; | 621 debugger; |
939 } | 622 } |
940 }; | 623 }; |
941 | 624 |
942 | 625 |
943 listener_delegate = function(exec_state) { | 626 listener_delegate = function(exec_state) { |
944 CheckScopeChain([debug.ScopeType.Catch, | 627 CheckScopeChain([debug.ScopeType.Catch, |
945 debug.ScopeType.Local, | 628 debug.ScopeType.Local, |
| 629 debug.ScopeType.Module, |
946 debug.ScopeType.Script, | 630 debug.ScopeType.Script, |
947 debug.ScopeType.Global], exec_state); | 631 debug.ScopeType.Global], exec_state); |
948 CheckScopeContent({e:'Exception'}, 0, exec_state); | 632 CheckScopeContent({e:'Exception'}, 0, exec_state); |
949 CheckScopeChainNames(["catch_block_1", "catch_block_1", undefined, undefined],
exec_state) | 633 CheckScopeChainNames(["catch_block_1", "catch_block_1", undefined, undefined,
undefined], exec_state) |
950 }; | 634 }; |
951 catch_block_1(); | 635 catch_block_1(); |
952 EndTest(); | 636 EndTest(); |
953 | 637 |
954 | 638 |
955 BeginTest("Catch block 2"); | |
956 function catch_block_2() { | |
957 try { | |
958 throw 'Exception'; | |
959 } catch (e) { | |
960 with({n:10}) { | |
961 debugger; | |
962 } | |
963 } | |
964 }; | |
965 | |
966 | |
967 listener_delegate = function(exec_state) { | |
968 CheckScopeChain([debug.ScopeType.With, | |
969 debug.ScopeType.Catch, | |
970 debug.ScopeType.Local, | |
971 debug.ScopeType.Script, | |
972 debug.ScopeType.Global], exec_state); | |
973 CheckScopeContent({n:10}, 0, exec_state); | |
974 CheckScopeContent({e:'Exception'}, 1, exec_state); | |
975 CheckScopeChainNames(["catch_block_2", "catch_block_2", "catch_block_2", undef
ined, undefined], exec_state) | |
976 }; | |
977 catch_block_2(); | |
978 EndTest(); | |
979 | |
980 | |
981 BeginTest("Catch block 3"); | 639 BeginTest("Catch block 3"); |
982 function catch_block_3() { | 640 function catch_block_3() { |
983 // Do eval to dynamically declare a local variable so that the context's | |
984 // extension slot is initialized with JSContextExtensionObject. | |
985 eval("var y = 78;"); | 641 eval("var y = 78;"); |
986 try { | 642 try { |
987 throw 'Exception'; | 643 throw 'Exception'; |
988 } catch (e) { | 644 } catch (e) { |
989 debugger; | 645 debugger; |
990 } | 646 } |
991 }; | 647 }; |
992 | 648 |
993 | 649 |
994 listener_delegate = function(exec_state) { | 650 listener_delegate = function(exec_state) { |
995 CheckScopeChain([debug.ScopeType.Catch, | 651 CheckScopeChain([debug.ScopeType.Catch, |
996 debug.ScopeType.Local, | 652 debug.ScopeType.Local, |
| 653 debug.ScopeType.Module, |
997 debug.ScopeType.Script, | 654 debug.ScopeType.Script, |
998 debug.ScopeType.Global], exec_state); | 655 debug.ScopeType.Global], exec_state); |
999 CheckScopeContent({e:'Exception'}, 0, exec_state); | 656 CheckScopeContent({e:'Exception'}, 0, exec_state); |
1000 CheckScopeContent({y:78}, 1, exec_state); | 657 CheckScopeContent({}, 1, exec_state); |
1001 CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined],
exec_state) | 658 CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined,
undefined], exec_state) |
1002 }; | 659 }; |
1003 catch_block_3(); | 660 catch_block_3(); |
1004 EndTest(); | 661 EndTest(); |
1005 | 662 |
1006 | 663 |
1007 BeginTest("Catch block 4"); | |
1008 function catch_block_4() { | |
1009 // Do eval to dynamically declare a local variable so that the context's | |
1010 // extension slot is initialized with JSContextExtensionObject. | |
1011 eval("var y = 98;"); | |
1012 try { | |
1013 throw 'Exception'; | |
1014 } catch (e) { | |
1015 with({n:10}) { | |
1016 debugger; | |
1017 } | |
1018 } | |
1019 }; | |
1020 | |
1021 listener_delegate = function(exec_state) { | |
1022 CheckScopeChain([debug.ScopeType.With, | |
1023 debug.ScopeType.Catch, | |
1024 debug.ScopeType.Local, | |
1025 debug.ScopeType.Script, | |
1026 debug.ScopeType.Global], exec_state); | |
1027 CheckScopeContent({n:10}, 0, exec_state); | |
1028 CheckScopeContent({e:'Exception'}, 1, exec_state); | |
1029 CheckScopeContent({y:98}, 2, exec_state); | |
1030 CheckScopeChainNames(["catch_block_4", "catch_block_4", "catch_block_4", undef
ined, undefined], exec_state) | |
1031 }; | |
1032 catch_block_4(); | |
1033 EndTest(); | |
1034 | |
1035 | |
1036 // Test catch in global scope. | 664 // Test catch in global scope. |
1037 BeginTest("Catch block 5"); | 665 BeginTest("Catch block 5"); |
1038 listener_delegate = function(exec_state) { | 666 listener_delegate = function(exec_state) { |
1039 CheckScopeChain([debug.ScopeType.Catch, | 667 CheckScopeChain([debug.ScopeType.Catch, |
| 668 debug.ScopeType.Module, |
1040 debug.ScopeType.Script, | 669 debug.ScopeType.Script, |
1041 debug.ScopeType.Global], exec_state); | 670 debug.ScopeType.Global], exec_state); |
1042 CheckScopeContent({e:'Exception'}, 0, exec_state); | 671 CheckScopeContent({e:'Exception'}, 0, exec_state); |
1043 CheckScopeChainNames([undefined, undefined, undefined], exec_state) | 672 CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) |
1044 }; | 673 }; |
1045 | 674 |
1046 try { | 675 try { |
1047 throw 'Exception'; | 676 throw 'Exception'; |
1048 } catch (e) { | 677 } catch (e) { |
1049 debugger; | 678 debugger; |
1050 } | 679 } |
1051 | 680 |
1052 EndTest(); | 681 EndTest(); |
1053 | 682 |
1054 | 683 |
1055 // Closure inside catch in global code. | 684 // Closure inside catch in global code. |
1056 BeginTest("Catch block 6"); | 685 BeginTest("Catch block 6"); |
1057 listener_delegate = function(exec_state) { | 686 listener_delegate = function(exec_state) { |
1058 CheckScopeChain([debug.ScopeType.Local, | 687 CheckScopeChain([debug.ScopeType.Local, |
1059 debug.ScopeType.Catch, | 688 debug.ScopeType.Catch, |
| 689 debug.ScopeType.Module, |
1060 debug.ScopeType.Script, | 690 debug.ScopeType.Script, |
1061 debug.ScopeType.Global], exec_state); | 691 debug.ScopeType.Global], exec_state); |
1062 CheckScopeContent({x: 2}, 0, exec_state); | 692 CheckScopeContent({x: 2}, 0, exec_state); |
1063 CheckScopeContent({e:'Exception'}, 1, exec_state); | 693 CheckScopeContent({e:'Exception'}, 1, exec_state); |
1064 CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state) | 694 CheckScopeChainNames([undefined, undefined, undefined, undefined, undefined],
exec_state) |
1065 }; | 695 }; |
1066 | 696 |
1067 try { | 697 try { |
1068 throw 'Exception'; | 698 throw 'Exception'; |
1069 } catch (e) { | 699 } catch (e) { |
1070 (function(x) { | 700 (function(x) { |
1071 debugger; | 701 debugger; |
1072 })(2); | 702 })(2); |
1073 } | 703 } |
1074 EndTest(); | 704 EndTest(); |
1075 | 705 |
1076 | 706 |
1077 // Catch block in function that is marked for optimization while being executed. | 707 // Catch block in function that is marked for optimization while being executed. |
1078 BeginTest("Catch block 7"); | 708 BeginTest("Catch block 7"); |
1079 function catch_block_7() { | 709 function catch_block_7() { |
1080 %OptimizeFunctionOnNextCall(catch_block_7); | 710 %OptimizeFunctionOnNextCall(catch_block_7); |
1081 try { | 711 try { |
1082 throw 'Exception'; | 712 throw 'Exception'; |
1083 } catch (e) { | 713 } catch (e) { |
1084 debugger; | 714 debugger; |
1085 } | 715 } |
1086 }; | 716 }; |
1087 | 717 |
1088 | 718 |
1089 listener_delegate = function(exec_state) { | 719 listener_delegate = function(exec_state) { |
1090 CheckScopeChain([debug.ScopeType.Catch, | 720 CheckScopeChain([debug.ScopeType.Catch, |
1091 debug.ScopeType.Local, | 721 debug.ScopeType.Local, |
| 722 debug.ScopeType.Module, |
1092 debug.ScopeType.Script, | 723 debug.ScopeType.Script, |
1093 debug.ScopeType.Global], exec_state); | 724 debug.ScopeType.Global], exec_state); |
1094 CheckScopeContent({e:'Exception'}, 0, exec_state); | 725 CheckScopeContent({e:'Exception'}, 0, exec_state); |
1095 CheckScopeChainNames(["catch_block_7", "catch_block_7", undefined, undefined],
exec_state) | 726 CheckScopeChainNames(["catch_block_7", "catch_block_7", undefined, undefined,
undefined], exec_state) |
1096 }; | 727 }; |
1097 catch_block_7(); | 728 catch_block_7(); |
1098 EndTest(); | 729 EndTest(); |
1099 | 730 |
1100 | 731 |
1101 BeginTest("Classes and methods 1"); | 732 BeginTest("Classes and methods 1"); |
1102 | 733 |
1103 listener_delegate = function(exec_state) { | 734 listener_delegate = function(exec_state) { |
1104 "use strict" | 735 "use strict" |
1105 CheckScopeChain([debug.ScopeType.Local, | 736 CheckScopeChain([debug.ScopeType.Local, |
| 737 debug.ScopeType.Module, |
1106 debug.ScopeType.Script, | 738 debug.ScopeType.Script, |
1107 debug.ScopeType.Global], exec_state); | 739 debug.ScopeType.Global], exec_state); |
1108 CheckScopeContent({}, 1, exec_state); | 740 CheckScopeContent({}, 1, exec_state); |
1109 CheckScopeChainNames(["m", undefined, undefined], exec_state) | 741 CheckScopeChainNames(["m", undefined, undefined, undefined], exec_state) |
1110 }; | 742 }; |
1111 | 743 |
1112 (function() { | 744 (function() { |
1113 "use strict"; | 745 "use strict"; |
1114 class C1 { | 746 class C1 { |
1115 m() { | 747 m() { |
1116 debugger; | 748 debugger; |
1117 } | 749 } |
1118 } | 750 } |
1119 new C1().m(); | 751 new C1().m(); |
1120 })(); | 752 })(); |
1121 | 753 |
1122 EndTest(); | 754 EndTest(); |
1123 | 755 |
1124 BeginTest("Scope positions"); | 756 BeginTest("Scope positions"); |
1125 var code1 = "function f() { \n" + | 757 var code1 = "function f() { \n" + |
1126 " var a = 1; \n" + | 758 " var a = 1; \n" + |
1127 " function b() { \n" + | 759 " function b() { \n" + |
1128 " debugger; \n" + | 760 " debugger; \n" + |
1129 " return a + 1; \n" + | 761 " return a + 1; \n" + |
1130 " } \n" + | 762 " } \n" + |
1131 " b(); \n" + | 763 " b(); \n" + |
1132 "} \n" + | 764 "} \n" + |
1133 "f(); \n"; | 765 "f(); \n"; |
1134 | 766 |
1135 listener_delegate = function(exec_state) { | 767 listener_delegate = function(exec_state) { |
1136 CheckScopeChainPositions([{start: 58, end: 118}, {start: 10, end: 162}, {}, {}
], exec_state); | 768 CheckScopeChainPositions([{start: 58, end: 118}, {start: 10, end: 162}], exec_
state); |
1137 } | 769 } |
1138 eval(code1); | 770 eval(code1); |
1139 EndTest(); | 771 EndTest(); |
1140 | 772 |
1141 | 773 |
1142 function catch_block_2() { | |
1143 try { | |
1144 throw 'Exception'; | |
1145 } catch (e) { | |
1146 with({n:10}) { | |
1147 debugger; | |
1148 } | |
1149 } | |
1150 }; | |
1151 | |
1152 BeginTest("Scope positions in catch and 'with' statement"); | |
1153 var code2 = "function catch_block() { \n" + | |
1154 " try { \n" + | |
1155 " throw 'Exception'; \n" + | |
1156 " } catch (e) { \n" + | |
1157 " with({n : 10}) { \n" + | |
1158 " debugger; \n" + | |
1159 " } \n" + | |
1160 " } \n" + | |
1161 "} \n" + | |
1162 "catch_block(); \n"; | |
1163 | |
1164 listener_delegate = function(exec_state) { | |
1165 CheckScopeChainPositions([{start: 131, end: 173}, {start: 94, end: 199}, {star
t: 20, end: 225}, {}, {}], exec_state); | |
1166 } | |
1167 eval(code2); | |
1168 EndTest(); | |
1169 | |
1170 BeginTest("Scope positions in for statement"); | 774 BeginTest("Scope positions in for statement"); |
1171 var code3 = "function for_statement() { \n" + | 775 var code3 = "function for_statement() { \n" + |
1172 " for (let i = 0; i < 1; i++) { \n" + | 776 " for (let i = 0; i < 1; i++) { \n" + |
1173 " debugger; \n" + | 777 " debugger; \n" + |
1174 " } \n" + | 778 " } \n" + |
1175 "} \n" + | 779 "} \n" + |
1176 "for_statement(); \n"; | 780 "for_statement(); \n"; |
1177 | 781 |
1178 listener_delegate = function(exec_state) { | 782 listener_delegate = function(exec_state) { |
1179 CheckScopeChain([debug.ScopeType.Block, | 783 CheckScopeChain([debug.ScopeType.Block, |
1180 debug.ScopeType.Local, | 784 debug.ScopeType.Local, |
| 785 debug.ScopeType.Module, |
1181 debug.ScopeType.Script, | 786 debug.ScopeType.Script, |
1182 debug.ScopeType.Global], exec_state); | 787 debug.ScopeType.Global], exec_state); |
1183 CheckScopeChainPositions([{start: 52, end: 111}, {start: 22, end: 145}, {}, {}
], exec_state); | 788 CheckScopeChainPositions([{start: 52, end: 111}, {start: 22, end: 145}], exec_
state); |
1184 } | 789 } |
1185 eval(code3); | 790 eval(code3); |
1186 EndTest(); | 791 EndTest(); |
1187 | 792 |
1188 BeginTest("Scope positions in for statement with lexical block"); | 793 BeginTest("Scope positions in for statement with lexical block"); |
1189 var code4 = "function for_statement() { \n" + | 794 var code4 = "function for_statement() { \n" + |
1190 " for (let i = 0; i < 1; i++) { \n" + | 795 " for (let i = 0; i < 1; i++) { \n" + |
1191 " let j; \n" + | 796 " let j; \n" + |
1192 " debugger; \n" + | 797 " debugger; \n" + |
1193 " } \n" + | 798 " } \n" + |
1194 "} \n" + | 799 "} \n" + |
1195 "for_statement(); \n"; | 800 "for_statement(); \n"; |
1196 | 801 |
1197 listener_delegate = function(exec_state) { | 802 listener_delegate = function(exec_state) { |
1198 CheckScopeChain([debug.ScopeType.Block, | 803 CheckScopeChain([debug.ScopeType.Block, |
1199 debug.ScopeType.Block, | 804 debug.ScopeType.Block, |
1200 debug.ScopeType.Local, | 805 debug.ScopeType.Local, |
| 806 debug.ScopeType.Module, |
1201 debug.ScopeType.Script, | 807 debug.ScopeType.Script, |
1202 debug.ScopeType.Global], exec_state); | 808 debug.ScopeType.Global], exec_state); |
1203 CheckScopeChainPositions([{start: 66, end: 147}, {start: 52, end: 147}, {start
: 22, end: 181}, {}, {}], exec_state); | 809 CheckScopeChainPositions([{start: 66, end: 147}, {start: 52, end: 147}, {start
: 22, end: 181}], exec_state); |
1204 } | 810 } |
1205 eval(code4); | 811 eval(code4); |
1206 EndTest(); | 812 EndTest(); |
1207 | 813 |
1208 BeginTest("Scope positions in lexical for each statement"); | 814 BeginTest("Scope positions in lexical for each statement"); |
1209 var code5 = "function for_each_statement() { \n" + | 815 var code5 = "function for_each_statement() { \n" + |
1210 " for (let i of [0]) { \n" + | 816 " for (let i of [0]) { \n" + |
1211 " debugger; \n" + | 817 " debugger; \n" + |
1212 " } \n" + | 818 " } \n" + |
1213 "} \n" + | 819 "} \n" + |
1214 "for_each_statement(); \n"; | 820 "for_each_statement(); \n"; |
1215 | 821 |
1216 listener_delegate = function(exec_state) { | 822 listener_delegate = function(exec_state) { |
1217 CheckScopeChain([debug.ScopeType.Block, | 823 CheckScopeChain([debug.ScopeType.Block, |
1218 debug.ScopeType.Local, | 824 debug.ScopeType.Local, |
| 825 debug.ScopeType.Module, |
1219 debug.ScopeType.Script, | 826 debug.ScopeType.Script, |
1220 debug.ScopeType.Global], exec_state); | 827 debug.ScopeType.Global], exec_state); |
1221 CheckScopeChainPositions([{start: 55, end: 111}, {start: 27, end: 145}, {}, {}
], exec_state); | 828 CheckScopeChainPositions([{start: 55, end: 111}, {start: 27, end: 145}], exec_
state); |
1222 } | 829 } |
1223 eval(code5); | 830 eval(code5); |
1224 EndTest(); | 831 EndTest(); |
1225 | 832 |
1226 BeginTest("Scope positions in lexical for each statement with lexical block"); | 833 BeginTest("Scope positions in lexical for each statement with lexical block"); |
1227 var code6 = "function for_each_statement() { \n" + | 834 var code6 = "function for_each_statement() { \n" + |
1228 " for (let i of [0]) { \n" + | 835 " for (let i of [0]) { \n" + |
1229 " let j; \n" + | 836 " let j; \n" + |
1230 " debugger; \n" + | 837 " debugger; \n" + |
1231 " } \n" + | 838 " } \n" + |
1232 "} \n" + | 839 "} \n" + |
1233 "for_each_statement(); \n"; | 840 "for_each_statement(); \n"; |
1234 | 841 |
1235 listener_delegate = function(exec_state) { | 842 listener_delegate = function(exec_state) { |
1236 CheckScopeChain([debug.ScopeType.Block, | 843 CheckScopeChain([debug.ScopeType.Block, |
1237 debug.ScopeType.Block, | 844 debug.ScopeType.Block, |
1238 debug.ScopeType.Local, | 845 debug.ScopeType.Local, |
| 846 debug.ScopeType.Module, |
1239 debug.ScopeType.Script, | 847 debug.ScopeType.Script, |
1240 debug.ScopeType.Global], exec_state); | 848 debug.ScopeType.Global], exec_state); |
1241 CheckScopeChainPositions([{start: 57, end: 147}, {start: 55, end: 147}, {start
: 27, end: 181}, {}, {}], exec_state); | 849 CheckScopeChainPositions([{start: 57, end: 147}, {start: 55, end: 147}, {start
: 27, end: 181}], exec_state); |
1242 } | 850 } |
1243 eval(code6); | 851 eval(code6); |
1244 EndTest(); | 852 EndTest(); |
1245 | 853 |
1246 BeginTest("Scope positions in non-lexical for each statement"); | 854 BeginTest("Scope positions in non-lexical for each statement"); |
1247 var code7 = "function for_each_statement() { \n" + | 855 var code7 = "function for_each_statement() { \n" + |
1248 " var i; \n" + | 856 " var i; \n" + |
1249 " for (i of [0]) { \n" + | 857 " for (i of [0]) { \n" + |
1250 " debugger; \n" + | 858 " debugger; \n" + |
1251 " } \n" + | 859 " } \n" + |
1252 "} \n" + | 860 "} \n" + |
1253 "for_each_statement(); \n"; | 861 "for_each_statement(); \n"; |
1254 | 862 |
1255 listener_delegate = function(exec_state) { | 863 listener_delegate = function(exec_state) { |
1256 CheckScopeChain([debug.ScopeType.Local, | 864 CheckScopeChain([debug.ScopeType.Local, |
| 865 debug.ScopeType.Module, |
1257 debug.ScopeType.Script, | 866 debug.ScopeType.Script, |
1258 debug.ScopeType.Global], exec_state); | 867 debug.ScopeType.Global], exec_state); |
1259 CheckScopeChainPositions([{start: 27, end: 181}, {}, {}], exec_state); | 868 CheckScopeChainPositions([{start: 27, end: 181}], exec_state); |
1260 } | 869 } |
1261 eval(code7); | 870 eval(code7); |
1262 EndTest(); | 871 EndTest(); |
1263 | 872 |
1264 BeginTest("Scope positions in non-lexical for each statement with lexical block"
); | 873 BeginTest("Scope positions in non-lexical for each statement with lexical block"
); |
1265 var code8 = "function for_each_statement() { \n" + | 874 var code8 = "function for_each_statement() { \n" + |
1266 " var i; \n" + | 875 " var i; \n" + |
1267 " for (i of [0]) { \n" + | 876 " for (i of [0]) { \n" + |
1268 " let j; \n" + | 877 " let j; \n" + |
1269 " debugger; \n" + | 878 " debugger; \n" + |
1270 " } \n" + | 879 " } \n" + |
1271 "} \n" + | 880 "} \n" + |
1272 "for_each_statement(); \n"; | 881 "for_each_statement(); \n"; |
1273 | 882 |
1274 listener_delegate = function(exec_state) { | 883 listener_delegate = function(exec_state) { |
1275 CheckScopeChain([debug.ScopeType.Block, | 884 CheckScopeChain([debug.ScopeType.Block, |
1276 debug.ScopeType.Local, | 885 debug.ScopeType.Local, |
| 886 debug.ScopeType.Module, |
1277 debug.ScopeType.Script, | 887 debug.ScopeType.Script, |
1278 debug.ScopeType.Global], exec_state); | 888 debug.ScopeType.Global], exec_state); |
1279 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}, {}, {}
], exec_state); | 889 CheckScopeChainPositions([{start: 89, end: 183}, {start: 27, end: 217}], exec_
state); |
1280 } | 890 } |
1281 eval(code8); | 891 eval(code8); |
1282 EndTest(); | 892 EndTest(); |
1283 | 893 |
1284 assertEquals(begin_test_count, break_count, | 894 assertEquals(begin_test_count, break_count, |
1285 'one or more tests did not enter the debugger'); | 895 'one or more tests did not enter the debugger'); |
1286 assertEquals(begin_test_count, end_test_count, | 896 assertEquals(begin_test_count, end_test_count, |
1287 'one or more tests did not have its result checked'); | 897 'one or more tests did not have its result checked'); |
OLD | NEW |