From f7331dbec8e9f0ec6f196eca99382081ac9c9e76 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Thu, 17 Oct 2013 12:56:03 +0200 Subject: [PATCH] Bug 924318 - Clean up ecma_6/Generators iterator tests. r=jwalden --- .../ecma_6/Generators/delegating-yield-12.js | 16 +- .../ecma_6/Generators/delegating-yield-2.js | 24 +-- .../ecma_6/Generators/delegating-yield-3.js | 14 +- .../ecma_6/Generators/delegating-yield-4.js | 12 +- js/src/tests/ecma_6/Generators/iteration.js | 145 +++++++++--------- js/src/tests/ecma_6/Generators/shell.js | 2 +- 6 files changed, 106 insertions(+), 107 deletions(-) diff --git a/js/src/tests/ecma_6/Generators/delegating-yield-12.js b/js/src/tests/ecma_6/Generators/delegating-yield-12.js index a6e99a22109..d487ba912c8 100644 --- a/js/src/tests/ecma_6/Generators/delegating-yield-12.js +++ b/js/src/tests/ecma_6/Generators/delegating-yield-12.js @@ -30,18 +30,18 @@ function IterableWrapper(iterable) { function* delegate(iter) { return yield* iter; } var iter = delegate(IterableWrapper([1, 2, 3])); -assertIteratorResult(1, false, iter.next()); -assertIteratorResult(2, false, iter.next()); -assertIteratorResult(3, false, iter.next()); -assertIteratorResult(undefined, true, iter.next()); +assertIteratorResult(iter.next(), 1, false); +assertIteratorResult(iter.next(), 2, false); +assertIteratorResult(iter.next(), 3, false); +assertIteratorResult(iter.next(), undefined, true); assertEq(log, 'innnn'); iter = delegate([1, 2, 3]); -assertIteratorResult(1, false, iter.next()); -assertIteratorResult(2, false, iter.next()); -assertIteratorResult(3, false, iter.next()); -assertIteratorResult(undefined, true, iter.next()); +assertIteratorResult(iter.next(), 1, false); +assertIteratorResult(iter.next(), 2, false); +assertIteratorResult(iter.next(), 3, false); +assertIteratorResult(iter.next(), undefined, true); assertEq(log, 'innnn'); diff --git a/js/src/tests/ecma_6/Generators/delegating-yield-2.js b/js/src/tests/ecma_6/Generators/delegating-yield-2.js index 1f42a794e30..59ac629d6f6 100644 --- a/js/src/tests/ecma_6/Generators/delegating-yield-2.js +++ b/js/src/tests/ecma_6/Generators/delegating-yield-2.js @@ -9,36 +9,36 @@ var GeneratorObjectPrototype_throw = GeneratorObjectPrototype.throw; // An uncaught delegated throw. var inner = g1(); var outer = delegate(inner); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 1, false); assertThrowsValue(function () { outer.throw(42) }, 42); assertThrowsInstanceOf(function () { outer.throw(42) }, TypeError); // A caught delegated throw. inner = g2(); outer = delegate(inner); -assertIteratorResult(1, false, outer.next()); -assertIteratorResult(42, false, outer.throw(42)); +assertIteratorResult(outer.next(), 1, false); +assertIteratorResult(outer.throw(42), 42, false); assertThrowsValue(function () { outer.throw(42) }, 42); assertThrowsInstanceOf(function () { outer.throw(42) }, TypeError); // What would be an uncaught delegated throw, but with a monkeypatched iterator. inner = g1(); outer = delegate(inner); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 1, false); inner.throw = function(e) { return e*2; }; assertEq(84, outer.throw(42)); -assertIteratorResult(undefined, true, outer.next()); +assertIteratorResult(outer.next(), undefined, true); // Monkeypatching inner.next. inner = g1(); outer = delegate(inner); inner.next = function() { return { value: 13, done: true } }; -assertIteratorResult(13, true, outer.next()); +assertIteratorResult(outer.next(), 13, true); // What would be a caught delegated throw, but with a monkeypunched prototype. inner = g2(); outer = delegate(inner); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 1, false); delete GeneratorObjectPrototype.throw; var outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42); assertThrowsValue(outer_throw_42, 42); @@ -48,24 +48,24 @@ assertThrowsInstanceOf(outer_throw_42, TypeError); inner = g2(); outer = delegate(inner); outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 1, false); GeneratorObjectPrototype.throw = function(e) { return e*2; } assertEq(84, outer_throw_42()); assertEq(84, outer_throw_42()); // This continues indefinitely. assertEq(84, outer_throw_42()); -assertIteratorResult(undefined, true, outer.next()); +assertIteratorResult(outer.next(), undefined, true); // The same, but restoring the original pre-monkey throw. inner = g2(); outer = delegate(inner); outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 1, false); assertEq(84, outer_throw_42()); assertEq(84, outer_throw_42()); GeneratorObjectPrototype.throw = GeneratorObjectPrototype_throw; -assertIteratorResult(42, false, outer_throw_42()); -assertIteratorResult(undefined, true, outer.next()); +assertIteratorResult(outer_throw_42(), 42, false); +assertIteratorResult(outer.next(), undefined, true); if (typeof reportCompare == "function") reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Generators/delegating-yield-3.js b/js/src/tests/ecma_6/Generators/delegating-yield-3.js index 948711f9dc8..a7bafef18ef 100644 --- a/js/src/tests/ecma_6/Generators/delegating-yield-3.js +++ b/js/src/tests/ecma_6/Generators/delegating-yield-3.js @@ -8,8 +8,8 @@ var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next; // Monkeypatch next on an iterator. var inner = g(20); var outer = delegate(inner); -assertIteratorResult(0, false, outer.next()); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 0, false); +assertIteratorResult(outer.next(), 1, false); inner.next = function() { return 0; }; // 42 yielded directly without re-boxing. assertEq(0, outer.next()); @@ -17,16 +17,16 @@ assertEq(0, outer.next()); assertEq(0, outer.next()); // Restore. inner.next = GeneratorObjectPrototype_next; -assertIteratorResult(2, false, outer.next()); +assertIteratorResult(outer.next(), 2, false); // Repatch. inner.next = function() { return { value: 42, done: true }; }; -assertIteratorResult(42, true, outer.next()); +assertIteratorResult(outer.next(), 42, true); // Monkeypunch next on the prototype. var inner = g(20); var outer = delegate(inner); -assertIteratorResult(0, false, outer.next()); -assertIteratorResult(1, false, outer.next()); +assertIteratorResult(outer.next(), 0, false); +assertIteratorResult(outer.next(), 1, false); GeneratorObjectPrototype.next = function() { return 0; }; // 42 yielded directly without re-boxing. assertEq(0, GeneratorObjectPrototype_next.call(outer)); @@ -34,7 +34,7 @@ assertEq(0, GeneratorObjectPrototype_next.call(outer)); assertEq(0, GeneratorObjectPrototype_next.call(outer)); // Restore. GeneratorObjectPrototype.next = GeneratorObjectPrototype_next; -assertIteratorResult(2, false, outer.next()); +assertIteratorResult(outer.next(), 2, false); if (typeof reportCompare == "function") reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Generators/delegating-yield-4.js b/js/src/tests/ecma_6/Generators/delegating-yield-4.js index 6f2d4f975f4..4e245c74c5b 100644 --- a/js/src/tests/ecma_6/Generators/delegating-yield-4.js +++ b/js/src/tests/ecma_6/Generators/delegating-yield-4.js @@ -7,12 +7,12 @@ var inner = g(20); var outer1 = delegate(inner); var outer2 = delegate(inner); -assertIteratorResult(0, false, outer1.next()); -assertIteratorResult(1, false, outer2.next()); -assertIteratorResult(2, false, inner.next()); -assertIteratorResult(3, false, outer1.next()); -assertIteratorResult(4, false, outer2.next()); -assertIteratorResult(5, false, inner.next()); +assertIteratorResult(outer1.next(), 0, false); +assertIteratorResult(outer2.next(), 1, false); +assertIteratorResult(inner.next(), 2, false); +assertIteratorResult(outer1.next(), 3, false); +assertIteratorResult(outer2.next(), 4, false); +assertIteratorResult(inner.next(), 5, false); if (typeof reportCompare == "function") reportCompare(true, true); diff --git a/js/src/tests/ecma_6/Generators/iteration.js b/js/src/tests/ecma_6/Generators/iteration.js index db1a7b17f67..bb4120e3e6d 100644 --- a/js/src/tests/ecma_6/Generators/iteration.js +++ b/js/src/tests/ecma_6/Generators/iteration.js @@ -13,9 +13,9 @@ function TestGeneratorResultPrototype() { function* g() { yield 1; } var iter = g(); var result = iter.next(); - assertIteratorResult(1, false, result); + assertIteratorResult(result, 1, false); result = iter.next(); - assertIteratorResult(undefined, true, result); + assertIteratorResult(result, undefined, true); assertThrowsInstanceOf(function() { iter.next() }, TypeError); } TestGeneratorResultPrototype(); @@ -25,18 +25,17 @@ function TestGenerator(g, expected_values_for_next, function testNext(thunk) { var iter = thunk(); for (var i = 0; i < expected_values_for_next.length; i++) { - assertIteratorResult(expected_values_for_next[i], - i == expected_values_for_next.length - 1, - iter.next()); + assertIteratorResult(iter.next(), expected_values_for_next[i], + i == expected_values_for_next.length - 1); } assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } function testSend(thunk) { var iter = thunk(); for (var i = 0; i < expected_values_for_send.length; i++) { - assertIteratorResult(expected_values_for_send[i], - i == expected_values_for_send.length - 1, - i ? iter.next(send_val) : iter.next()); + assertIteratorResult(i ? iter.next(send_val) : iter.next(), + expected_values_for_send[i], + i == expected_values_for_send.length - 1); } assertThrowsInstanceOf(function() { iter.next(send_val); }, TypeError); } @@ -44,9 +43,9 @@ function TestGenerator(g, expected_values_for_next, for (var i = 0; i < expected_values_for_next.length; i++) { var iter = thunk(); for (var j = 0; j < i; j++) { - assertIteratorResult(expected_values_for_next[j], - j == expected_values_for_next.length - 1, - iter.next()); + assertIteratorResult(iter.next(), + expected_values_for_next[j], + j == expected_values_for_next.length - 1); } var Sentinel = function () {} assertThrowsInstanceOf(function () { iter.throw(new Sentinel); }, Sentinel); @@ -335,10 +334,10 @@ function TestTryCatch(instantiate) { function Sentinel() {} function Test1(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(undefined, true, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), undefined, true); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test1(instantiate(g)); @@ -350,29 +349,29 @@ function TestTryCatch(instantiate) { Test2(instantiate(g)); function Test3(iter) { - assertIteratorResult(1, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test3(instantiate(g)); function Test4(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(undefined, true, iter.next()); + assertIteratorResult(iter.throw(exn), exn, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), undefined, true); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test4(instantiate(g)); function Test5(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); - assertIteratorResult(3, false, iter.next()); + assertIteratorResult(iter.throw(exn), exn, false); + assertIteratorResult(iter.next(), 3, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); @@ -380,10 +379,10 @@ function TestTryCatch(instantiate) { Test5(instantiate(g)); function Test6(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); + assertIteratorResult(iter.throw(exn), exn, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } @@ -398,11 +397,11 @@ function TestTryFinally(instantiate) { function Sentinel2() {} function Test1(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(4, false, iter.next()); - assertIteratorResult(undefined, true, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), 4, false); + assertIteratorResult(iter.next(), undefined, true); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test1(instantiate(g)); @@ -414,16 +413,16 @@ function TestTryFinally(instantiate) { Test2(instantiate(g)); function Test3(iter) { - assertIteratorResult(1, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test3(instantiate(g)); function Test4(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.throw(new Sentinel)); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.throw(new Sentinel), 3, false); assertThrowsInstanceOf(function() { iter.next(); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); @@ -431,28 +430,28 @@ function TestTryFinally(instantiate) { Test4(instantiate(g)); function Test5(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.throw(new Sentinel)); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.throw(new Sentinel), 3, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test5(instantiate(g)); function Test6(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.next(), 3, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test6(instantiate(g)); function Test7(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(4, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), 4, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } @@ -476,12 +475,12 @@ function TestNestedTry(instantiate) { function Sentinel2() {} function Test1(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(4, false, iter.next()); - assertIteratorResult(5, false, iter.next()); - assertIteratorResult(undefined, true, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), 4, false); + assertIteratorResult(iter.next(), 5, false); + assertIteratorResult(iter.next(), undefined, true); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test1(instantiate(g)); @@ -493,53 +492,53 @@ function TestNestedTry(instantiate) { Test2(instantiate(g)); function Test3(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(4, false, iter.throw(new Sentinel)); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.throw(new Sentinel), 4, false); assertThrowsInstanceOf(function() { iter.next(); }, Sentinel); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test3(instantiate(g)); function Test4(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(4, false, iter.throw(new Sentinel)); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.throw(new Sentinel), 4, false); assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test4(instantiate(g)); function Test5(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(4, false, iter.next()); - assertIteratorResult(5, false, iter.next()); - assertIteratorResult(undefined, true, iter.next()); + assertIteratorResult(iter.throw(exn), exn, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.next(), 4, false); + assertIteratorResult(iter.next(), 5, false); + assertIteratorResult(iter.next(), undefined, true); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test5(instantiate(g)); function Test6(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); - assertIteratorResult(4, false, iter.throw(new Sentinel2)); + assertIteratorResult(iter.throw(exn), exn, false); + assertIteratorResult(iter.throw(new Sentinel2), 4, false); assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); } Test6(instantiate(g)); function Test7(iter) { - assertIteratorResult(1, false, iter.next()); - assertIteratorResult(2, false, iter.next()); + assertIteratorResult(iter.next(), 1, false); + assertIteratorResult(iter.next(), 2, false); var exn = new Sentinel; - assertIteratorResult(exn, false, iter.throw(exn)); - assertIteratorResult(3, false, iter.next()); - assertIteratorResult(4, false, iter.throw(new Sentinel2)); + assertIteratorResult(iter.throw(exn), exn, false); + assertIteratorResult(iter.next(), 3, false); + assertIteratorResult(iter.throw(new Sentinel2), 4, false); assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2); assertThrowsInstanceOf(function() { iter.next(); }, TypeError); diff --git a/js/src/tests/ecma_6/Generators/shell.js b/js/src/tests/ecma_6/Generators/shell.js index f46c7c04a0f..28a649a5e8c 100644 --- a/js/src/tests/ecma_6/Generators/shell.js +++ b/js/src/tests/ecma_6/Generators/shell.js @@ -16,7 +16,7 @@ var std_iterator = (function() { function assertFalse(a) { assertEq(a, false) } function assertTrue(a) { assertEq(a, true) } function assertNotEq(found, not_expected) { assertFalse(found === expected) } -function assertIteratorResult(value, done, result) { +function assertIteratorResult(result, value, done) { assertDeepEq(result.value, value); assertEq(result.done, done); }