Bug 1069416 - Part 3: Remove std_iterator from js tests. r=evilpie

This commit is contained in:
Tooru Fujisawa 2015-01-28 13:06:37 +09:00
parent c6ae19c92b
commit 65903b957a
99 changed files with 145 additions and 160 deletions

View File

@ -5,8 +5,6 @@
load(libdir + "asserts.js");
const std_iterator = Symbol.iterator;
if (typeof assertIteratorResult === 'undefined') {
var assertIteratorResult = function assertIteratorResult(result, value, done) {
assertEq(typeof result, "object");

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
function f([a]) a
var i = 0;
var o = {[std_iterator]: function () { i++; return {
var o = {[Symbol.iterator]: function () { i++; return {
next: function () { i++; return {value: 42, done: false}; }}}};
assertEq(f(o), 42);
assertEq(i, 2);

View File

@ -2,6 +2,6 @@
load(libdir + "iteration.js");
eval("var x; typeof x")
Array.prototype[std_iterator] = function () { for(y in x); };
Array.prototype[Symbol.iterator] = function () { for(y in x); };
for (var v of ['a', 'b', 'c', 'd'])
s = v;

View File

@ -9,7 +9,7 @@ assertThrowsInstanceOf(() => { [a, b, c] = {0: 0, 1: 1, 2: 2} }, TypeError);
var nextcalls = 0, donecalls = 0, valuecalls = 0;
var doneafter = 0;
var iterable = {};
iterable[std_iterator] = function () {
iterable[Symbol.iterator] = function () {
return {
next: function () {
assertEq(arguments.length, 0, 'iterator.next() should be called with no arguments');
@ -50,8 +50,8 @@ assertIterable([5,5,4,4],
[3,4]);
var arraycalls = 0;
var ArrayIterator = Array.prototype[std_iterator];
Array.prototype[std_iterator] = function () {
var ArrayIterator = Array.prototype[Symbol.iterator];
Array.prototype[Symbol.iterator] = function () {
arraycalls++;
return ArrayIterator.apply(this, arguments);
};
@ -72,14 +72,14 @@ loop(() => { doneafter = 4; var [a,b,...rest] = iterable; return rest; });
// destructuring assignment should always use iterators and not optimize
// to a "group assignment"
delete Array.prototype[std_iterator];
delete Array.prototype[Symbol.iterator];
assertThrowsInstanceOf(() => { var [a,b] = [1,2]; }, TypeError);
Array.prototype[std_iterator] = ArrayIterator;
Array.prototype[Symbol.iterator] = ArrayIterator;
// observe the binding order
a = undefined, b = undefined, c = undefined;
var obj = {};
obj[std_iterator] = function* () {
obj[Symbol.iterator] = function* () {
// normal fields should be initialized right after |.next()|
yield 1;
assertEq(a, 1);
@ -99,11 +99,11 @@ assertEqArray(c, [4,5]);
assertThrowsValue(function () {
try {
Array.prototype[std_iterator] = function () { throw 'from iterator'; };
Array.prototype[Symbol.iterator] = function () { throw 'from iterator'; };
throw [1, 2];
} catch ([x, y]) {
throw 'not reached';
}
}, 'from iterator');
Array.prototype[std_iterator] = ArrayIterator;
Array.prototype[Symbol.iterator] = ArrayIterator;

View File

@ -18,11 +18,11 @@ assertEqArray([...[undefined]], [undefined]);
// other iterable objects
assertEqArray([...new Int32Array([1, 2, 3])], [1, 2, 3]);
assertEqArray([..."abc"], ["a", "b", "c"]);
assertEqArray([...[1, 2, 3][std_iterator]()], [1, 2, 3]);
assertEqArray([...[1, 2, 3][Symbol.iterator]()], [1, 2, 3]);
assertEqArray([...Set([1, 2, 3])], [1, 2, 3]);
assertEqArray([...Map([["a", "A"], ["b", "B"], ["c", "C"]])].map(([k, v]) => k + v), ["aA", "bB", "cC"]);
let itr = {};
itr[std_iterator] = function () {
itr[Symbol.iterator] = function () {
return {
i: 1,
next: function() {

View File

@ -24,10 +24,10 @@ try { // line0 + 1
}
// other iterable objects
assertEq(eval(...["a + b"][std_iterator]()), 11);
assertEq(eval(...["a + b"][Symbol.iterator]()), 11);
assertEq(eval(...Set(["a + b"])), 11);
let itr = {};
itr[std_iterator] = function() {
itr[Symbol.iterator] = function() {
return {
i: 0,
next: function() {

View File

@ -10,9 +10,9 @@ function checkCommon(f) {
// other iterable objects
assertEqArray(f.apply(...Set([null, [1, 2, 3]])), [1, 2, 3]);
assertEqArray(f.apply(...[null, [1, 2, 3]][std_iterator]()), [1, 2, 3]);
assertEqArray(f.apply(...[null, [1, 2, 3]][Symbol.iterator]()), [1, 2, 3]);
let itr = {};
itr[std_iterator] = function() {
itr[Symbol.iterator] = function() {
return {
i: 0,
next: function() {

View File

@ -21,11 +21,11 @@ function checkLength(f, makeFn) {
// other iterable objects
assertEq(makeFn("...arg")(f, new Int32Array([1, 2, 3])), 3);
assertEq(makeFn("...arg")(f, "abc"), 3);
assertEq(makeFn("...arg")(f, [1, 2, 3][std_iterator]()), 3);
assertEq(makeFn("...arg")(f, [1, 2, 3][Symbol.iterator]()), 3);
assertEq(makeFn("...arg")(f, Set([1, 2, 3])), 3);
assertEq(makeFn("...arg")(f, Map([["a", "A"], ["b", "B"], ["c", "C"]])), 3);
let itr = {};
itr[std_iterator] = function() {
itr[Symbol.iterator] = function() {
return {
i: 1,
next: function() {

View File

@ -11,16 +11,16 @@ assertThrowsInstanceOf(() => Math.sin(...1), TypeError);
assertThrowsInstanceOf(() => Math.sin(...{}), TypeError);
var foo = {}
foo[std_iterator] = 10;
foo[Symbol.iterator] = 10;
assertThrowsInstanceOf(() => Math.sin(...foo), TypeError);
foo[std_iterator] = function() undefined;
foo[Symbol.iterator] = function() undefined;
assertThrowsInstanceOf(() => Math.sin(...foo), TypeError);
foo[std_iterator] = function() this;
foo[Symbol.iterator] = function() this;
assertThrowsInstanceOf(() => Math.sin(...foo), TypeError);
foo[std_iterator] = function() this;
foo[Symbol.iterator] = function() this;
foo.next = function() { throw 10; };
assertThrowsValue(() => Math.sin(...foo), 10);

View File

@ -16,11 +16,11 @@ function checkCommon(f, makeFn) {
// other iterable objects
assertEqArray(makeFn("...arg")(f, new Int32Array([1, 2, 3])), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, "abc"), ["a", "b", "c"]);
assertEqArray(makeFn("...arg")(f, [1, 2, 3][std_iterator]()), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, [1, 2, 3][Symbol.iterator]()), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, Set([1, 2, 3])), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, Map([["a", "A"], ["b", "B"], ["c", "C"]])).map(([k, v]) => k + v), ["aA", "bB", "cC"]);
let itr = {};
itr[std_iterator] = function() {
itr[Symbol.iterator] = function() {
return {
i: 1,
next: function() {

View File

@ -3,12 +3,12 @@
load(libdir + "iteration.js");
var m = Map();
var it = m[std_iterator]();
var it = m[Symbol.iterator]();
m.clear();
assertIteratorDone(it, undefined);
m = Map([["a", 1], ["b", 2], ["c", 3], ["d", 4]]);
it = m[std_iterator]();
it = m[Symbol.iterator]();
assertIteratorNext(it, ["a", 1]);
m.clear();
assertIteratorDone(it, undefined);

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var m = Map([["a", 1]]);
var it = m[std_iterator]();
var it = m[Symbol.iterator]();
assertIteratorNext(it, ["a", 1]);
m.clear();
m.set("b", 2);

View File

@ -106,7 +106,7 @@ function test_change1() {
var proxy_arr = new Proxy(arr, {
get: function(target, name) {
if (name == std_iterator) {
if (name == Symbol.iterator) {
modified = true;
Map.prototype.set = function() {
called = true;

View File

@ -17,7 +17,7 @@ var initialMap = new Map([['a', 1], ['b', 2.3], [false, undefined]]);
initialMap.forEach(callback);
// test that both the Maps are equal and are in same order
var iterator = initialMap[std_iterator]();
var iterator = initialMap[Symbol.iterator]();
var count = 0;
for (var [k, v] of testMap) {
assertEq(initialMap.has(k), true);
@ -53,7 +53,7 @@ assertThrowsInstanceOf(function() {
// StopIteration exception is thrown
var m = new Map([["one", 1]]);
Object.getPrototypeOf(m[std_iterator]()).next = function () { throw "FAIL"; };
Object.getPrototypeOf(m[Symbol.iterator]()).next = function () { throw "FAIL"; };
assertThrowsInstanceOf(function () {
m.forEach(function () { throw StopIteration; });
}, StopIteration, "Map.prototype.forEach should use intrinsic next method.");

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var map = Map();
var iter0 = map[std_iterator](), iter1 = map[std_iterator]();
var iter0 = map[Symbol.iterator](), iter1 = map[Symbol.iterator]();
assertIteratorDone(iter0, undefined); // closes iter0
map.set(1, 2);
assertIteratorDone(iter0, undefined); // already closed

View File

@ -4,7 +4,7 @@ load(libdir + "iteration.js");
var key = {};
var map = Map([[key, 'value']]);
var entry = map[std_iterator]().next().value;
var entry = map[Symbol.iterator]().next().value;
assertEq(Array.isArray(entry), true);
assertEq(Object.getPrototypeOf(entry), Array.prototype);
assertEq(Object.isExtensible(entry), true);

View File

@ -3,11 +3,11 @@
load(libdir + "iteration.js");
var map = Map([['a', 1], ['b', 2]]);
var iter = map[std_iterator]();
var iter = map[Symbol.iterator]();
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]();
var a1 = map[Symbol.iterator]();
assertIteratorNext(a1, ['a', 1]);
assertEq(a.value !== a1.value, true);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var map = Map([['a', 1]]);
var res = map[std_iterator]().next();
var res = map[Symbol.iterator]().next();
assertIteratorResult(res, ['a', 1], false);
res.value[0] = 'b';
res.value[1] = 2;

View File

@ -6,16 +6,16 @@ load(libdir + "iteration.js");
var g = newGlobal();
var iterator_fn = Map.prototype[std_iterator];
var iterator_fn = Map.prototype[Symbol.iterator];
assertThrowsInstanceOf(function () { iterator_fn.call({}); }, TypeError);
assertThrowsInstanceOf(function () { iterator_fn.call(Set()); }, TypeError);
var mapw = g.eval("Map([['x', 1], ['y', 2]])");
assertEqArray(iterator_fn.call(mapw).next().value, ["x", 1]);
var next_fn = Map()[std_iterator]().next;
var next_fn = Map()[Symbol.iterator]().next;
assertThrowsInstanceOf(function () { next_fn.call({}); }, TypeError);
assertThrowsInstanceOf(function () { next_fn.call(Set()[std_iterator]()); }, TypeError);
var iterw = mapw[std_iterator]();
assertThrowsInstanceOf(function () { next_fn.call(Set()[Symbol.iterator]()); }, TypeError);
var iterw = mapw[Symbol.iterator]();
assertEqArray(next_fn.call(iterw).value, ["x", 1]);
assertEqArray(next_fn.call(iterw).value, ["y", 2]);
assertEq(next_fn.call(iterw).done, true);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var map = Map([['a', 0], ['b', 1], ['c', 2], ['d', 3]]);
var iter = map[std_iterator]();
var iter = map[Symbol.iterator]();
var log = '';
for (let [k, v] of iter) {
log += k + v;

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var map = Map([['a', 0], ['b', 1], ['c', 2], ['d', 3]]);
var iter = map[std_iterator]();
var iter = map[Symbol.iterator]();
assertIteratorNext(iter, ['a', 0]);
assertIteratorNext(iter, ['b', 1]);
map.delete('c');

View File

@ -12,7 +12,7 @@ for (var j = 0; j < SIZE; j++)
var NITERS = 5;
var iters = [];
for (var i = 0; i < NITERS; i++) {
var iter = map[std_iterator]();
var iter = map[Symbol.iterator]();
assertIteratorNext(iter, [0, 0]);
assertIteratorNext(iter, [1, 1]);
iters[i] = iter;

View File

@ -7,7 +7,7 @@ load(libdir + "iteration.js");
var map = Map();
for (var i = 0; i < 32; i++)
map.set(i, i);
var iter = map[std_iterator]();
var iter = map[Symbol.iterator]();
assertIteratorNext(iter, [0, 0]);
for (var i = 0; i < 30; i++)
map.delete(i);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var m = Map();
var it = m[std_iterator]();
var it = m[Symbol.iterator]();
assertIteratorDone(it, undefined); // close the iterator
m.clear();
m.set("a", 1);

View File

@ -46,4 +46,4 @@ assertEq(desc.set, undefined);
checkMethod("clear", 0);
// Map.prototype[@@iterator] and .entries are the same function object.
assertEq(Map.prototype[std_iterator], Map.prototype.entries);
assertEq(Map.prototype[Symbol.iterator], Map.prototype.entries);

View File

@ -3,12 +3,12 @@
load(libdir + "iteration.js");
var s = Set();
var it = s[std_iterator]();
var it = s[Symbol.iterator]();
s.clear();
assertIteratorDone(it, undefined);
s = Set(["a", "b", "c", "d"]);
it = s[std_iterator]();
it = s[Symbol.iterator]();
assertIteratorNext(it, "a");
s.clear();
assertIteratorDone(it, undefined);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var s = Set(["a"]);
var it = s[std_iterator]();
var it = s[Symbol.iterator]();
assertIteratorNext(it, "a");
s.clear();
s.add("b");

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var s = Set();
var it = s[std_iterator]();
var it = s[Symbol.iterator]();
assertIteratorDone(it, undefined); // close the iterator
s.clear();
s.add("a");

View File

@ -93,7 +93,7 @@ function test_change1() {
var proxy_arr = new Proxy(arr, {
get: function(target, name) {
if (name == std_iterator) {
if (name == Symbol.iterator) {
modified = true;
Set.prototype.add = function() {
called = true;

View File

@ -17,7 +17,7 @@ var initialSet = new Set(['a', 1, undefined]);
initialSet.forEach(callback);
// test that both the Sets are equal and are in same order
var iterator = initialSet[std_iterator]();
var iterator = initialSet[Symbol.iterator]();
var count = 0;
for (var v of testSet) {
assertEq(initialSet.has(v), true);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var set = Set();
var iter0 = set[std_iterator](), iter1 = set[std_iterator]();
var iter0 = set[Symbol.iterator](), iter1 = set[Symbol.iterator]();
assertIteratorDone(iter0, undefined); // closes iter0
set.add("x");
assertIteratorDone(iter0, undefined); // already closed

View File

@ -5,6 +5,6 @@ load(libdir + "iteration.js");
var key = {};
var set = Set([key]);
var iter = set[std_iterator]();
var iter = set[Symbol.iterator]();
referencesVia(iter, "**UNKNOWN SLOT 0**", set);
referencesVia(set, "key", key);

View File

@ -5,16 +5,16 @@ load(libdir + "iteration.js");
var g = newGlobal();
var iterator_fn = Set.prototype[std_iterator];
var iterator_fn = Set.prototype[Symbol.iterator];
assertThrowsInstanceOf(function () { iterator_fn.call({}); }, TypeError);
assertThrowsInstanceOf(function () { iterator_fn.call(Map()); }, TypeError);
var setw = g.eval("Set(['x', 'y'])");
assertIteratorNext(iterator_fn.call(setw), "x");
var next_fn = Set()[std_iterator]().next;
var next_fn = Set()[Symbol.iterator]().next;
assertThrowsInstanceOf(function () { next_fn.call({}); }, TypeError);
assertThrowsInstanceOf(function () { next_fn.call(Map()[std_iterator]()); }, TypeError);
var iterw = setw[std_iterator]();
assertThrowsInstanceOf(function () { next_fn.call(Map()[Symbol.iterator]()); }, TypeError);
var iterw = setw[Symbol.iterator]();
assertIteratorResult(next_fn.call(iterw), "x", false);
assertIteratorResult(next_fn.call(iterw), "y", false);
assertIteratorResult(next_fn.call(iterw), undefined, true);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var set = Set("abcd");
var iter = set[std_iterator]();
var iter = set[Symbol.iterator]();
var log = "";
for (let x of iter) {
log += x;

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
var set = Set("abcd");
var iter = set[std_iterator]();
var iter = set[Symbol.iterator]();
assertIteratorNext(iter, "a");
assertIteratorNext(iter, "b");
set.delete("c");

View File

@ -12,7 +12,7 @@ for (var j = 0; j < SIZE; j++)
var NITERS = 5;
var iters = [];
for (var i = 0; i < NITERS; i++) {
var iter = set[std_iterator]();
var iter = set[Symbol.iterator]();
assertIteratorNext(iter, 0);
assertIteratorNext(iter, 1);
iters[i] = iter;

View File

@ -7,7 +7,7 @@ load(libdir + "iteration.js");
var set = Set();
for (var i = 0; i < 32; i++)
set.add(i);
var iter = set[std_iterator]();
var iter = set[Symbol.iterator]();
assertIteratorNext(iter, 0);
for (var i = 0; i < 30; i++)
set.delete(i);

View File

@ -45,4 +45,4 @@ checkMethod("clear", 0);
// Set.prototype.keys, .values, and .iterator are the same function object
assertEq(Set.prototype.keys, Set.prototype.values);
assertEq(Set.prototype[std_iterator], Set.prototype.values);
assertEq(Set.prototype[Symbol.iterator], Set.prototype.values);

View File

@ -11,7 +11,7 @@ var k3 = {};
var done = false;
var iterable = {};
iterable[std_iterator] = function*() {
iterable[Symbol.iterator] = function*() {
yield [k1, v1];
yield [k2, v2];
done = true;

View File

@ -4,10 +4,10 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var non_iterable1 = {};
non_iterable1[std_iterator] = {};
non_iterable1[Symbol.iterator] = {};
assertThrowsInstanceOf(() => new WeakMap(non_iterable1), TypeError);
var non_iterable2 = {};
non_iterable2[std_iterator] = function() {
non_iterable2[Symbol.iterator] = function() {
};
assertThrowsInstanceOf(() => new WeakMap(non_iterable2), TypeError);

View File

@ -103,7 +103,7 @@ function test_change1() {
var proxy_arr = new Proxy(arr, {
get: function(target, name) {
if (name == std_iterator) {
if (name == Symbol.iterator) {
modified = true;
WeakMap.prototype.set = function() {
called = true;

View File

@ -90,7 +90,7 @@ function test_change1() {
var proxy_arr = new Proxy(arr, {
get: function(target, name) {
if (name == std_iterator) {
if (name == Symbol.iterator) {
modified = true;
WeakSet.prototype.add = function() {
called = true;

View File

@ -16,7 +16,7 @@ testMethod("delete");
testMethod("clear");
assertThrowsInstanceOf(function() { var ws = new WeakSet(); ws.add(1); }, TypeError);
assertThrowsInstanceOf(function() { new WeakSet({[std_iterator]: 2}) }, TypeError);
assertEq(typeof [][std_iterator], "function");
assertThrowsInstanceOf(function() { new WeakSet({[Symbol.iterator]: 2}) }, TypeError);
assertEq(typeof [][Symbol.iterator], "function");
assertThrowsInstanceOf(function() { WeakSet(); }, TypeError);

View File

@ -3,7 +3,7 @@
load(libdir + "iteration.js");
function test(obj, name) {
var iter = obj[std_iterator]();
var iter = obj[Symbol.iterator]();
assertEq(typeof iter, "object");
assertEq(iter instanceof Iterator, true);
assertEq(iter.toString(), "[object " + obj.constructor.name + " Iterator]");

View File

@ -6,7 +6,7 @@ load(libdir + "referencesVia.js");
var key = {};
function test(obj, edgeName) {
var iter = obj[std_iterator]();
var iter = obj[Symbol.iterator]();
referencesVia(iter, "**UNKNOWN SLOT 0**", obj);
referencesVia(obj, edgeName, key);
}

View File

@ -4,7 +4,7 @@
load(libdir + "iteration.js");
function test(obj0, obj1) {
var iter0 = obj0[std_iterator](), iter1 = obj1[std_iterator]();
var iter0 = obj0[Symbol.iterator](), iter1 = obj1[Symbol.iterator]();
var proto = Object.getPrototypeOf(iter0);
assertEq(Object.getPrototypeOf(iter1), proto);
assertEq(Object.getPrototypeOf(proto), Iterator.prototype);

View File

@ -2,9 +2,9 @@
load(libdir + "iteration.js");
var aproto = Object.getPrototypeOf(Array()[std_iterator]());
var mproto = Object.getPrototypeOf(Map()[std_iterator]());
var sproto = Object.getPrototypeOf(Set()[std_iterator]());
var aproto = Object.getPrototypeOf(Array()[Symbol.iterator]());
var mproto = Object.getPrototypeOf(Map()[Symbol.iterator]());
var sproto = Object.getPrototypeOf(Set()[Symbol.iterator]());
assertEq(aproto !== mproto, true);
assertEq(aproto !== sproto, true);
assertEq(mproto !== sproto, true);

View File

@ -4,18 +4,18 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
function test(constructor) {
var proto = Object.getPrototypeOf(constructor()[std_iterator]());
var proto = Object.getPrototypeOf(constructor()[Symbol.iterator]());
var names = Object.getOwnPropertyNames(proto);
names.sort();
assertDeepEq(names, ['next']);
assertEq(proto.hasOwnProperty(std_iterator), true);
assertEq(proto.hasOwnProperty(Symbol.iterator), true);
var desc = Object.getOwnPropertyDescriptor(proto, 'next');
assertEq(desc.configurable, true);
assertEq(desc.enumerable, false);
assertEq(desc.writable, true);
assertEq(proto[std_iterator](), proto);
assertEq(proto[Symbol.iterator](), proto);
assertIteratorDone(proto, undefined);
}

View File

@ -4,7 +4,7 @@ load(libdir + "iteration.js");
// Arguments objects do not have a .@@iterator() method by default.
// Install one on Object.prototype.
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function test() {

View File

@ -8,7 +8,7 @@ function f() {
var s = '';
var args = f('a', 'b', 'c');
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
for (var v of args)
s += v;
assertEq(s, 'abc');

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function test() {

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function g(obj) {

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function g(obj) {

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function f() {

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
var s;
function f() {

View File

@ -6,7 +6,7 @@ var m = {1: 'peek'};
var a = [0, , 2, 3];
a.__proto__ = m;
var log = [];
Object.prototype[std_iterator] = Array.prototype[std_iterator];
Object.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
for (var x of a)
log.push(x);
assertEq(log[1], 'peek');

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var arr = [0, 1, 2];
var it = arr[std_iterator]();
var it = arr[Symbol.iterator]();
arr[0] = 1000;
arr[2] = 2000;
assertIteratorNext(it, 1000);

View File

@ -4,7 +4,7 @@ load(libdir + "referencesVia.js");
load(libdir + "iteration.js");
function test(obj) {
var it = Array.prototype[std_iterator].call(obj);
var it = Array.prototype[Symbol.iterator].call(obj);
assertEq(referencesVia(it, "**UNKNOWN SLOT 0**", obj), true);
}

View File

@ -5,7 +5,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
function test(obj) {
var it = Array.prototype[std_iterator].call(obj);
var it = Array.prototype[Symbol.iterator].call(obj);
var ki = Array.prototype.keys.call(obj);
var ei = Array.prototype.entries.call(obj);
for (var i = 0; i < (obj.length >>> 0); i++) {

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var arr = [0, 1];
var it = arr[std_iterator]();
var it = arr[Symbol.iterator]();
var ki = arr.keys();
var ei = arr.entries();
assertIteratorNext(it, 0);

View File

@ -5,7 +5,7 @@ load(libdir + "iteration.js");
for (var v of [undefined, null]) {
// ES6 draft 2013-09-05 section 22.1.5.1.
assertThrowsInstanceOf(function () { Array.prototype[std_iterator].call(v); }, TypeError);
assertThrowsInstanceOf(function () { Array.prototype[Symbol.iterator].call(v); }, TypeError);
assertThrowsInstanceOf(function () { Array.prototype.keys.call(v); }, TypeError);
assertThrowsInstanceOf(function () { Array.prototype.entries.call(v); }, TypeError);
}

View File

@ -17,7 +17,7 @@ var proxyObj = {
}
};
var it = Array.prototype[std_iterator].call(Proxy.create(proxyObj));
var it = Array.prototype[Symbol.iterator].call(Proxy.create(proxyObj));
assertIteratorNext(it, "0");
s += ' ';

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var arr = [0, 1, 2];
var it = arr[std_iterator]();
var it = arr[Symbol.iterator]();
var ki = arr.keys();
var ei = arr.entries();

View File

@ -4,13 +4,13 @@ load(libdir + "iteration.js");
var constructors = [Array, String, Uint8Array, Uint8ClampedArray];
for (var c of constructors) {
assertEq(c.prototype[std_iterator].length, 0);
assertEq(c.prototype[Symbol.iterator].length, 0);
var loc = (c === Array || c === String)
? c.prototype
: Object.getPrototypeOf(c.prototype);
var desc = Object.getOwnPropertyDescriptor(loc, std_iterator);
var desc = Object.getOwnPropertyDescriptor(loc, Symbol.iterator);
assertEq(desc.configurable, true);
assertEq(desc.enumerable, false);
assertEq(desc.writable, true);

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
var proto = Object.getPrototypeOf([][std_iterator]());
var proto = Object.getPrototypeOf([][Symbol.iterator]());
assertEq(Object.getPrototypeOf(proto), Iterator.prototype);
proto = Object.getPrototypeOf([].keys());
assertEq(Object.getPrototypeOf(proto), Iterator.prototype);
@ -13,7 +13,7 @@ function check(it) {
assertEq(typeof it, 'object');
assertEq(Object.getPrototypeOf(it), proto);
assertEq(Object.getOwnPropertyNames(it).length, 0);
assertEq(it[std_iterator](), it);
assertEq(it[Symbol.iterator](), it);
// for-in enumerates the iterator's properties.
it.x = 0;
@ -23,8 +23,8 @@ function check(it) {
assertEq(s, 'x.');
}
check([][std_iterator]());
check(Array.prototype[std_iterator].call({}));
check([][Symbol.iterator]());
check(Array.prototype[Symbol.iterator].call({}));
check([].keys());
check(Array.prototype.keys.call({}));
check([].entries());

View File

@ -3,6 +3,6 @@
load(libdir + "asserts.js");
load(libdir + "iteration.js");
var it = [1, 2][std_iterator]();
var it = [1, 2][Symbol.iterator]();
var v = Object.create(it);
assertThrowsInstanceOf(function () { Iterator.prototype.next.call(v); }, TypeError);

View File

@ -5,6 +5,6 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var g = newGlobal();
g.eval(`var it = [1, 2][${uneval(std_iterator)}]();`);
g.eval(`var it = [1, 2][Symbol.iterator]();`);
assertIteratorNext(g.it, 1);
assertDeepEq([][std_iterator]().next.call(g.it), { value: 2, done: false })
assertDeepEq([][Symbol.iterator]().next.call(g.it), { value: 2, done: false })

View File

@ -12,7 +12,7 @@ function Iter() {
return { get value() { throw 42; }, done: true }
}
this[std_iterator] = function () { return this; }
this[Symbol.iterator] = function () { return this; }
this.next = next;
}

View File

@ -5,7 +5,7 @@ load(libdir + "iteration.js");
var p = Proxy.create({
getPropertyDescriptor: function (name) {
if (name == std_iterator)
if (name == Symbol.iterator)
throw "fit";
return undefined;
}

View File

@ -9,5 +9,5 @@
load(libdir + "asserts.js");
load(libdir + "iteration.js");
delete Array.prototype[std_iterator];
delete Array.prototype[Symbol.iterator];
assertThrowsInstanceOf(function () { for (var x of []) ; }, TypeError);

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
function test(v) {
Array.prototype[std_iterator] = v;
Array.prototype[Symbol.iterator] = v;
assertThrowsInstanceOf(function () { for (var x of []) ; }, TypeError);
}
test(undefined);

View File

@ -2,7 +2,7 @@
load(libdir + "iteration.js");
Array.prototype[std_iterator] = function* () {
Array.prototype[Symbol.iterator] = function* () {
for (var i = this.length; --i >= 0; )
yield this[i];
};

View File

@ -4,7 +4,7 @@ load(libdir + "asserts.js");
load(libdir + "iteration.js");
var a = [];
a[std_iterator] = function* () {
a[Symbol.iterator] = function* () {
yield 'o';
yield 'k';
};
@ -13,5 +13,5 @@ for (var v of a)
s += v;
assertEq(s, 'ok');
a[std_iterator] = undefined;
a[Symbol.iterator] = undefined;
assertThrowsInstanceOf(function () { for (var v of a) ; }, TypeError);

View File

@ -3,6 +3,6 @@
load(libdir + "asserts.js");
load(libdir + "iteration.js");
delete String.prototype[std_iterator];
delete String.prototype[Symbol.iterator];
assertThrowsInstanceOf(function () { for (var v of "abc") ; }, TypeError);
assertThrowsInstanceOf(function () { for (var v of new String("abc")) ; }, TypeError);

View File

@ -3,6 +3,6 @@
load(libdir + "asserts.js");
load(libdir + "iteration.js");
var iterProto = Object.getPrototypeOf([][std_iterator]());
var iterProto = Object.getPrototypeOf([][Symbol.iterator]());
delete iterProto.next;
assertThrowsInstanceOf(function () { for (var v of []) ; }, TypeError);

View File

@ -4,7 +4,7 @@
load(libdir + "asserts.js");
load(libdir + "iteration.js");
var iterProto = Object.getPrototypeOf([][std_iterator]());
var iterProto = Object.getPrototypeOf([][Symbol.iterator]());
var s = '';
assertThrowsInstanceOf(function () {
for (var v of ['duck', 'duck', 'duck', 'goose', 'FAIL']) {

View File

@ -5,7 +5,7 @@ load(libdir + "iteration.js");
var g = newGlobal();
g.eval(`
var obj = {};
obj[${uneval(std_iterator)}] = function () { return this; };
obj[Symbol.iterator] = function () { return this; };
obj.next = function () { return { done: true }; };
`);
for (x of g.obj)

View File

@ -31,7 +31,7 @@ var iterator_fn = Proxy.createFunction({}, function () {
var obj = Proxy.create({
get: function (receiver, name) {
assertEq(name, std_iterator);
assertEq(name, Symbol.iterator);
s += "I";
return iterator_fn;
}

View File

@ -5,7 +5,7 @@ load(libdir + "iteration.js");
load(libdir + "string.js");
function test(obj) {
var it = String.prototype[std_iterator].call(obj);
var it = String.prototype[Symbol.iterator].call(obj);
var s = String(obj);
for (var i = 0, length = s.length; i < length;) {
var r = s[i++];

View File

@ -47,10 +47,10 @@ function assertBuiltinFunction(o, name, arity) {
// String.prototype[@@iterator] is a built-in function
assertBuiltinFunction(String.prototype, std_iterator, 0);
assertBuiltinFunction(String.prototype, Symbol.iterator, 0);
// Test StringIterator.prototype surface
var iter = ""[std_iterator]();
var iter = ""[Symbol.iterator]();
var iterProto = Object.getPrototypeOf(iter);
// StringIterator.prototype inherits from Object.prototype
@ -58,17 +58,17 @@ assertEq(Object.getPrototypeOf(iterProto), Object.prototype);
// Own properties for StringIterator.prototype: "next"
arraysEqual(Object.getOwnPropertyNames(iterProto).sort(), ["next"]);
assertEq(iterProto.hasOwnProperty(std_iterator), true);
assertEq(iterProto.hasOwnProperty(Symbol.iterator), true);
// StringIterator.prototype[@@iterator] is a built-in function
assertBuiltinFunction(iterProto, std_iterator, 0);
assertBuiltinFunction(iterProto, Symbol.iterator, 0);
// StringIterator.prototype.next is a built-in function
assertBuiltinFunction(iterProto, "next", 0);
// StringIterator.prototype[@@iterator] is generic and returns |this|
for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iter, iterProto]) {
assertEq(iterProto[std_iterator].call(v), v);
assertEq(iterProto[Symbol.iterator].call(v), v);
}
// StringIterator.prototype.next is not generic

View File

@ -13,7 +13,7 @@ function Iter(val, count) {
}
}
this[std_iterator] = function() { return this; };
this[Symbol.iterator] = function() { return this; };
this.next = next;
}

View File

@ -4,7 +4,7 @@ load(libdir + "iteration.js");
function iterable() {
var iterable = {};
iterable[std_iterator] = () => ({next: () => void 0});
iterable[Symbol.iterator] = () => ({next: () => void 0});
return iterable;
}

View File

@ -25,7 +25,7 @@ function TestChangeArrayIteratorNext() {
return M2;
}
var iter = ([])[std_iterator]();
var iter = ([])[Symbol.iterator]();
var iterProto = Object.getPrototypeOf(iter);
var OldNext = iterProto.next;
var NewNext = function () {

View File

@ -27,7 +27,7 @@ function TestIncreaseArrayLength() {
return M2;
}
var iter = ([])[std_iterator]();
var iter = ([])[Symbol.iterator]();
var iterProto = Object.getPrototypeOf(iter);
var OldNext = iterProto.next;
var NewNext = function () {

View File

@ -26,7 +26,7 @@ function TestDecreaseArrayLength() {
return M2;
}
var iter = ([])[std_iterator]();
var iter = ([])[Symbol.iterator]();
var iterProto = Object.getPrototypeOf(iter);
var OldNext = iterProto.next;
var NewNext = function () {

View File

@ -141,7 +141,7 @@ assertDeepEq(Array.from({[Symbol.iterator]: undefined}), []);
for (var primitive of [undefined, null, 17]) {
assertThrowsInstanceOf(
() => Array.from({
[std_iterator]() {
[Symbol.iterator]() {
return {next() { return primitive; }};
}
}),

View File

@ -8,7 +8,7 @@
// If an object has both .length and [@@iterator] properties, [@@iterator] is used.
var a = ['a', 'e', 'i', 'o', 'u'];
a[std_iterator] = function* () {
a[Symbol.iterator] = function* () {
for (var i = 5; i--; )
yield this[i];
};

View File

@ -36,7 +36,7 @@ assertDeepEq(log, ["define", "0", "define", "1", "define", "2", "set", "length"]
// calls handler.get on it.
log = [];
assertDeepEq(Array.from(new LoggingProxy([3, 4, 5])), [3, 4, 5]);
assertDeepEq(log, ["get", std_iterator,
assertDeepEq(log, ["get", Symbol.iterator,
"get", "length", "get", "0",
"get", "length", "get", "1",
"get", "length", "get", "2",
@ -45,9 +45,9 @@ assertDeepEq(log, ["get", std_iterator,
// Array-like iteration only gets the length once.
log = [];
var arr = [5, 6, 7];
arr[std_iterator] = undefined;
arr[Symbol.iterator] = undefined;
assertDeepEq(Array.from(new LoggingProxy(arr)), [5, 6, 7]);
assertDeepEq(log, ["get", std_iterator,
assertDeepEq(log, ["get", Symbol.iterator,
"get", "length", "get", "0", "get", "1", "get", "2"]);
if (typeof reportCompare === 'function')

View File

@ -11,11 +11,11 @@ assertDeepEq(Array.from(gclef), [gclef]);
assertDeepEq(Array.from(gclef + " G"), [gclef, " ", "G"]);
// Array.from on a string calls the @@iterator method.
String.prototype[std_iterator] = function* () { yield 1; yield 2; };
String.prototype[Symbol.iterator] = function* () { yield 1; yield 2; };
assertDeepEq(Array.from("anything"), [1, 2]);
// If the iterator method is deleted, Strings are still arraylike.
delete String.prototype[std_iterator];
delete String.prototype[Symbol.iterator];
assertDeepEq(Array.from("works"), ['w', 'o', 'r', 'k', 's']);
assertDeepEq(Array.from(gclef), ['\uD834', '\uDD1E']);

View File

@ -12,7 +12,7 @@ function results(results) {
}
var iter = { next: next }
var ret = {};
ret[std_iterator] = function () { return iter; }
ret[Symbol.iterator] = function () { return iter; }
return ret;
}
@ -23,7 +23,7 @@ function* yield_results(expected) {
function collect_results(iterable) {
var ret = [];
var result;
var iter = iterable[std_iterator]();
var iter = iterable[Symbol.iterator]();
do {
result = iter.next();
ret.push(result);

View File

@ -8,7 +8,7 @@ function Iter() {
}
this.next = next;
this[std_iterator] = function () { return this; }
this[Symbol.iterator] = function () { return this; }
}
function* delegate(iter) { return yield* iter; }

View File

@ -19,9 +19,9 @@ function IteratorWrapper(iterator) {
function IterableWrapper(iterable) {
var ret = {};
ret[std_iterator] = function () {
ret[Symbol.iterator] = function () {
log += 'i';
return IteratorWrapper(iterable[std_iterator]());
return IteratorWrapper(iterable[Symbol.iterator]());
}
return ret;

View File

@ -8,7 +8,7 @@ function results(results) {
}
var iter = { next: next };
var ret = {};
ret[std_iterator] = function () { return iter; }
ret[Symbol.iterator] = function () { return iter; }
return ret;
}
@ -19,7 +19,7 @@ function* yield_results(expected, n) {
function collect_results(iterable) {
var ret = [];
var result;
var iter = iterable[std_iterator]();
var iter = iterable[Symbol.iterator]();
do {
result = iter.next();
ret.push(result);

View File

@ -28,7 +28,7 @@ function Iter(val, count) {
}
this.next = next;
this[std_iterator] = iterator;
this[Symbol.iterator] = iterator;
}
function* delegate(iter) { return yield* iter; }

View File

@ -9,7 +9,7 @@ function results(results) {
return results[i++];
}
var ret = { next: next }
ret[std_iterator] = iterator;
ret[Symbol.iterator] = iterator;
return ret;
}

View File

@ -2,17 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var std_iterator = (function() {
try {
for (var _ of new Proxy({}, { get: function(_, name) { throw name; } }))
break;
} catch (name) {
return name;
}
throw 'wat';
})();
function assertFalse(a) { assertEq(a, false) }
function assertTrue(a) { assertEq(a, true) }
function assertNotEq(found, not_expected) { assertFalse(found === expected) }

View File

@ -66,8 +66,8 @@ if (typeof Symbol === "function") {
assertEq(descs.hasOwnProperty(s1), true);
assertEq(descs.hasOwnProperty(s2), true);
assertEq(descs.hasOwnProperty(s3), false);
assertEq([].hasOwnProperty(std_iterator), false);
assertEq(Array.prototype.hasOwnProperty(std_iterator), true);
assertEq([].hasOwnProperty(Symbol.iterator), false);
assertEq(Array.prototype.hasOwnProperty(Symbol.iterator), true);
// Object.prototype.propertyIsEnumerable
assertEq(n.propertyIsEnumerable(s1), true);

View File

@ -17,10 +17,10 @@ check("for (var v of x) throw fit;");
check("[...x]");
check("Math.hypot(...x)");
x[std_iterator] = "potato";
x[Symbol.iterator] = "potato";
check("for (var v of x) throw fit;");
x[std_iterator] = {};
x[Symbol.iterator] = {};
check("for (var v of x) throw fit;");
if (typeof reportCompare === "function")

View File

@ -876,5 +876,3 @@ function OptLevel( i ) {
cx.setOptimizationLevel(i);
}
/* end of Rhino functions */
var std_iterator = Symbol.iterator;