Index: test/test262/local-tests/test/language/statements/for-await-of/Symbol.asyncIterator-async-generator.js |
diff --git a/test/test262/local-tests/test/language/statements/for-await-of/Symbol.asyncIterator-async-generator.js b/test/test262/local-tests/test/language/statements/for-await-of/Symbol.asyncIterator-async-generator.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..43fbc674789b597360139da50716a835156b2824 |
--- /dev/null |
+++ b/test/test262/local-tests/test/language/statements/for-await-of/Symbol.asyncIterator-async-generator.js |
@@ -0,0 +1,72 @@ |
+// 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 present on target of the IterationStatement, |
+ invoke it. |
+es6id: pending |
+flags: [async] |
+---*/ |
+ |
+var log = []; |
+var iterable = Object.setPrototypeOf({ |
+ [Symbol.iterator]() { |
+ $DONE(new Test262Error("iterable[@@iterator]() not invoked if @@asyncIterator is present")); |
+ }, |
+ [Symbol.asyncIterator]() { |
+ log.push("iterable[@@asyncIterator]()"); |
+ return this; |
+ }, |
+ |
+ next() { |
+ log.push("iterable.next()"); |
+ var value = undefined; |
+ var done = true; |
+ if (this._i < this._items.length) { |
+ value = this._items[this._i++]; |
+ done = false; |
+ } |
+ return new Promise(function(resolve) { |
+ resolve({ value, done: done }); |
+ }); |
+ }, |
+ |
+ _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[@@asyncIterator]()", |
+ "iterable.next()", |
+ "awaited value a", |
+ "iterable.next()", |
+ "awaited value b", |
+ "iterable.next()", |
+ "awaited value c", |
+ "iterable.next()", |
+ "done" |
+ ].join("\n")); |
+}, $DONE).then($DONE, $DONE); |