Index: test/test262/local-tests/test/language/statements/for-await-of/Symbol.iterator-async-generator.js |
diff --git a/test/test262/local-tests/test/language/statements/for-await-of/Symbol.iterator-async-generator.js b/test/test262/local-tests/test/language/statements/for-await-of/Symbol.iterator-async-generator.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7b78680e62ab13b2959d15a062729caa8dbd30e0 |
--- /dev/null |
+++ b/test/test262/local-tests/test/language/statements/for-await-of/Symbol.iterator-async-generator.js |
@@ -0,0 +1,66 @@ |
+// Copyright (C) 2017 the V8 project authors. All rights reserved. |
+// This code is governed by the BSD license found in the LICENSE file. |
+ |
+/*--- |
+author: Caitlin Potter <caitp@igalia.com> |
+description: > |
+ If [Symbol.asyncIterator] is null on target of the IterationStatement, |
+ invoke it [Symbol.iterator] instead. |
+es6id: pending |
+flags: [async] |
+---*/ |
+ |
+var log = []; |
+var iterable = Object.setPrototypeOf({ |
+ [Symbol.iterator]() { |
+ log.push("iterable[@@iterator]()"); |
+ return this; |
+ }, |
+ [Symbol.asyncIterator]: null, |
+ |
+ next() { |
+ log.push("iterable.next()"); |
+ if (this._i < this._items.length) { |
+ var value = this._items[this._i++]; |
+ return { value: Promise.resolve(value), done: false }; |
+ } |
+ return { value: undefined, done: true }; |
+ }, |
+ |
+ _i: 0, |
+ _items: ["a", "b", "c"] |
+}, null); |
+ |
+async function* g(iterable) { |
+ log.push("begin iteration"); |
+ var i = 0; |
+ for await (var value of iterable) { |
+ log.push("awaited value " + value); |
+ ++i; |
+ } |
+ yield i; |
+} |
+ |
+var iter = g(iterable); |
+iter.next().then(function(result) { |
+ assert.sameValue(result.value, 3, "Visits all elements"); |
+ assert.sameValue(result.done, false); |
+ log.push("done"); |
+}, $DONE).then(undefined, $DONE); |
+ |
+iter.next().then(function(result) { |
+ assert.sameValue(result.value, undefined); |
+ assert.sameValue(result.done, true); |
+ assert.sameValue(log.join("\n"), [ |
+ "begin iteration", |
+ "iterable[@@iterator]()", |
+ "iterable.next()", |
+ "awaited value a", |
+ "iterable.next()", |
+ "awaited value b", |
+ "iterable.next()", |
+ "awaited value c", |
+ "iterable.next()", |
+ "done" |
+ ].join("\n")); |
+}, $DONE).then($DONE, $DONE); |