Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: test/mjsunit/harmony/iterator-close.js

Issue 2034653002: Fix bug in yield* desugaring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/iterator-close.js
diff --git a/test/mjsunit/harmony/iterator-close.js b/test/mjsunit/harmony/iterator-close.js
index 02dc9d326f35ec07cd20dfd0d49326ee551bcdd1..03cdeac0383b4660da1e267a7f41ae6024fc3b60 100644
--- a/test/mjsunit/harmony/iterator-close.js
+++ b/test/mjsunit/harmony/iterator-close.js
@@ -1298,3 +1298,75 @@ function* g() { yield 42; return 88 };
}, 5);
assertEquals([1], log);
}
+
+
+// yield*, argument's return method is "undefined".
+function TestYieldStarWithoutReturn(get_iterable) {
+ assertTrue(get_iterable().return == undefined);
+
+ function* g() { yield* get_iterable() }
+
+ {
+ let gen = g();
+ assertEquals({value: 1, done: false}, gen.next());
+ assertEquals({value: undefined, done: true}, gen.return());
+ }
+
+ assertEquals(42, (() => {
+ for (let x of g()) break;
+ return 42;
+ })());
+
+ assertEquals(42, (() => {
+ for (let x of g()) return 42;
+ })());
+
+ assertThrowsEquals(() => {
+ for (let x of g()) throw 42;
+ }, 42);
+}
+{
+ let get_iterable1 = () => [1, 2];
+ let get_iterable2 = function*() { yield 1; yield 2 };
+ get_iterable2.prototype.return = null;
+ TestYieldStarWithoutReturn(get_iterable1);
+ TestYieldStarWithoutReturn(get_iterable2);
+}
+
+
+// yield*, argument's return method is defined.
+{
+ let get_iterable = function*() { yield 1; yield 2 };
+ const obj = {};
+ get_iterable.prototype.return = (...args) => obj;
+
+ function* g() { yield* get_iterable() }
+
+ {
+ let gen = g();
+ assertEquals({value: 1, done: false}, gen.next());
+ assertSame(obj, gen.return());
+ assertSame(obj, gen.return());
+ assertSame(obj, gen.return());
+ assertEquals({value: 2, done: false}, gen.next());
+ assertSame(obj, gen.return());
+ assertSame(obj, gen.return());
+ assertSame(obj, gen.return());
+ assertEquals({value: undefined, done: true}, gen.next());
+ assertEquals({value: undefined, done: true}, gen.return());
+ assertEquals({value: undefined, done: true}, gen.return());
+ }
+
+ assertEquals(42, (() => {
+ for (let x of g()) break;
+ return 42;
+ })());
+
+ assertEquals(42, (() => {
+ for (let x of g()) return 42;
+ })());
+
+ assertThrowsEquals(() => {
+ for (let x of g()) throw 42;
+ }, 42);
+}
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698