| Index: test/mjsunit/harmony/generators-iteration.js
|
| diff --git a/test/mjsunit/harmony/generators-iteration.js b/test/mjsunit/harmony/generators-iteration.js
|
| index d86a20f9e7da2cd52a59dd3cb15eb4bcfea76ec8..e6c05e3445996f96ac0d638ff8a96d46cc63d54e 100644
|
| --- a/test/mjsunit/harmony/generators-iteration.js
|
| +++ b/test/mjsunit/harmony/generators-iteration.js
|
| @@ -74,7 +74,12 @@ function TestGenerator(g, expected_values_for_next,
|
| }
|
| function testSend(thunk) {
|
| var iter = thunk();
|
| - for (var i = 0; i < expected_values_for_send.length; i++) {
|
| + // Throw error when sending a value to a newly created generator.
|
| + if (expected_values_for_send.length > 0) {
|
| + assertThrows(function () { iter.next(send_val); }, TypeError);
|
| + assertIteratorResult(expected_values_for_send[0], 0 == expected_values_for_send.length - 1, iter.next());
|
| + }
|
| + for (var i = 1; i < expected_values_for_send.length; i++) {
|
| assertIteratorResult(expected_values_for_send[i],
|
| i == expected_values_for_send.length - 1,
|
| iter.next(send_val));
|
| @@ -648,3 +653,37 @@ function TestRecursion() {
|
| assertThrows(TestThrowRecursion, Error);
|
| }
|
| TestRecursion();
|
| +
|
| +function TestNewlyCreated(instantiate) {
|
| + function * g() { return yield 1; }
|
| +
|
| + function Test1(iter) {
|
| + assertThrows(function () { iter.next(1); }, TypeError);
|
| + // Iterator is still "suspendedStart" state.
|
| + assertThrows(function () { iter.next(1); }, TypeError);
|
| + assertIteratorResult(1, false, iter.next());
|
| + assertIteratorResult(2, true, iter.next(2));
|
| + assertIteratorIsClosed(iter);
|
| + }
|
| + Test1(instantiate(g));
|
| +
|
| + function Test1(iter) {
|
| + // If a provided value is undefined, iter with "suspendedStart" status
|
| + // doesn't throw an error.
|
| + assertIteratorResult(1, false, iter.next(undefined));
|
| + assertIteratorResult(2, true, iter.next(2));
|
| + assertIteratorIsClosed(iter);
|
| + }
|
| + Test1(instantiate(g));
|
| +
|
| + function Test2(iter) {
|
| + function Sentinel() { }
|
| + assertThrows(function () { iter.throw(new Sentinel); }, Sentinel);
|
| + // When calling throw method to an newly created iterator, it becomes
|
| + // "completed" state.
|
| + assertThrownIteratorIsClosed(iter);
|
| + }
|
| + Test2(instantiate(g));
|
| +}
|
| +TestNewlyCreated(function (g) { return g(); });
|
| +TestNewlyCreated(function* (g) { return yield* g(); });
|
|
|