Chromium Code Reviews| Index: test/mjsunit/es6/generators-iteration.js |
| diff --git a/test/mjsunit/es6/generators-iteration.js b/test/mjsunit/es6/generators-iteration.js |
| index e61a7c3a9a5c8a44060ab5f380bc347c38291a19..ae4c682e7e8504c70e62dfae4b17d7ac908b3ca6 100644 |
| --- a/test/mjsunit/es6/generators-iteration.js |
| +++ b/test/mjsunit/es6/generators-iteration.js |
| @@ -397,39 +397,17 @@ TestGenerator( |
| "foo", |
| [42, undefined]); |
| -// Test that yield* re-yields received results without re-boxing. |
|
rossberg
2016/01/29 18:12:27
Why did this test go away?
neis
2016/01/31 19:21:49
I replaced it with one that checks the correct beh
|
| -function TestDelegatingYield() { |
| - function results(results) { |
| - var i = 0; |
| - function next() { |
| - return results[i++]; |
| - } |
| - var iter = { next: next }; |
| - var ret = {}; |
| - ret[Symbol.iterator] = function() { return iter; }; |
| - return ret; |
| - } |
| - function* yield_results(expected) { |
| - return yield* results(expected); |
| - } |
| - function collect_results(iterable) { |
| - var iter = iterable[Symbol.iterator](); |
| - var ret = []; |
| - var result; |
| - do { |
| - result = iter.next(); |
| - ret.push(result); |
| - } while (!result.done); |
| - return ret; |
| - } |
| - // We have to put a full result for the end, because the return will re-box. |
| - var expected = [{value: 1}, 13, "foo", {value: 34, done: true}]; |
| - |
| - // Sanity check. |
| - assertEquals(expected, collect_results(results(expected))); |
| - assertEquals(expected, collect_results(yield_results(expected))); |
| +// Test that yield* validates iterator results. |
| +function TestDelegatingYield(junk) { |
| + var iterator = {next: () => junk}; |
| + var iterable = {[Symbol.iterator]: () => iterator}; |
| + function* g() { return yield* iterable }; |
| + assertThrows(() => g().next(), TypeError); |
| } |
| TestDelegatingYield(); |
| +TestDelegatingYield(null); |
| +TestDelegatingYield(42); |
| +TestDelegatingYield(true); |
| function TestTryCatch(instantiate) { |
| function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; } |
| @@ -681,3 +659,16 @@ function TestRecursion() { |
| assertThrows(TestThrowRecursion, Error); |
| } |
| TestRecursion(); |
| + |
| + |
| +// Test yield* on non-iterable objects. |
| +function* g(junk) { return yield* junk } |
| +var non_iterables = [ |
| + 42, |
| + {[Symbol.iterator]: 42}, |
| + {[Symbol.iterator]: () => 42}, |
| + {[Symbol.iterator]: () => ({next: 42})}, |
| +]; |
| +for (let junk of non_iterables) { |
| + assertThrows(() => g(junk).next(), TypeError); |
| +} |