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

Side by Side Diff: test/mjsunit/harmony/generators-iteration.js

Issue 14582007: Implement yield* (delegating yield) (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Fix asm nits; rework test suite to test yield* on everything Created 7 years, 7 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
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 function Sentinel() {} 66 function Sentinel() {}
67 assertThrows(function () { iter.throw(new Sentinel); }, Sentinel); 67 assertThrows(function () { iter.throw(new Sentinel); }, Sentinel);
68 assertThrows(function () { iter.next(); }, Error); 68 assertThrows(function () { iter.next(); }, Error);
69 } 69 }
70 } 70 }
71 71
72 testNext(g); 72 testNext(g);
73 testSend(g); 73 testSend(g);
74 testThrow(g); 74 testThrow(g);
75 75
76 testNext(function*() { return yield* g(); });
77 testSend(function*() { return yield* g(); });
78 testThrow(function*() { return yield* g(); });
79
76 if (g instanceof GeneratorFunction) { 80 if (g instanceof GeneratorFunction) {
77 testNext(function() { return new g(); }); 81 testNext(function() { return new g(); });
78 testSend(function() { return new g(); }); 82 testSend(function() { return new g(); });
79 testThrow(function() { return new g(); }); 83 testThrow(function() { return new g(); });
80 } 84 }
81 } 85 }
82 86
83 TestGenerator(function* g1() { }, 87 TestGenerator(function* g1() { },
84 [undefined], 88 [undefined],
85 "foo", 89 "foo",
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 throw (yield (1 + (yield 2) + 3)) 304 throw (yield (1 + (yield 2) + 3))
301 } catch (e) { 305 } catch (e) {
302 if (typeof e == 'object') throw e; 306 if (typeof e == 'object') throw e;
303 return e + (yield (4 + (yield 5) + 6)); 307 return e + (yield (4 + (yield 5) + 6));
304 } 308 }
305 }, 309 },
306 [2, NaN, 5, NaN, NaN], 310 [2, NaN, 5, NaN, NaN],
307 "foo", 311 "foo",
308 [2, "1foo3", 5, "4foo6", "foofoo"]); 312 [2, "1foo3", 5, "4foo6", "foofoo"]);
309 313
310 function TestTryCatch() { 314 function TestTryCatch(instantiate) {
311 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } 315 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; }
312 function Sentinel() {} 316 function Sentinel() {}
313 var iter;
314 317
315 iter = g(); 318 function Test1(iter) {
316 assertIteratorResult(1, false, iter.next()); 319 assertIteratorResult(1, false, iter.next());
317 assertIteratorResult(2, false, iter.next()); 320 assertIteratorResult(2, false, iter.next());
318 assertIteratorResult(3, false, iter.next()); 321 assertIteratorResult(3, false, iter.next());
319 assertIteratorResult(undefined, true, iter.next()); 322 assertIteratorResult(undefined, true, iter.next());
320 assertThrows(function() { iter.next(); }, Error); 323 assertThrows(function() { iter.next(); }, Error);
324 }
325 Test1(instantiate(g));
321 326
322 iter = g(); 327 function Test2(iter) {
323 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 328 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
324 assertThrows(function() { iter.next(); }, Error); 329 assertThrows(function() { iter.next(); }, Error);
330 }
331 Test2(instantiate(g));
325 332
326 iter = g(); 333 function Test3(iter) {
327 assertIteratorResult(1, false, iter.next()); 334 assertIteratorResult(1, false, iter.next());
328 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 335 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
329 assertThrows(function() { iter.next(); }, Error); 336 assertThrows(function() { iter.next(); }, Error);
337 }
338 Test3(instantiate(g));
330 339
331 iter = g(); 340 function Test4(iter) {
332 assertIteratorResult(1, false, iter.next()); 341 assertIteratorResult(1, false, iter.next());
333 assertIteratorResult(2, false, iter.next()); 342 assertIteratorResult(2, false, iter.next());
334 var exn = new Sentinel; 343 var exn = new Sentinel;
335 assertIteratorResult(exn, false, iter.throw(exn)); 344 assertIteratorResult(exn, false, iter.throw(exn));
336 assertIteratorResult(3, false, iter.next()); 345 assertIteratorResult(3, false, iter.next());
337 assertIteratorResult(undefined, true, iter.next()); 346 assertIteratorResult(undefined, true, iter.next());
338 assertThrows(function() { iter.next(); }, Error); 347 assertThrows(function() { iter.next(); }, Error);
348 }
349 Test4(instantiate(g));
339 350
340 iter = g(); 351 function Test5(iter) {
341 assertIteratorResult(1, false, iter.next()); 352 assertIteratorResult(1, false, iter.next());
342 assertIteratorResult(2, false, iter.next()); 353 assertIteratorResult(2, false, iter.next());
343 var exn = new Sentinel; 354 var exn = new Sentinel;
344 assertIteratorResult(exn, false, iter.throw(exn)); 355 assertIteratorResult(exn, false, iter.throw(exn));
345 assertIteratorResult(3, false, iter.next()); 356 assertIteratorResult(3, false, iter.next());
346 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 357 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
347 assertThrows(function() { iter.next(); }, Error); 358 assertThrows(function() { iter.next(); }, Error);
348 359
349 iter = g(); 360 }
350 assertIteratorResult(1, false, iter.next()); 361 Test5(instantiate(g));
351 assertIteratorResult(2, false, iter.next());
352 var exn = new Sentinel;
353 assertIteratorResult(exn, false, iter.throw(exn));
354 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
355 assertThrows(function() { iter.next(); }, Error);
356 362
357 iter = g(); 363 function Test6(iter) {
358 assertIteratorResult(1, false, iter.next()); 364 assertIteratorResult(1, false, iter.next());
359 assertIteratorResult(2, false, iter.next()); 365 assertIteratorResult(2, false, iter.next());
360 assertIteratorResult(3, false, iter.next()); 366 var exn = new Sentinel;
361 assertIteratorResult(undefined, true, iter.next()); 367 assertIteratorResult(exn, false, iter.throw(exn));
362 assertThrows(function() { iter.next(); }, Error); 368 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
369 assertThrows(function() { iter.next(); }, Error);
370 }
371 Test6(instantiate(g));
372
373 function Test7(iter) {
374 assertIteratorResult(1, false, iter.next());
375 assertIteratorResult(2, false, iter.next());
376 assertIteratorResult(3, false, iter.next());
377 assertIteratorResult(undefined, true, iter.next());
378 assertThrows(function() { iter.next(); }, Error);
379 }
380 Test7(instantiate(g));
363 } 381 }
364 TestTryCatch(); 382 TestTryCatch(function (g) { return g(); });
383 TestTryCatch(function* (g) { return yield* g(); });
365 384
366 function TestTryFinally() { 385 function TestTryFinally(instantiate) {
367 function* g() { yield 1; try { yield 2; } finally { yield 3; } yield 4; } 386 function* g() { yield 1; try { yield 2; } finally { yield 3; } yield 4; }
368 function Sentinel() {} 387 function Sentinel() {}
369 function Sentinel2() {} 388 function Sentinel2() {}
370 var iter;
371 389
372 iter = g(); 390 function Test1(iter) {
373 assertIteratorResult(1, false, iter.next()); 391 assertIteratorResult(1, false, iter.next());
374 assertIteratorResult(2, false, iter.next()); 392 assertIteratorResult(2, false, iter.next());
375 assertIteratorResult(3, false, iter.next()); 393 assertIteratorResult(3, false, iter.next());
376 assertIteratorResult(4, false, iter.next()); 394 assertIteratorResult(4, false, iter.next());
377 assertIteratorResult(undefined, true, iter.next()); 395 assertIteratorResult(undefined, true, iter.next());
378 assertThrows(function() { iter.next(); }, Error); 396 assertThrows(function() { iter.next(); }, Error);
397 }
398 Test1(instantiate(g));
379 399
380 iter = g(); 400 function Test2(iter) {
381 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 401 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
382 assertThrows(function() { iter.next(); }, Error); 402 assertThrows(function() { iter.next(); }, Error);
403 }
404 Test2(instantiate(g));
383 405
384 iter = g(); 406 function Test3(iter) {
385 assertIteratorResult(1, false, iter.next()); 407 assertIteratorResult(1, false, iter.next());
386 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 408 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
387 assertThrows(function() { iter.next(); }, Error); 409 assertThrows(function() { iter.next(); }, Error);
410 }
411 Test3(instantiate(g));
388 412
389 iter = g(); 413 function Test4(iter) {
390 assertIteratorResult(1, false, iter.next()); 414 assertIteratorResult(1, false, iter.next());
391 assertIteratorResult(2, false, iter.next()); 415 assertIteratorResult(2, false, iter.next());
392 assertIteratorResult(3, false, iter.throw(new Sentinel)); 416 assertIteratorResult(3, false, iter.throw(new Sentinel));
393 assertThrows(function() { iter.next(); }, Sentinel); 417 assertThrows(function() { iter.next(); }, Sentinel);
394 assertThrows(function() { iter.next(); }, Error); 418 assertThrows(function() { iter.next(); }, Error);
395 419
396 iter = g(); 420 }
397 assertIteratorResult(1, false, iter.next()); 421 Test4(instantiate(g));
398 assertIteratorResult(2, false, iter.next());
399 assertIteratorResult(3, false, iter.throw(new Sentinel));
400 assertThrows(function() { iter.throw(new Sentinel2); }, Sentinel2);
401 assertThrows(function() { iter.next(); }, Error);
402 422
403 iter = g(); 423 function Test5(iter) {
404 assertIteratorResult(1, false, iter.next()); 424 assertIteratorResult(1, false, iter.next());
405 assertIteratorResult(2, false, iter.next()); 425 assertIteratorResult(2, false, iter.next());
406 assertIteratorResult(3, false, iter.next()); 426 assertIteratorResult(3, false, iter.throw(new Sentinel));
407 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 427 assertThrows(function() { iter.throw(new Sentinel2); }, Sentinel2);
408 assertThrows(function() { iter.next(); }, Error); 428 assertThrows(function() { iter.next(); }, Error);
429 }
430 Test5(instantiate(g));
409 431
410 iter = g(); 432 function Test6(iter) {
411 assertIteratorResult(1, false, iter.next()); 433 assertIteratorResult(1, false, iter.next());
412 assertIteratorResult(2, false, iter.next()); 434 assertIteratorResult(2, false, iter.next());
413 assertIteratorResult(3, false, iter.next()); 435 assertIteratorResult(3, false, iter.next());
414 assertIteratorResult(4, false, iter.next()); 436 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
415 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 437 assertThrows(function() { iter.next(); }, Error);
416 assertThrows(function() { iter.next(); }, Error); 438 }
439 Test6(instantiate(g));
417 440
418 iter = g(); 441 function Test7(iter) {
419 assertIteratorResult(1, false, iter.next()); 442 assertIteratorResult(1, false, iter.next());
420 assertIteratorResult(2, false, iter.next()); 443 assertIteratorResult(2, false, iter.next());
421 assertIteratorResult(3, false, iter.next()); 444 assertIteratorResult(3, false, iter.next());
422 assertIteratorResult(4, false, iter.next()); 445 assertIteratorResult(4, false, iter.next());
423 assertIteratorResult(undefined, true, iter.next()); 446 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
424 assertThrows(function() { iter.next(); }, Error); 447 assertThrows(function() { iter.next(); }, Error);
448 }
449 Test7(instantiate(g));
450
451 function Test8(iter) {
452 assertIteratorResult(1, false, iter.next());
453 assertIteratorResult(2, false, iter.next());
454 assertIteratorResult(3, false, iter.next());
455 assertIteratorResult(4, false, iter.next());
456 assertIteratorResult(undefined, true, iter.next());
457 assertThrows(function() { iter.next(); }, Error);
458
459 }
460 Test8(instantiate(g));
425 } 461 }
426 TestTryFinally(); 462 TestTryFinally(function (g) { return g(); });
463 TestTryFinally(function* (g) { return yield* g(); });
427 464
428 function TestNestedTry() { 465 function TestNestedTry(instantiate) {
429 function* g() { 466 function* g() {
430 try { 467 try {
431 yield 1; 468 yield 1;
432 try { yield 2; } catch (e) { yield e; } 469 try { yield 2; } catch (e) { yield e; }
433 yield 3; 470 yield 3;
434 } finally { 471 } finally {
435 yield 4; 472 yield 4;
436 } 473 }
437 yield 5; 474 yield 5;
438 } 475 }
439 function Sentinel() {} 476 function Sentinel() {}
440 function Sentinel2() {} 477 function Sentinel2() {}
441 var iter;
442 478
443 iter = g(); 479 function Test1(iter) {
444 assertIteratorResult(1, false, iter.next()); 480 assertIteratorResult(1, false, iter.next());
445 assertIteratorResult(2, false, iter.next()); 481 assertIteratorResult(2, false, iter.next());
446 assertIteratorResult(3, false, iter.next()); 482 assertIteratorResult(3, false, iter.next());
447 assertIteratorResult(4, false, iter.next()); 483 assertIteratorResult(4, false, iter.next());
448 assertIteratorResult(5, false, iter.next()); 484 assertIteratorResult(5, false, iter.next());
449 assertIteratorResult(undefined, true, iter.next()); 485 assertIteratorResult(undefined, true, iter.next());
450 assertThrows(function() { iter.next(); }, Error); 486 assertThrows(function() { iter.next(); }, Error);
487 }
488 Test1(instantiate(g));
451 489
452 iter = g(); 490 function Test2(iter) {
453 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel); 491 assertThrows(function() { iter.throw(new Sentinel); }, Sentinel);
454 assertThrows(function() { iter.next(); }, Error); 492 assertThrows(function() { iter.next(); }, Error);
493 }
494 Test2(instantiate(g));
455 495
456 iter = g(); 496 function Test3(iter) {
457 assertIteratorResult(1, false, iter.next()); 497 assertIteratorResult(1, false, iter.next());
458 assertIteratorResult(4, false, iter.throw(new Sentinel)); 498 assertIteratorResult(4, false, iter.throw(new Sentinel));
459 assertThrows(function() { iter.next(); }, Sentinel); 499 assertThrows(function() { iter.next(); }, Sentinel);
460 assertThrows(function() { iter.next(); }, Error); 500 assertThrows(function() { iter.next(); }, Error);
501 }
502 Test3(instantiate(g));
461 503
462 iter = g(); 504 function Test4(iter) {
463 assertIteratorResult(1, false, iter.next()); 505 assertIteratorResult(1, false, iter.next());
464 assertIteratorResult(4, false, iter.throw(new Sentinel)); 506 assertIteratorResult(4, false, iter.throw(new Sentinel));
465 assertThrows(function() { iter.throw(new Sentinel2); }, Sentinel2); 507 assertThrows(function() { iter.throw(new Sentinel2); }, Sentinel2);
466 assertThrows(function() { iter.next(); }, Error); 508 assertThrows(function() { iter.next(); }, Error);
509 }
510 Test4(instantiate(g));
467 511
468 iter = g(); 512 function Test5(iter) {
469 assertIteratorResult(1, false, iter.next()); 513 assertIteratorResult(1, false, iter.next());
470 assertIteratorResult(2, false, iter.next()); 514 assertIteratorResult(2, false, iter.next());
471 var exn = new Sentinel; 515 var exn = new Sentinel;
472 assertIteratorResult(exn, false, iter.throw(exn)); 516 assertIteratorResult(exn, false, iter.throw(exn));
473 assertIteratorResult(3, false, iter.next()); 517 assertIteratorResult(3, false, iter.next());
474 assertIteratorResult(4, false, iter.next()); 518 assertIteratorResult(4, false, iter.next());
475 assertIteratorResult(5, false, iter.next()); 519 assertIteratorResult(5, false, iter.next());
476 assertIteratorResult(undefined, true, iter.next()); 520 assertIteratorResult(undefined, true, iter.next());
477 assertThrows(function() { iter.next(); }, Error); 521 assertThrows(function() { iter.next(); }, Error);
478 522
479 iter = g(); 523 }
480 assertIteratorResult(1, false, iter.next()); 524 Test5(instantiate(g));
481 assertIteratorResult(2, false, iter.next());
482 var exn = new Sentinel;
483 assertIteratorResult(exn, false, iter.throw(exn));
484 assertIteratorResult(4, false, iter.throw(new Sentinel2));
485 assertThrows(function() { iter.next(); }, Sentinel2);
486 assertThrows(function() { iter.next(); }, Error);
487 525
488 iter = g(); 526 function Test6(iter) {
489 assertIteratorResult(1, false, iter.next()); 527 assertIteratorResult(1, false, iter.next());
490 assertIteratorResult(2, false, iter.next()); 528 assertIteratorResult(2, false, iter.next());
491 var exn = new Sentinel; 529 var exn = new Sentinel;
492 assertIteratorResult(exn, false, iter.throw(exn)); 530 assertIteratorResult(exn, false, iter.throw(exn));
493 assertIteratorResult(3, false, iter.next()); 531 assertIteratorResult(4, false, iter.throw(new Sentinel2));
494 assertIteratorResult(4, false, iter.throw(new Sentinel2)); 532 assertThrows(function() { iter.next(); }, Sentinel2);
495 assertThrows(function() { iter.next(); }, Sentinel2); 533 assertThrows(function() { iter.next(); }, Error);
496 assertThrows(function() { iter.next(); }, Error); 534 }
535 Test6(instantiate(g));
536
537 function Test7(iter) {
538 assertIteratorResult(1, false, iter.next());
539 assertIteratorResult(2, false, iter.next());
540 var exn = new Sentinel;
541 assertIteratorResult(exn, false, iter.throw(exn));
542 assertIteratorResult(3, false, iter.next());
543 assertIteratorResult(4, false, iter.throw(new Sentinel2));
544 assertThrows(function() { iter.next(); }, Sentinel2);
545 assertThrows(function() { iter.next(); }, Error);
546
547 }
548 Test7(instantiate(g));
497 549
498 // That's probably enough. 550 // That's probably enough.
499 } 551 }
500 TestNestedTry(); 552 TestNestedTry(function (g) { return g(); });
553 TestNestedTry(function* (g) { return yield* g(); });
501 554
502 function TestRecursion() { 555 function TestRecursion() {
503 function TestNextRecursion() { 556 function TestNextRecursion() {
504 function* g() { yield iter.next(); } 557 function* g() { yield iter.next(); }
505 var iter = g(); 558 var iter = g();
506 return iter.next(); 559 return iter.next();
507 } 560 }
508 function TestSendRecursion() { 561 function TestSendRecursion() {
509 function* g() { yield iter.send(42); } 562 function* g() { yield iter.send(42); }
510 var iter = g(); 563 var iter = g();
511 return iter.next(); 564 return iter.next();
512 } 565 }
513 function TestThrowRecursion() { 566 function TestThrowRecursion() {
514 function* g() { yield iter.throw(1); } 567 function* g() { yield iter.throw(1); }
515 var iter = g(); 568 var iter = g();
516 return iter.next(); 569 return iter.next();
517 } 570 }
518 assertThrows(TestNextRecursion, Error); 571 assertThrows(TestNextRecursion, Error);
519 assertThrows(TestSendRecursion, Error); 572 assertThrows(TestSendRecursion, Error);
520 assertThrows(TestThrowRecursion, Error); 573 assertThrows(TestThrowRecursion, Error);
521 } 574 }
522 TestRecursion(); 575 TestRecursion();
OLDNEW
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698