mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 924318 - More iterator test cleanups. r=jwalden
This commit is contained in:
parent
f7331dbec8
commit
7b4a8ad188
@ -19,3 +19,15 @@ if (typeof assertIteratorResult === 'undefined') {
|
||||
assertDeepEq(result.done, done);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof assertIteratorNext === 'undefined') {
|
||||
var assertIteratorNext = function assertIteratorNext(iter, value) {
|
||||
assertIteratorResult(iter.next(), value, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof assertIteratorDone === 'undefined') {
|
||||
var assertIteratorDone = function assertIteratorDone(iter, value) {
|
||||
assertIteratorResult(iter.next(), value, true);
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ load(libdir + "iteration.js");
|
||||
var m = Map();
|
||||
var it = m[std_iterator]();
|
||||
m.clear();
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
||||
m = Map([["a", 1], ["b", 2], ["c", 3], ["d", 4]]);
|
||||
it = m[std_iterator]();
|
||||
assertIteratorResult(it.next(), ["a", 1], false);
|
||||
assertIteratorNext(it, ["a", 1]);
|
||||
m.clear();
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
||||
var log = "";
|
||||
m = Map([["a", 1], ["b", 2], ["c", 3], ["d", 4]]);
|
||||
|
@ -5,8 +5,8 @@ load(libdir + "iteration.js");
|
||||
|
||||
var m = Map([["a", 1]]);
|
||||
var it = m[std_iterator]();
|
||||
assertIteratorResult(it.next(), ["a", 1], false);
|
||||
assertIteratorNext(it, ["a", 1]);
|
||||
m.clear();
|
||||
m.set("b", 2);
|
||||
assertIteratorResult(it.next(), ["b", 2], false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, ["b", 2]);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -22,7 +22,7 @@ var count = 0;
|
||||
for (var [k, v] of testMap) {
|
||||
assertEq(initialMap.has(k), true);
|
||||
assertEq(initialMap.get(k), testMap.get(k));
|
||||
assertIteratorResult(iterator.next(), [k, testMap.get(k)], false);
|
||||
assertIteratorNext(iterator, [k, testMap.get(k)]);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ load(libdir + "iteration.js");
|
||||
|
||||
var map = Map();
|
||||
var iter0 = map[std_iterator](), iter1 = map[std_iterator]();
|
||||
assertIteratorResult(iter0.next(), undefined, true); // closes iter0
|
||||
assertIteratorDone(iter0, undefined); // closes iter0
|
||||
map.set(1, 2);
|
||||
assertIteratorResult(iter0.next(), undefined, true); // already closed
|
||||
assertIteratorResult(iter1.next(), [1, 2], false); // was not yet closed
|
||||
assertIteratorDone(iter0, undefined); // already closed
|
||||
assertIteratorNext(iter1, [1, 2]); // was not yet closed
|
||||
|
@ -8,6 +8,6 @@ var a = iter.next(), b = iter.next();
|
||||
assertIteratorResult(a, ['a', 1], false);
|
||||
assertIteratorResult(b, ['b', 2], false);
|
||||
assertEq(a.value !== b.value, true);
|
||||
var a1 = map[std_iterator]().next();
|
||||
assertIteratorResult(a1, ['a', 1], false);
|
||||
var a1 = map[std_iterator]();
|
||||
assertIteratorNext(a1, ['a', 1]);
|
||||
assertEq(a.value !== a1.value, true);
|
||||
|
@ -5,9 +5,9 @@ load(libdir + "iteration.js");
|
||||
|
||||
var map = Map([['a', 0], ['b', 1], ['c', 2], ['d', 3]]);
|
||||
var iter = map[std_iterator]();
|
||||
assertIteratorResult(iter.next(), ['a', 0], false);
|
||||
assertIteratorResult(iter.next(), ['b', 1], false);
|
||||
assertIteratorNext(iter, ['a', 0]);
|
||||
assertIteratorNext(iter, ['b', 1]);
|
||||
map.delete('c');
|
||||
map.delete('b');
|
||||
assertIteratorResult(iter.next(), ['d', 3], false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, ['d', 3]);
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
@ -13,8 +13,8 @@ var NITERS = 5;
|
||||
var iters = [];
|
||||
for (var i = 0; i < NITERS; i++) {
|
||||
var iter = map[std_iterator]();
|
||||
assertIteratorResult(iter.next(), [0, 0], false);
|
||||
assertIteratorResult(iter.next(), [1, 1], false);
|
||||
assertIteratorNext(iter, [0, 0]);
|
||||
assertIteratorNext(iter, [1, 1]);
|
||||
iters[i] = iter;
|
||||
}
|
||||
|
||||
@ -26,6 +26,6 @@ for (var j = 0; j < SIZE; j += 2)
|
||||
for (var i = 0; i < NITERS; i++) {
|
||||
var iter = iters[i];
|
||||
for (var j = 3; j < SIZE; j += 2)
|
||||
assertIteratorResult(iter.next(), [j, j], false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, [j, j]);
|
||||
assertIteratorDone(iter, undefined);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ var map = Map();
|
||||
for (var i = 0; i < 32; i++)
|
||||
map.set(i, i);
|
||||
var iter = map[std_iterator]();
|
||||
assertIteratorResult(iter.next(), [0, 0], false);
|
||||
assertIteratorNext(iter, [0, 0]);
|
||||
for (var i = 0; i < 30; i++)
|
||||
map.delete(i);
|
||||
assertEq(map.size, 2);
|
||||
@ -16,6 +16,6 @@ for (var i = 32; i < 100; i++)
|
||||
map.set(i, i); // eventually triggers compaction
|
||||
|
||||
for (var i = 30; i < 100; i++)
|
||||
assertIteratorResult(iter.next(), [i, i], false);
|
||||
assertIteratorNext(iter, [i, i]);
|
||||
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
@ -4,7 +4,7 @@ load(libdir + "iteration.js");
|
||||
|
||||
var m = Map();
|
||||
var it = m[std_iterator]();
|
||||
assertIteratorResult(it.next(), undefined, true); // close the iterator
|
||||
assertIteratorDone(it, undefined); // close the iterator
|
||||
m.clear();
|
||||
m.set("a", 1);
|
||||
assertIteratorResult(it.next(), undefined, true); // iterator still closed
|
||||
assertIteratorDone(it, undefined); // iterator still closed
|
||||
|
@ -7,11 +7,11 @@ var data = [["one", 1], ["two", 2], ["three", 3], ["four", 4]];
|
||||
var m = Map(data);
|
||||
|
||||
var ki = m.keys();
|
||||
assertIteratorResult(ki.next(), "one", false);
|
||||
assertIteratorResult(ki.next(), "two", false);
|
||||
assertIteratorResult(ki.next(), "three", false);
|
||||
assertIteratorResult(ki.next(), "four", false);
|
||||
assertIteratorResult(ki.next(), undefined, true);
|
||||
assertIteratorNext(ki, "one");
|
||||
assertIteratorNext(ki, "two");
|
||||
assertIteratorNext(ki, "three");
|
||||
assertIteratorNext(ki, "four");
|
||||
assertIteratorDone(ki, undefined);
|
||||
|
||||
assertEq([k for (k of m.keys())].toSource(), ["one", "two", "three", "four"].toSource());
|
||||
assertEq([k for (k of m.values())].toSource(), [1, 2, 3, 4].toSource());
|
||||
|
@ -5,13 +5,13 @@ load(libdir + "iteration.js");
|
||||
var s = Set();
|
||||
var it = s[std_iterator]();
|
||||
s.clear();
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
||||
s = Set(["a", "b", "c", "d"]);
|
||||
it = s[std_iterator]();
|
||||
assertIteratorResult(it.next(), "a", false);
|
||||
assertIteratorNext(it, "a");
|
||||
s.clear();
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
||||
var log = "";
|
||||
s = Set(["a", "b", "c", "d"]);
|
||||
|
@ -4,8 +4,8 @@ load(libdir + "iteration.js");
|
||||
|
||||
var s = Set(["a"]);
|
||||
var it = s[std_iterator]();
|
||||
assertIteratorResult(it.next(), "a", false);
|
||||
assertIteratorNext(it, "a");
|
||||
s.clear();
|
||||
s.add("b");
|
||||
assertIteratorResult(it.next(), "b", false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, "b");
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -4,7 +4,7 @@ load(libdir + "iteration.js");
|
||||
|
||||
var s = Set();
|
||||
var it = s[std_iterator]();
|
||||
assertIteratorResult(it.next(), undefined, true); // close the iterator
|
||||
assertIteratorDone(it, undefined); // close the iterator
|
||||
s.clear();
|
||||
s.add("a");
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -21,7 +21,7 @@ var iterator = initialSet[std_iterator]();
|
||||
var count = 0;
|
||||
for (var v of testSet) {
|
||||
assertEq(initialSet.has(v), true);
|
||||
assertIteratorResult(iterator.next(), v, false);
|
||||
assertIteratorNext(iterator, v);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ load(libdir + "iteration.js");
|
||||
|
||||
var set = Set();
|
||||
var iter0 = set[std_iterator](), iter1 = set[std_iterator]();
|
||||
assertIteratorResult(iter0.next(), undefined, true); // closes iter0
|
||||
assertIteratorDone(iter0, undefined); // closes iter0
|
||||
set.add("x");
|
||||
assertIteratorResult(iter0.next(), undefined, true); // already closed
|
||||
assertIteratorResult(iter1.next(), "x", false); // was not yet closed
|
||||
assertIteratorDone(iter0, undefined); // already closed
|
||||
assertIteratorNext(iter1, "x"); // was not yet closed
|
||||
|
@ -9,7 +9,7 @@ var iterator_fn = Set.prototype[std_iterator];
|
||||
assertThrowsInstanceOf(function () { iterator_fn.call({}); }, TypeError);
|
||||
assertThrowsInstanceOf(function () { iterator_fn.call(Map()); }, TypeError);
|
||||
var setw = g.eval("Set(['x', 'y'])");
|
||||
assertIteratorResult(iterator_fn.call(setw).next(), "x", false);
|
||||
assertIteratorNext(iterator_fn.call(setw), "x");
|
||||
|
||||
var next_fn = Set()[std_iterator]().next;
|
||||
assertThrowsInstanceOf(function () { next_fn.call({}); }, TypeError);
|
||||
|
@ -4,9 +4,9 @@ load(libdir + "iteration.js");
|
||||
|
||||
var set = Set("abcd");
|
||||
var iter = set[std_iterator]();
|
||||
assertIteratorResult(iter.next(), "a", false);
|
||||
assertIteratorResult(iter.next(), "b", false);
|
||||
assertIteratorNext(iter, "a");
|
||||
assertIteratorNext(iter, "b");
|
||||
set.delete("c");
|
||||
set.delete("b");
|
||||
assertIteratorResult(iter.next(), "d", false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, "d");
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
@ -13,8 +13,8 @@ var NITERS = 5;
|
||||
var iters = [];
|
||||
for (var i = 0; i < NITERS; i++) {
|
||||
var iter = set[std_iterator]();
|
||||
assertIteratorResult(iter.next(), 0, false);
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorNext(iter, 0);
|
||||
assertIteratorNext(iter, 1);
|
||||
iters[i] = iter;
|
||||
}
|
||||
|
||||
@ -26,6 +26,6 @@ for (var j = 0; j < SIZE; j += 2)
|
||||
for (var i = 0; i < NITERS; i++) {
|
||||
var iter = iters[i];
|
||||
for (var j = 3; j < SIZE; j += 2)
|
||||
assertIteratorResult(iter.next(), j, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, j);
|
||||
assertIteratorDone(iter, undefined);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ var set = Set();
|
||||
for (var i = 0; i < 32; i++)
|
||||
set.add(i);
|
||||
var iter = set[std_iterator]();
|
||||
assertIteratorResult(iter.next(), 0, false);
|
||||
assertIteratorNext(iter, 0);
|
||||
for (var i = 0; i < 30; i++)
|
||||
set.delete(i);
|
||||
assertEq(set.size, 2);
|
||||
@ -16,5 +16,5 @@ for (var i = 32; i < 100; i++)
|
||||
set.add(i); // eventually triggers compaction
|
||||
|
||||
for (var i = 30; i < 100; i++)
|
||||
assertIteratorResult(iter.next(), i, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, i);
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
@ -7,11 +7,11 @@ var data = [1, 2, 3, 4];
|
||||
var s = Set(data);
|
||||
|
||||
var ki = s.keys();
|
||||
assertIteratorResult(ki.next(), 1, false);
|
||||
assertIteratorResult(ki.next(), 2, false);
|
||||
assertIteratorResult(ki.next(), 3, false);
|
||||
assertIteratorResult(ki.next(), 4, false);
|
||||
assertIteratorResult(ki.next(), undefined, true);
|
||||
assertIteratorNext(ki, 1);
|
||||
assertIteratorNext(ki, 2);
|
||||
assertIteratorNext(ki, 3);
|
||||
assertIteratorNext(ki, 4);
|
||||
assertIteratorDone(ki, undefined);
|
||||
|
||||
assertEq([...s.keys()].toSource(), data.toSource());
|
||||
assertEq([...s.values()].toSource(), data.toSource());
|
||||
|
@ -15,7 +15,7 @@ function test(constructor) {
|
||||
assertEq(desc.writable, true);
|
||||
|
||||
assertEq(proto[std_iterator](), proto);
|
||||
assertIteratorResult(proto.next(), undefined, true);
|
||||
assertIteratorDone(proto, undefined);
|
||||
}
|
||||
|
||||
//test(Array);
|
||||
|
@ -17,4 +17,4 @@ var rv = gw.evalInGlobal("it.next();");
|
||||
assertEq(rv.throw, "fit");
|
||||
|
||||
dbg.enabled = false;
|
||||
assertIteratorResult(g.it.next(), 1, false);
|
||||
assertIteratorNext(g.it, 1);
|
||||
|
@ -16,4 +16,4 @@ g.eval("var it = g();");
|
||||
assertEq(gw.evalInGlobal("it.next();"), null);
|
||||
|
||||
dbg.enabled = false;
|
||||
assertIteratorResult(g.it.next(), 1, false);
|
||||
assertIteratorNext(g.it, 1);
|
||||
|
@ -15,6 +15,6 @@ function* gen() {
|
||||
yield '2';
|
||||
}
|
||||
var iter = gen();
|
||||
assertIteratorResult(iter.next(), '1', false);
|
||||
assertIteratorNext(iter, '1');
|
||||
assertEq(iter.next(), '!');
|
||||
assertThrowsInstanceOf(iter.next.bind(iter), TypeError);
|
||||
|
@ -7,7 +7,7 @@ var arr = [0, 1, 2];
|
||||
var it = arr[std_iterator]();
|
||||
arr[0] = 1000;
|
||||
arr[2] = 2000;
|
||||
assertIteratorResult(it.next(), 1000, false);
|
||||
assertIteratorResult(it.next(), 1, false);
|
||||
assertIteratorResult(it.next(), 2000, false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, 1000);
|
||||
assertIteratorNext(it, 1);
|
||||
assertIteratorNext(it, 2000);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -7,8 +7,8 @@ load(libdir + "iteration.js");
|
||||
function test(obj) {
|
||||
var it = Array.prototype[std_iterator].call(obj);
|
||||
for (var i = 0; i < (obj.length >>> 0); i++)
|
||||
assertIteratorResult(it.next(), obj[i], false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, obj[i]);
|
||||
assertIteratorDone(it, undefined);
|
||||
}
|
||||
|
||||
test({length: 0});
|
||||
|
@ -5,10 +5,10 @@ load(libdir + "iteration.js");
|
||||
|
||||
var arr = [0, 1];
|
||||
var it = arr[std_iterator]();
|
||||
assertIteratorResult(it.next(), 0, false);
|
||||
assertIteratorResult(it.next(), 1, false);
|
||||
assertIteratorNext(it, 0);
|
||||
assertIteratorNext(it, 1);
|
||||
arr[2] = 2;
|
||||
arr.length = 4;
|
||||
assertIteratorResult(it.next(), 2, false);
|
||||
assertIteratorResult(it.next(), undefined, false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, 2);
|
||||
assertIteratorNext(it, undefined);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -16,9 +16,9 @@ var it = Array.prototype[std_iterator].call(Proxy.create({
|
||||
}
|
||||
}));
|
||||
|
||||
assertIteratorResult(it.next(), "0", false);
|
||||
assertIteratorNext(it, "0");
|
||||
s += ' ';
|
||||
assertIteratorResult(it.next(), "1", false);
|
||||
assertIteratorNext(it, "1");
|
||||
s += ' ';
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
assertEq(s, "L0 L1 L");
|
||||
|
@ -5,7 +5,7 @@ load(libdir + "iteration.js");
|
||||
|
||||
var arr = [0, 1, 2];
|
||||
var it = arr[std_iterator]();
|
||||
assertIteratorResult(it.next(), 0, false);
|
||||
assertIteratorResult(it.next(), 1, false);
|
||||
assertIteratorNext(it, 0);
|
||||
assertIteratorNext(it, 1);
|
||||
arr.length = 1;
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorDone(it, undefined);
|
||||
|
@ -9,7 +9,7 @@ var inner = g(20);
|
||||
var n = 0;
|
||||
for (var x of inner) {
|
||||
assertEq(x, n * 2);
|
||||
assertIteratorResult(inner.next(), n * 2 + 1, false);
|
||||
assertIteratorNext(inner, n * 2 + 1);
|
||||
n++;
|
||||
}
|
||||
assertEq(n, 10);
|
||||
|
@ -9,5 +9,5 @@ load(libdir + "iteration.js");
|
||||
|
||||
var g = newGlobal();
|
||||
g.eval("var it = [1, 2]['" + std_iterator + "']();");
|
||||
assertIteratorResult(g.it.next(), 1, false);
|
||||
assertIteratorNext(g.it, 1);
|
||||
assertThrowsInstanceOf([][std_iterator]().next.bind(g.it), TypeError)
|
||||
|
@ -6,8 +6,8 @@ load(libdir + "iteration.js");
|
||||
function test(obj) {
|
||||
var it = String.prototype[std_iterator].call(obj);
|
||||
for (var i = 0; i < (obj.length >>> 0); i++)
|
||||
assertIteratorResult(it.next(), obj[i], false);
|
||||
assertIteratorResult(it.next(), undefined, true);
|
||||
assertIteratorNext(it, obj[i]);
|
||||
assertIteratorDone(it, undefined);
|
||||
}
|
||||
|
||||
test({length: 0});
|
||||
|
@ -30,18 +30,18 @@ function IterableWrapper(iterable) {
|
||||
function* delegate(iter) { return yield* iter; }
|
||||
|
||||
var iter = delegate(IterableWrapper([1, 2, 3]));
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
||||
assertEq(log, 'innnn');
|
||||
|
||||
iter = delegate([1, 2, 3]);
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorDone(iter, undefined);
|
||||
|
||||
assertEq(log, 'innnn');
|
||||
|
||||
|
@ -9,14 +9,14 @@ var GeneratorObjectPrototype_throw = GeneratorObjectPrototype.throw;
|
||||
// An uncaught delegated throw.
|
||||
var inner = g1();
|
||||
var outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
assertThrowsValue(function () { outer.throw(42) }, 42);
|
||||
assertThrowsInstanceOf(function () { outer.throw(42) }, TypeError);
|
||||
|
||||
// A caught delegated throw.
|
||||
inner = g2();
|
||||
outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
assertIteratorResult(outer.throw(42), 42, false);
|
||||
assertThrowsValue(function () { outer.throw(42) }, 42);
|
||||
assertThrowsInstanceOf(function () { outer.throw(42) }, TypeError);
|
||||
@ -24,21 +24,21 @@ assertThrowsInstanceOf(function () { outer.throw(42) }, TypeError);
|
||||
// What would be an uncaught delegated throw, but with a monkeypatched iterator.
|
||||
inner = g1();
|
||||
outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
inner.throw = function(e) { return e*2; };
|
||||
assertEq(84, outer.throw(42));
|
||||
assertIteratorResult(outer.next(), undefined, true);
|
||||
assertIteratorDone(outer, undefined);
|
||||
|
||||
// Monkeypatching inner.next.
|
||||
inner = g1();
|
||||
outer = delegate(inner);
|
||||
inner.next = function() { return { value: 13, done: true } };
|
||||
assertIteratorResult(outer.next(), 13, true);
|
||||
assertIteratorDone(outer, 13);
|
||||
|
||||
// What would be a caught delegated throw, but with a monkeypunched prototype.
|
||||
inner = g2();
|
||||
outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
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(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
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(outer.next(), undefined, true);
|
||||
assertIteratorDone(outer, undefined);
|
||||
|
||||
// The same, but restoring the original pre-monkey throw.
|
||||
inner = g2();
|
||||
outer = delegate(inner);
|
||||
outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 1);
|
||||
assertEq(84, outer_throw_42());
|
||||
assertEq(84, outer_throw_42());
|
||||
GeneratorObjectPrototype.throw = GeneratorObjectPrototype_throw;
|
||||
assertIteratorResult(outer_throw_42(), 42, false);
|
||||
assertIteratorResult(outer.next(), undefined, true);
|
||||
assertIteratorDone(outer, undefined);
|
||||
|
||||
if (typeof reportCompare == "function")
|
||||
reportCompare(true, true);
|
||||
|
@ -8,8 +8,8 @@ var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next;
|
||||
// Monkeypatch next on an iterator.
|
||||
var inner = g(20);
|
||||
var outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 0, false);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 0);
|
||||
assertIteratorNext(outer, 1);
|
||||
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(outer.next(), 2, false);
|
||||
assertIteratorNext(outer, 2);
|
||||
// Repatch.
|
||||
inner.next = function() { return { value: 42, done: true }; };
|
||||
assertIteratorResult(outer.next(), 42, true);
|
||||
assertIteratorDone(outer, 42);
|
||||
|
||||
// Monkeypunch next on the prototype.
|
||||
var inner = g(20);
|
||||
var outer = delegate(inner);
|
||||
assertIteratorResult(outer.next(), 0, false);
|
||||
assertIteratorResult(outer.next(), 1, false);
|
||||
assertIteratorNext(outer, 0);
|
||||
assertIteratorNext(outer, 1);
|
||||
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(outer.next(), 2, false);
|
||||
assertIteratorNext(outer, 2);
|
||||
|
||||
if (typeof reportCompare == "function")
|
||||
reportCompare(true, true);
|
||||
|
@ -7,12 +7,12 @@ var inner = g(20);
|
||||
var outer1 = delegate(inner);
|
||||
var outer2 = delegate(inner);
|
||||
|
||||
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);
|
||||
assertIteratorNext(outer1, 0);
|
||||
assertIteratorNext(outer2, 1);
|
||||
assertIteratorNext(inner, 2);
|
||||
assertIteratorNext(outer1, 3);
|
||||
assertIteratorNext(outer2, 4);
|
||||
assertIteratorNext(inner, 5);
|
||||
|
||||
if (typeof reportCompare == "function")
|
||||
reportCompare(true, true);
|
||||
|
@ -12,10 +12,8 @@ var GeneratorFunction = (function*(){yield 1;}).constructor;
|
||||
function TestGeneratorResultPrototype() {
|
||||
function* g() { yield 1; }
|
||||
var iter = g();
|
||||
var result = iter.next();
|
||||
assertIteratorResult(result, 1, false);
|
||||
result = iter.next();
|
||||
assertIteratorResult(result, undefined, true);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next() }, TypeError);
|
||||
}
|
||||
TestGeneratorResultPrototype();
|
||||
@ -334,10 +332,10 @@ function TestTryCatch(instantiate) {
|
||||
function Sentinel() {}
|
||||
|
||||
function Test1(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test1(instantiate(g));
|
||||
@ -349,29 +347,29 @@ function TestTryCatch(instantiate) {
|
||||
Test2(instantiate(g));
|
||||
|
||||
function Test3(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test3(instantiate(g));
|
||||
|
||||
function Test4(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
assertIteratorResult(iter.throw(exn), exn, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorResult(iter.next(), undefined, true);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test4(instantiate(g));
|
||||
|
||||
function Test5(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
assertIteratorResult(iter.throw(exn), exn, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
|
||||
@ -379,8 +377,8 @@ function TestTryCatch(instantiate) {
|
||||
Test5(instantiate(g));
|
||||
|
||||
function Test6(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
assertIteratorResult(iter.throw(exn), exn, false);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
@ -397,11 +395,11 @@ function TestTryFinally(instantiate) {
|
||||
function Sentinel2() {}
|
||||
|
||||
function Test1(iter) {
|
||||
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);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorNext(iter, 4);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test1(instantiate(g));
|
||||
@ -413,15 +411,15 @@ function TestTryFinally(instantiate) {
|
||||
Test2(instantiate(g));
|
||||
|
||||
function Test3(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test3(instantiate(g));
|
||||
|
||||
function Test4(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorResult(iter.throw(new Sentinel), 3, false);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
@ -430,8 +428,8 @@ function TestTryFinally(instantiate) {
|
||||
Test4(instantiate(g));
|
||||
|
||||
function Test5(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorResult(iter.throw(new Sentinel), 3, false);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
@ -439,19 +437,19 @@ function TestTryFinally(instantiate) {
|
||||
Test5(instantiate(g));
|
||||
|
||||
function Test6(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test6(instantiate(g));
|
||||
|
||||
function Test7(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorResult(iter.next(), 4, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorNext(iter, 4);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
@ -475,12 +473,12 @@ function TestNestedTry(instantiate) {
|
||||
function Sentinel2() {}
|
||||
|
||||
function Test1(iter) {
|
||||
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);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorNext(iter, 4);
|
||||
assertIteratorNext(iter, 5);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
}
|
||||
Test1(instantiate(g));
|
||||
@ -492,7 +490,7 @@ function TestNestedTry(instantiate) {
|
||||
Test2(instantiate(g));
|
||||
|
||||
function Test3(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorResult(iter.throw(new Sentinel), 4, false);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
@ -500,7 +498,7 @@ function TestNestedTry(instantiate) {
|
||||
Test3(instantiate(g));
|
||||
|
||||
function Test4(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorResult(iter.throw(new Sentinel), 4, false);
|
||||
assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
@ -508,22 +506,22 @@ function TestNestedTry(instantiate) {
|
||||
Test4(instantiate(g));
|
||||
|
||||
function Test5(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
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);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorNext(iter, 4);
|
||||
assertIteratorNext(iter, 5);
|
||||
assertIteratorDone(iter, undefined);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
|
||||
}
|
||||
Test5(instantiate(g));
|
||||
|
||||
function Test6(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
assertIteratorResult(iter.throw(exn), exn, false);
|
||||
assertIteratorResult(iter.throw(new Sentinel2), 4, false);
|
||||
@ -533,11 +531,11 @@ function TestNestedTry(instantiate) {
|
||||
Test6(instantiate(g));
|
||||
|
||||
function Test7(iter) {
|
||||
assertIteratorResult(iter.next(), 1, false);
|
||||
assertIteratorResult(iter.next(), 2, false);
|
||||
assertIteratorNext(iter, 1);
|
||||
assertIteratorNext(iter, 2);
|
||||
var exn = new Sentinel;
|
||||
assertIteratorResult(iter.throw(exn), exn, false);
|
||||
assertIteratorResult(iter.next(), 3, false);
|
||||
assertIteratorNext(iter, 3);
|
||||
assertIteratorResult(iter.throw(new Sentinel2), 4, false);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2);
|
||||
assertThrowsInstanceOf(function() { iter.next(); }, TypeError);
|
||||
|
@ -20,3 +20,9 @@ function assertIteratorResult(result, value, done) {
|
||||
assertDeepEq(result.value, value);
|
||||
assertEq(result.done, done);
|
||||
}
|
||||
function assertIteratorNext(iter, value) {
|
||||
assertIteratorResult(iter.next(), value, false);
|
||||
}
|
||||
function assertIteratorDone(iter, value) {
|
||||
assertIteratorResult(iter.next(), value, true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user