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

Unified Diff: test/mjsunit/harmony/generators.js

Issue 1884183002: First version of the new generators implementation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 8 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
Index: test/mjsunit/harmony/generators.js
diff --git a/test/mjsunit/harmony/generators.js b/test/mjsunit/harmony/generators.js
index df6cec892532b83d37601f639ccda8aed6188d12..74bd4876066f3aac6443caecd6af283b6678db35 100644
--- a/test/mjsunit/harmony/generators.js
+++ b/test/mjsunit/harmony/generators.js
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// Flags: --ignition-generators --harmony-do-expressions
+
{ // yield in try-catch
@@ -270,3 +272,306 @@
assertEquals({value: 42, done: true}, x.return(42));
}
}
+
+
+// More or less random tests from here on.
+
+
+{
+ function* foo() { }
+ let g = foo();
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { return new.target }
+ let g = foo();
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { throw 666; return 42}
+ let g = foo();
+ assertThrowsEquals(() => g.next(), 666);
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo(a) { return a; }
+ let g = foo(42);
+ assertEquals({value: 42, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo(a) { a.iwashere = true; return a; }
+ let x = {};
+ let g = foo(x);
+ assertEquals({value: {iwashere: true}, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ let a = 42;
+ function* foo() { return a; }
+ let g = foo();
+ assertEquals({value: 42, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ let a = 40;
+ function* foo(b) { return a + b; }
+ let g = foo(2);
+ assertEquals({value: 42, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ let a = 40;
+ function* foo(b) { a--; b++; return a + b; }
+ let g = foo(2);
+ assertEquals({value: 42, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ let g;
+ function* foo() { g.next() }
+ g = foo();
+ assertThrows(() => g.next(), TypeError);
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { yield 2; yield 3; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { yield 2; if (true) { yield 3 }; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { yield 2; if (true) { yield 3; yield 4 } }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { yield 2; if (false) { yield 3 }; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() { yield 2; while (true) { yield 3 }; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+}
+
+{
+ function* foo() { yield 2; (yield 3) + 42; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+}
+
+{
+ function* foo() { yield 2; (do {yield 3}) + 42; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+}
+
+{
+ function* foo() { yield 2; return (yield 3) + 42; yield 4 }
+ g = foo();
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 42, done: true}, g.next(0));
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ let x = 42;
+ function* foo() {
+ yield x;
+ for (let x in {a: 1, b: 2}) {
+ let i = 2;
+ yield x;
+ yield i;
+ do {
+ yield i;
+ } while (i-- > 0);
+ }
+ yield x;
+ return 5;
+ }
+ g = foo();
+ assertEquals({value: 42, done: false}, g.next());
+ assertEquals({value: 'a', done: false}, g.next());
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 1, done: false}, g.next());
+ assertEquals({value: 0, done: false}, g.next());
+ assertEquals({value: 'b', done: false}, g.next());
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 1, done: false}, g.next());
+ assertEquals({value: 0, done: false}, g.next());
+ assertEquals({value: 42, done: false}, g.next());
+ assertEquals({value: 5, done: true}, g.next());
+}
+
+{
+ let a = 3;
+ function* foo() {
+ let b = 4;
+ yield 1;
+ { let c = 5; yield 2; yield a; yield b; yield c; }
+ }
+ g = foo();
+ assertEquals({value: 1, done: false}, g.next());
+ assertEquals({value: 2, done: false}, g.next());
+ assertEquals({value: 3, done: false}, g.next());
+ assertEquals({value: 4, done: false}, g.next());
+ assertEquals({value: 5, done: false}, g.next());
+ assertEquals({value: undefined, done: true}, g.next());
+}
+
+{
+ function* foo() {
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ yield 42;
+ }
+ g = foo();
+ for (let i = 0; i < 100; ++i) {
+ assertEquals({value: 42, done: false}, g.next());
+ }
+ assertEquals({value: undefined, done: true}, g.next());
+}
« src/interpreter/bytecode-generator.cc ('K') | « test/cctest/interpreter/test-interpreter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698