Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: test/mjsunit/debug-scopes.js

Issue 247003004: Add tests for generator/debugger interaction (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --expose-debug-as debug --allow-natives-syntax 28 // Flags: --expose-debug-as debug --allow-natives-syntax --harmony-generators
29 // The functions used for testing backtraces. They are at the top to make the 29 // The functions used for testing backtraces. They are at the top to make the
30 // testing of source line/column easier. 30 // testing of source line/column easier.
31 31
32 // Get the Debug object exposed from the debug context global object. 32 // Get the Debug object exposed from the debug context global object.
33 var Debug = debug.Debug; 33 var Debug = debug.Debug;
34 34
35 var test_name; 35 var test_name;
36 var listener_delegate; 36 var listener_delegate;
37 var listener_called; 37 var listener_called;
38 var exception; 38 var exception;
(...skipping 15 matching lines...) Expand all
54 } 54 }
55 } 55 }
56 56
57 // Add the debug event listener. 57 // Add the debug event listener.
58 Debug.setListener(listener); 58 Debug.setListener(listener);
59 59
60 60
61 // Initialize for a new test. 61 // Initialize for a new test.
62 function BeginTest(name) { 62 function BeginTest(name) {
63 test_name = name; 63 test_name = name;
64 listener_delegate = null; 64 var keep_listener = name.match(/^Generator/);
65 if (!keep_listener)
66 listener_delegate = null;
65 listener_called = false; 67 listener_called = false;
66 exception = null; 68 exception = null;
67 begin_test_count++; 69 begin_test_count++;
68 } 70 }
69 71
70 72
71 // Check result of a test. 73 // Check result of a test.
72 function EndTest() { 74 function EndTest() {
73 assertTrue(listener_called, "listerner not called for " + test_name); 75 assertTrue(listener_called, "listener not called for " + test_name);
74 assertNull(exception, test_name + " / " + exception); 76 assertNull(exception, test_name + " / " + exception);
75 end_test_count++; 77 end_test_count++;
76 } 78 }
77 79
78 80
79 // Check that two scope are the same. 81 // Check that two scope are the same.
80 function assertScopeMirrorEquals(scope1, scope2) { 82 function assertScopeMirrorEquals(scope1, scope2) {
81 assertEquals(scope1.scopeType(), scope2.scopeType()); 83 assertEquals(scope1.scopeType(), scope2.scopeType());
82 assertEquals(scope1.frameIndex(), scope2.frameIndex()); 84 assertEquals(scope1.frameIndex(), scope2.frameIndex());
83 assertEquals(scope1.scopeIndex(), scope2.scopeIndex()); 85 assertEquals(scope1.scopeIndex(), scope2.scopeIndex());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 217
216 listener_delegate = function(exec_state) { 218 listener_delegate = function(exec_state) {
217 CheckScopeChain([debug.ScopeType.Local, 219 CheckScopeChain([debug.ScopeType.Local,
218 debug.ScopeType.Global], exec_state); 220 debug.ScopeType.Global], exec_state);
219 CheckScopeContent({}, 0, exec_state); 221 CheckScopeContent({}, 0, exec_state);
220 }; 222 };
221 local_1(); 223 local_1();
222 EndTest(); 224 EndTest();
223 225
224 226
227 BeginTest("Generator Local 1");
228 function *generator_local_1() {
229 debugger;
230 }
231 generator_local_1().next();
232 EndTest();
233
234
225 // Local scope with a parameter. 235 // Local scope with a parameter.
226 BeginTest("Local 2"); 236 BeginTest("Local 2");
227 237
228 function local_2(a) { 238 function local_2(a) {
229 debugger; 239 debugger;
230 } 240 }
231 241
232 listener_delegate = function(exec_state) { 242 listener_delegate = function(exec_state) {
233 CheckScopeChain([debug.ScopeType.Local, 243 CheckScopeChain([debug.ScopeType.Local,
234 debug.ScopeType.Global], exec_state); 244 debug.ScopeType.Global], exec_state);
235 CheckScopeContent({a:1}, 0, exec_state); 245 CheckScopeContent({a:1}, 0, exec_state);
236 }; 246 };
237 local_2(1); 247 local_2(1);
238 EndTest(); 248 EndTest();
239 249
240 250
251 BeginTest("Generator Local 2");
252 function *generator_local_2(a) {
253 debugger;
254 }
255 generator_local_2(1).next();
256 EndTest();
257
258
241 // Local scope with a parameter and a local variable. 259 // Local scope with a parameter and a local variable.
242 BeginTest("Local 3"); 260 BeginTest("Local 3");
243 261
244 function local_3(a) { 262 function local_3(a) {
245 var x = 3; 263 var x = 3;
246 debugger; 264 debugger;
247 } 265 }
248 266
249 listener_delegate = function(exec_state) { 267 listener_delegate = function(exec_state) {
250 CheckScopeChain([debug.ScopeType.Local, 268 CheckScopeChain([debug.ScopeType.Local,
251 debug.ScopeType.Global], exec_state); 269 debug.ScopeType.Global], exec_state);
252 CheckScopeContent({a:1,x:3}, 0, exec_state); 270 CheckScopeContent({a:1,x:3}, 0, exec_state);
253 }; 271 };
254 local_3(1); 272 local_3(1);
255 EndTest(); 273 EndTest();
256 274
257 275
276 BeginTest("Generator Local 3");
277 function *generator_local_3(a) {
278 var x = 3;
279 debugger;
280 }
281 generator_local_3(1).next();
282 EndTest();
283
284
258 // Local scope with parameters and local variables. 285 // Local scope with parameters and local variables.
259 BeginTest("Local 4"); 286 BeginTest("Local 4");
260 287
261 function local_4(a, b) { 288 function local_4(a, b) {
262 var x = 3; 289 var x = 3;
263 var y = 4; 290 var y = 4;
264 debugger; 291 debugger;
265 } 292 }
266 293
267 listener_delegate = function(exec_state) { 294 listener_delegate = function(exec_state) {
(...skipping 15 matching lines...) Expand all
283 310
284 listener_delegate = function(exec_state) { 311 listener_delegate = function(exec_state) {
285 CheckScopeChain([debug.ScopeType.Local, 312 CheckScopeChain([debug.ScopeType.Local,
286 debug.ScopeType.Global], exec_state); 313 debug.ScopeType.Global], exec_state);
287 CheckScopeContent({}, 0, exec_state); 314 CheckScopeContent({}, 0, exec_state);
288 }; 315 };
289 local_5(); 316 local_5();
290 EndTest(); 317 EndTest();
291 318
292 319
320 BeginTest("Generator Local 5");
321 function *generator_local_5() {
322 eval('');
323 debugger;
324 }
325 generator_local_5().next();
326 EndTest();
327
328
293 // Local introducing local variable using eval. 329 // Local introducing local variable using eval.
294 BeginTest("Local 6"); 330 BeginTest("Local 6");
295 331
296 function local_6() { 332 function local_6() {
297 eval('var i = 5'); 333 eval('var i = 5');
298 debugger; 334 debugger;
299 } 335 }
300 336
301 listener_delegate = function(exec_state) { 337 listener_delegate = function(exec_state) {
302 CheckScopeChain([debug.ScopeType.Local, 338 CheckScopeChain([debug.ScopeType.Local,
303 debug.ScopeType.Global], exec_state); 339 debug.ScopeType.Global], exec_state);
304 CheckScopeContent({i:5}, 0, exec_state); 340 CheckScopeContent({i:5}, 0, exec_state);
305 }; 341 };
306 local_6(); 342 local_6();
307 EndTest(); 343 EndTest();
308 344
309 345
346 BeginTest("Generator Local 6");
347 function *generator_local_6() {
348 eval('var i = 5');
349 debugger;
350 }
351 generator_local_6().next();
352 EndTest();
353
354
310 // Local scope with parameters, local variables and local variable introduced 355 // Local scope with parameters, local variables and local variable introduced
311 // using eval. 356 // using eval.
312 BeginTest("Local 7"); 357 BeginTest("Local 7");
313 358
314 function local_7(a, b) { 359 function local_7(a, b) {
315 var x = 3; 360 var x = 3;
316 var y = 4; 361 var y = 4;
317 eval('var i = 5'); 362 eval('var i = 5');
318 eval('var j = 6'); 363 eval('var j = 6');
319 debugger; 364 debugger;
320 } 365 }
321 366
322 listener_delegate = function(exec_state) { 367 listener_delegate = function(exec_state) {
323 CheckScopeChain([debug.ScopeType.Local, 368 CheckScopeChain([debug.ScopeType.Local,
324 debug.ScopeType.Global], exec_state); 369 debug.ScopeType.Global], exec_state);
325 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state); 370 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state);
326 }; 371 };
327 local_7(1, 2); 372 local_7(1, 2);
328 EndTest(); 373 EndTest();
329 374
330 375
376 BeginTest("Generator Local 7");
377 function *generator_local_7(a, b) {
378 var x = 3;
379 var y = 4;
380 eval('var i = 5');
381 eval('var j = 6');
382 debugger;
383 }
384 generator_local_7(1, 2).next();
385 EndTest();
386
387
331 // Single empty with block. 388 // Single empty with block.
332 BeginTest("With 1"); 389 BeginTest("With 1");
333 390
334 function with_1() { 391 function with_1() {
335 with({}) { 392 with({}) {
336 debugger; 393 debugger;
337 } 394 }
338 } 395 }
339 396
340 listener_delegate = function(exec_state) { 397 listener_delegate = function(exec_state) {
(...skipping 22 matching lines...) Expand all
363 debug.ScopeType.With, 420 debug.ScopeType.With,
364 debug.ScopeType.Local, 421 debug.ScopeType.Local,
365 debug.ScopeType.Global], exec_state); 422 debug.ScopeType.Global], exec_state);
366 CheckScopeContent({}, 0, exec_state); 423 CheckScopeContent({}, 0, exec_state);
367 CheckScopeContent({}, 1, exec_state); 424 CheckScopeContent({}, 1, exec_state);
368 }; 425 };
369 with_2(); 426 with_2();
370 EndTest(); 427 EndTest();
371 428
372 429
430 BeginTest("Generator With 2");
431 function *generator_with_2() {
432 with({}) {
433 with({}) {
434 debugger;
435 }
436 }
437 }
438 generator_with_2().next();
439 EndTest();
440
441
373 // With block using an in-place object literal. 442 // With block using an in-place object literal.
374 BeginTest("With 3"); 443 BeginTest("With 3");
375 444
376 function with_3() { 445 function with_3() {
377 with({a:1,b:2}) { 446 with({a:1,b:2}) {
378 debugger; 447 debugger;
379 } 448 }
380 } 449 }
381 450
382 listener_delegate = function(exec_state) { 451 listener_delegate = function(exec_state) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 }; 546 };
478 with_7(); 547 with_7();
479 EndTest(); 548 EndTest();
480 549
481 550
482 // Simple closure formed by returning an inner function referering the outer 551 // Simple closure formed by returning an inner function referering the outer
483 // functions arguments. 552 // functions arguments.
484 BeginTest("Closure 1"); 553 BeginTest("Closure 1");
485 554
486 function closure_1(a) { 555 function closure_1(a) {
487 function f() { 556 return function() {
488 debugger; 557 debugger;
489 return a; 558 return a;
490 }; 559 };
491 return f;
492 } 560 }
493 561
494 listener_delegate = function(exec_state) { 562 listener_delegate = function(exec_state) {
495 CheckScopeChain([debug.ScopeType.Local, 563 CheckScopeChain([debug.ScopeType.Local,
496 debug.ScopeType.Closure, 564 debug.ScopeType.Closure,
497 debug.ScopeType.Global], exec_state); 565 debug.ScopeType.Global], exec_state);
498 CheckScopeContent({a:1}, 1, exec_state); 566 CheckScopeContent({a:1}, 1, exec_state);
499 }; 567 };
500 closure_1(1)(); 568 closure_1(1)();
501 EndTest(); 569 EndTest();
502 570
503 571
572 BeginTest("Generator Closure 1");
573 function *generator_closure_1(a) {
574 return function() {
575 debugger;
576 return a;
577 };
578 }
579 generator_closure_1(1).next().value();
580 EndTest();
581
582
504 // Simple closure formed by returning an inner function referering the outer 583 // Simple closure formed by returning an inner function referering the outer
505 // functions arguments. Due to VM optimizations parts of the actual closure is 584 // functions arguments. Due to VM optimizations parts of the actual closure is
506 // missing from the debugger information. 585 // missing from the debugger information.
507 BeginTest("Closure 2"); 586 BeginTest("Closure 2");
508 587
509 function closure_2(a, b) { 588 function closure_2(a, b) {
510 var x = a + 2; 589 var x = a + 2;
511 var y = b + 2; 590 var y = b + 2;
512 function f() { 591 function f() {
513 debugger; 592 debugger;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 CheckScopeContent({a:15}, 1, exec_state); 830 CheckScopeContent({a:15}, 1, exec_state);
752 CheckScopeContent({x:14}, 2, exec_state); 831 CheckScopeContent({x:14}, 2, exec_state);
753 CheckScopeContent({j:13}, 3, exec_state); 832 CheckScopeContent({j:13}, 3, exec_state);
754 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state); 833 CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state);
755 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state); 834 CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state);
756 }; 835 };
757 the_full_monty(1, 2)(); 836 the_full_monty(1, 2)();
758 EndTest(); 837 EndTest();
759 838
760 839
840 BeginTest("Generator the full monty");
841 function* generator_the_full_monty(a, b) {
842 var x = 3;
843 var y = 4;
844 eval('var i = 5');
845 eval('var j = 6');
846 function f(a, b) {
847 var x = 9;
848 var y = 10;
849 eval('var i = 11');
850 eval('var j = 12');
851 with ({j:13}){
852 return function() {
853 var x = 14;
854 with ({a:15}) {
855 with ({b:16}) {
856 debugger;
857 some_global = a;
858 return f;
859 }
860 }
861 };
862 }
863 }
864 return f(a, b);
865 }
866 generator_the_full_monty(1, 2).next().value();
867 EndTest();
868
869
761 BeginTest("Closure inside With 1"); 870 BeginTest("Closure inside With 1");
762 function closure_in_with_1() { 871 function closure_in_with_1() {
763 with({x:1}) { 872 with({x:1}) {
764 (function inner(x) { 873 (function inner(x) {
765 debugger; 874 debugger;
766 })(2); 875 })(2);
767 } 876 }
768 } 877 }
769 878
770 listener_delegate = function(exec_state) { 879 listener_delegate = function(exec_state) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 listener_delegate = function(exec_state) { 980 listener_delegate = function(exec_state) {
872 CheckScopeChain([debug.ScopeType.Catch, 981 CheckScopeChain([debug.ScopeType.Catch,
873 debug.ScopeType.Local, 982 debug.ScopeType.Local,
874 debug.ScopeType.Global], exec_state); 983 debug.ScopeType.Global], exec_state);
875 CheckScopeContent({e:'Exception'}, 0, exec_state); 984 CheckScopeContent({e:'Exception'}, 0, exec_state);
876 }; 985 };
877 catch_block_1(); 986 catch_block_1();
878 EndTest(); 987 EndTest();
879 988
880 989
990 BeginTest("Generator catch block 1");
991 function *generator_catch_block_1() {
992 try {
993 throw 'Exception';
994 } catch (e) {
995 debugger;
996 }
997 };
998 generator_catch_block_1().next();
999 EndTest();
1000
1001
881 BeginTest("Catch block 2"); 1002 BeginTest("Catch block 2");
882 function catch_block_2() { 1003 function catch_block_2() {
883 try { 1004 try {
884 throw 'Exception'; 1005 throw 'Exception';
885 } catch (e) { 1006 } catch (e) {
886 with({n:10}) { 1007 with({n:10}) {
887 debugger; 1008 debugger;
888 } 1009 }
889 } 1010 }
890 }; 1011 };
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 CheckScopeContent({e:'Exception'}, 0, exec_state); 1130 CheckScopeContent({e:'Exception'}, 0, exec_state);
1010 }; 1131 };
1011 catch_block_7(); 1132 catch_block_7();
1012 EndTest(); 1133 EndTest();
1013 1134
1014 1135
1015 assertEquals(begin_test_count, break_count, 1136 assertEquals(begin_test_count, break_count,
1016 'one or more tests did not enter the debugger'); 1137 'one or more tests did not enter the debugger');
1017 assertEquals(begin_test_count, end_test_count, 1138 assertEquals(begin_test_count, end_test_count,
1018 'one or more tests did not have its result checked'); 1139 'one or more tests did not have its result checked');
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/debug-stepout-scope-part2.js » ('j') | test/mjsunit/debug-stepout-scope-part2.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698