| OLD | NEW |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 for (var i = 0; i < expected_values_for_next.length; i++) { | 67 for (var i = 0; i < expected_values_for_next.length; i++) { |
| 68 var v1 = expected_values_for_next[i]; | 68 var v1 = expected_values_for_next[i]; |
| 69 var v2 = i == expected_values_for_next.length - 1; | 69 var v2 = i == expected_values_for_next.length - 1; |
| 70 // var v3 = iter.next(); | 70 // var v3 = iter.next(); |
| 71 assertIteratorResult(v1, v2, iter.next()); | 71 assertIteratorResult(v1, v2, iter.next()); |
| 72 } | 72 } |
| 73 assertIteratorIsClosed(iter); | 73 assertIteratorIsClosed(iter); |
| 74 } | 74 } |
| 75 function testSend(thunk) { | 75 function testSend(thunk) { |
| 76 var iter = thunk(); | 76 var iter = thunk(); |
| 77 for (var i = 0; i < expected_values_for_send.length; i++) { | 77 // Throw error when sending a value to a newly created generator. |
| 78 if (expected_values_for_send.length > 0) { |
| 79 assertThrows(function () { iter.next(send_val); }, TypeError); |
| 80 assertIteratorResult(expected_values_for_send[0], 0 == expected_values_f
or_send.length - 1, iter.next()); |
| 81 } |
| 82 for (var i = 1; i < expected_values_for_send.length; i++) { |
| 78 assertIteratorResult(expected_values_for_send[i], | 83 assertIteratorResult(expected_values_for_send[i], |
| 79 i == expected_values_for_send.length - 1, | 84 i == expected_values_for_send.length - 1, |
| 80 iter.next(send_val)); | 85 iter.next(send_val)); |
| 81 } | 86 } |
| 82 assertIteratorIsClosed(iter); | 87 assertIteratorIsClosed(iter); |
| 83 } | 88 } |
| 84 function testThrow(thunk) { | 89 function testThrow(thunk) { |
| 85 for (var i = 0; i < expected_values_for_next.length; i++) { | 90 for (var i = 0; i < expected_values_for_next.length; i++) { |
| 86 var iter = thunk(); | 91 var iter = thunk(); |
| 87 for (var j = 0; j < i; j++) { | 92 for (var j = 0; j < i; j++) { |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 function TestThrowRecursion() { | 646 function TestThrowRecursion() { |
| 642 function* g() { yield iter.throw(1); } | 647 function* g() { yield iter.throw(1); } |
| 643 var iter = g(); | 648 var iter = g(); |
| 644 return iter.next(); | 649 return iter.next(); |
| 645 } | 650 } |
| 646 assertThrows(TestNextRecursion, Error); | 651 assertThrows(TestNextRecursion, Error); |
| 647 assertThrows(TestSendRecursion, Error); | 652 assertThrows(TestSendRecursion, Error); |
| 648 assertThrows(TestThrowRecursion, Error); | 653 assertThrows(TestThrowRecursion, Error); |
| 649 } | 654 } |
| 650 TestRecursion(); | 655 TestRecursion(); |
| 656 |
| 657 function TestNewlyCreated(instantiate) { |
| 658 function * g() { return yield 1; } |
| 659 |
| 660 function Test1(iter) { |
| 661 assertThrows(function () { iter.next(1); }, TypeError); |
| 662 // Iterator is still "suspendedStart" state. |
| 663 assertThrows(function () { iter.next(1); }, TypeError); |
| 664 assertIteratorResult(1, false, iter.next()); |
| 665 assertIteratorResult(2, true, iter.next(2)); |
| 666 assertIteratorIsClosed(iter); |
| 667 } |
| 668 Test1(instantiate(g)); |
| 669 |
| 670 function Test1(iter) { |
| 671 // If a provided value is undefined, iter with "suspendedStart" status |
| 672 // doesn't throw an error. |
| 673 assertIteratorResult(1, false, iter.next(undefined)); |
| 674 assertIteratorResult(2, true, iter.next(2)); |
| 675 assertIteratorIsClosed(iter); |
| 676 } |
| 677 Test1(instantiate(g)); |
| 678 |
| 679 function Test2(iter) { |
| 680 function Sentinel() { } |
| 681 assertThrows(function () { iter.throw(new Sentinel); }, Sentinel); |
| 682 // When calling throw method to an newly created iterator, it becomes |
| 683 // "completed" state. |
| 684 assertThrownIteratorIsClosed(iter); |
| 685 } |
| 686 Test2(instantiate(g)); |
| 687 } |
| 688 TestNewlyCreated(function (g) { return g(); }); |
| 689 TestNewlyCreated(function* (g) { return yield* g(); }); |
| OLD | NEW |