Index: test/mjsunit/harmony/generators.js |
diff --git a/test/mjsunit/harmony/generators.js b/test/mjsunit/harmony/generators.js |
index c9b59bc53a2f2e52b2a0017b5597aca79387c050..ce68fd0175341c0e9afb40b42b2d711763daf4ac 100644 |
--- a/test/mjsunit/harmony/generators.js |
+++ b/test/mjsunit/harmony/generators.js |
@@ -3,6 +3,32 @@ |
// found in the LICENSE file. |
// Flags: --ignition-generators --harmony-do-expressions |
+// Flags: --allow-natives-syntax |
+ |
+ |
+function MaybeOptimizeOrDeoptimize(f) { |
+ let x = Math.random(); // --random-seed makes this deterministic |
+ if (x <= 0.33) { |
+ %OptimizeFunctionOnNextCall(f); |
+ } else if (x <= 0.66) { |
+ %DeoptimizeFunction(f); |
+ } |
+} |
+ |
+function Next(generator, ...args) { |
+ MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); |
+ return generator.next(...args); |
+} |
+ |
+function Return(generator, ...args) { |
+ MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); |
+ return generator.return(...args); |
+} |
+ |
+function Throw(generator, ...args) { |
+ MaybeOptimizeOrDeoptimize(%GeneratorGetFunction(generator)); |
+ return generator.throw(...args); |
+} |
{ // yield in try-catch |
@@ -11,19 +37,19 @@ |
try {yield 1} catch (error) {assertEquals("caught", error)} |
}; |
- assertThrowsEquals(() => g().throw("not caught"), "not caught"); |
+ assertThrowsEquals(() => Throw(g(), "not caught"), "not caught"); |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.throw("caught")); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Throw(x, "caught")); |
} |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
- assertThrowsEquals(() => x.throw("not caught"), "not caught"); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
+ assertThrowsEquals(() => Throw(x, "not caught"), "not caught"); |
} |
} |
@@ -33,19 +59,19 @@ |
{ |
let x = g(); |
- assertEquals({value: 43, done: false}, x.next()); |
- assertEquals({value: 42, done: true}, x.next()); |
+ assertEquals({value: 43, done: false}, Next(x)); |
+ assertEquals({value: 42, done: true}, Next(x)); |
} |
} |
{ // return that doesn't close |
let x; |
- let g = function*() { try {return 42} finally {x.throw(666)} }; |
+ let g = function*() { try {return 42} finally {Throw(x, 666)} }; |
{ |
x = g(); |
- assertThrows(() => x.next(), TypeError); // still executing |
+ assertThrows(() => Next(x), TypeError); // still executing |
} |
} |
@@ -56,42 +82,42 @@ |
{ // "return" closes at suspendedStart |
let x = g(); |
- assertEquals({value: 666, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next(42)); |
- assertThrowsEquals(() => x.throw(43), 43); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 42)); |
+ assertThrowsEquals(() => Throw(x, 43), 43); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
{ // "throw" closes at suspendedStart |
let x = g(); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: undefined, done: true}, x.next(42)); |
- assertEquals({value: 43, done: true}, x.return(43)); |
- assertThrowsEquals(() => x.throw(44), 44); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: undefined, done: true}, Next(x, 42)); |
+ assertEquals({value: 43, done: true}, Return(x, 43)); |
+ assertThrowsEquals(() => Throw(x, 44), 44); |
} |
{ // "next" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 13, done: true}, x.next(666)); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertThrowsEquals(() => x.throw(666), 666); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 13, done: true}, Next(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
} |
{ // "return" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 13, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertEquals({value: 666, done: true}, x.return(666)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 13, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
} |
{ // "throw" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 13, done: true}, x.throw(666)); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 13, done: true}, Throw(x, 666)); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
} |
} |
@@ -102,45 +128,45 @@ |
{ // "return" closes at suspendedStart |
let x = g(); |
- assertEquals({value: 666, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next(42)); |
- assertThrowsEquals(() => x.throw(43), 43); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 42)); |
+ assertThrowsEquals(() => Throw(x, 43), 43); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
{ // "throw" closes at suspendedStart |
let x = g(); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: undefined, done: true}, x.next(42)); |
- assertEquals({value: 43, done: true}, x.return(43)); |
- assertThrowsEquals(() => x.throw(44), 44); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: undefined, done: true}, Next(x, 42)); |
+ assertEquals({value: 43, done: true}, Return(x, 43)); |
+ assertThrowsEquals(() => Throw(x, 44), 44); |
} |
{ // "next" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
{ // "return" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 666, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertThrowsEquals(() => x.throw(44), 44); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertThrowsEquals(() => Throw(x, 44), 44); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
{ // "throw" closes at suspendedYield |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: undefined, done: true}, x.next(666)); |
- assertThrowsEquals(() => x.throw(666), 666); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: undefined, done: true}, Next(x, 666)); |
+ assertThrowsEquals(() => Throw(x, 666), 666); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
} |
@@ -151,17 +177,17 @@ |
{ |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.return(666)); |
- assertEquals({value: 13, done: true}, x.next()); |
- assertEquals({value: 666, done: true}, x.return(666)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Return(x, 666)); |
+ assertEquals({value: 13, done: true}, Next(x)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
} |
{ |
let x = g(); |
- assertEquals({value: 666, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next()); |
- assertEquals({value: 666, done: true}, x.return(666)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
} |
} |
@@ -172,17 +198,17 @@ |
{ |
let x = g(); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.return(666)); |
- assertEquals({value: 666, done: true}, x.next()); |
- assertEquals({value: 5, done: true}, x.return(5)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Return(x, 666)); |
+ assertEquals({value: 666, done: true}, Next(x)); |
+ assertEquals({value: 5, done: true}, Return(x, 5)); |
} |
{ |
let x = g(); |
- assertEquals({value: 666, done: true}, x.return(666)); |
- assertEquals({value: undefined, done: true}, x.next()); |
- assertEquals({value: 666, done: true}, x.return(666)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
+ assertEquals({value: 666, done: true}, Return(x, 666)); |
} |
} |
@@ -194,29 +220,29 @@ |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.next(666)); |
- assertEquals({value: 13, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Next(x, 666)); |
+ assertEquals({value: 13, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
} |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.return(666)); |
- assertEquals({value: 13, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Return(x, 666)); |
+ assertEquals({value: 13, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
} |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.throw(666)); |
- assertEquals({value: 13, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Throw(x, 666)); |
+ assertEquals({value: 13, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
} |
} |
@@ -228,28 +254,28 @@ |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.next(666)); |
- assertEquals({value: undefined, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Next(x, 666)); |
+ assertEquals({value: undefined, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
} |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.return(44)); |
- assertEquals({value: 44, done: false}, x.next()); |
- assertEquals({value: undefined, done: true}, x.next()); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Return(x, 44)); |
+ assertEquals({value: 44, done: false}, Next(x)); |
+ assertEquals({value: undefined, done: true}, Next(x)); |
} |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 42, done: false}, x.next()); |
- assertEquals({value: 43, done: false}, x.throw(666)); |
- assertThrowsEquals(() => x.next(), 666); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 42, done: false}, Next(x)); |
+ assertEquals({value: 43, done: false}, Throw(x, 666)); |
+ assertThrowsEquals(() => Next(x), 666); |
} |
} |
@@ -267,9 +293,9 @@ |
{ |
let x = g(); |
- assertEquals({value: 1, done: false}, x.next()); |
- assertEquals({value: 2, done: false}, x.next()); |
- assertEquals({value: 42, done: true}, x.return(42)); |
+ assertEquals({value: 1, done: false}, Next(x)); |
+ assertEquals({value: 2, done: false}, Next(x)); |
+ assertEquals({value: 42, done: true}, Return(x, 42)); |
} |
} |
@@ -280,143 +306,144 @@ |
{ |
function* foo() { } |
let g = foo(); |
- assertEquals({value: undefined, done: true}, g.next()); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
function* foo() { return new.target } |
let g = foo(); |
- assertEquals({value: undefined, done: true}, g.next()); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
function* foo() { throw 666; return 42} |
let g = foo(); |
- assertThrowsEquals(() => g.next(), 666); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertThrowsEquals(() => Next(g), 666); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
function* foo(a) { return a; } |
let g = foo(42); |
- assertEquals({value: 42, done: true}, g.next()); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: 42, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: {iwashere: true}, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
let a = 42; |
function* foo() { return a; } |
let g = foo(); |
- assertEquals({value: 42, done: true}, g.next()); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: 42, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 42, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 42, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
let g; |
- function* foo() { g.next() } |
+ function* foo() { Next(g) } |
g = foo(); |
- assertThrows(() => g.next(), TypeError); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertThrows(() => Next(g), TypeError); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
+ |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
} |
{ |
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()); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 42, done: true}, Next(g, 0)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
@@ -435,19 +462,19 @@ |
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()); |
+ assertEquals({value: 42, done: false}, Next(g)); |
+ assertEquals({value: 'a', done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 1, done: false}, Next(g)); |
+ assertEquals({value: 0, done: false}, Next(g)); |
+ assertEquals({value: 'b', done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 1, done: false}, Next(g)); |
+ assertEquals({value: 0, done: false}, Next(g)); |
+ assertEquals({value: 42, done: false}, Next(g)); |
+ assertEquals({value: 5, done: true}, Next(g)); |
} |
{ |
@@ -458,12 +485,12 @@ |
{ 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()); |
+ assertEquals({value: 1, done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 3, done: false}, Next(g)); |
+ assertEquals({value: 4, done: false}, Next(g)); |
+ assertEquals({value: 5, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
@@ -571,9 +598,9 @@ |
} |
g = foo(); |
for (let i = 0; i < 100; ++i) { |
- assertEquals({value: 42, done: false}, g.next()); |
+ assertEquals({value: 42, done: false}, i%25 === 0 ? Next(g) : g.next()); |
} |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
} |
{ |
@@ -587,14 +614,27 @@ |
} |
} |
g = foo(); |
- assertEquals({value: 0, done: false}, g.next()); |
- assertEquals({value: 10, done: false}, g.next()); |
- assertEquals({value: 10, done: false}, g.next()); |
- assertEquals({value: 1, done: false}, g.next()); |
- assertEquals({value: 11, done: false}, g.next()); |
- assertEquals({value: 11, done: false}, g.next()); |
- assertEquals({value: 2, done: false}, g.next()); |
- assertEquals({value: 12, done: false}, g.next()); |
- assertEquals({value: 12, done: false}, g.next()); |
- assertEquals({value: undefined, done: true}, g.next()); |
+ assertEquals({value: 0, done: false}, Next(g)); |
+ assertEquals({value: 10, done: false}, Next(g)); |
+ assertEquals({value: 10, done: false}, Next(g)); |
+ assertEquals({value: 1, done: false}, Next(g)); |
+ assertEquals({value: 11, done: false}, Next(g)); |
+ assertEquals({value: 11, done: false}, Next(g)); |
+ assertEquals({value: 2, done: false}, Next(g)); |
+ assertEquals({value: 12, done: false}, Next(g)); |
+ assertEquals({value: 12, done: false}, Next(g)); |
+ assertEquals({value: undefined, done: true}, Next(g)); |
+} |
+ |
+{ |
+ let foo = function*() { |
+ while (true) { |
+ if (true || false) yield 42; |
+ continue; |
+ } |
+ } |
+ g = foo(); |
+ assertEquals({value: 42, done: false}, Next(g)); |
+ assertEquals({value: 42, done: false}, Next(g)); |
+ assertEquals({value: 42, done: false}, Next(g)); |
} |