michael@0: // Array.prototype.iterator is generic. michael@0: // That is, it can be applied to arraylike objects and strings, not just arrays. michael@0: michael@0: load(libdir + "asserts.js"); michael@0: load(libdir + "iteration.js"); michael@0: michael@0: function test(obj) { michael@0: var it = Array.prototype[std_iterator].call(obj); michael@0: var ki = Array.prototype.keys.call(obj); michael@0: var ei = Array.prototype.entries.call(obj); michael@0: for (var i = 0; i < (obj.length >>> 0); i++) { michael@0: assertIteratorNext(it, obj[i]); michael@0: assertIteratorNext(ki, i); michael@0: assertIteratorNext(ei, [i, obj[i]]); michael@0: } michael@0: assertIteratorDone(it, undefined); michael@0: assertIteratorDone(ki, undefined); michael@0: assertIteratorDone(ei, undefined); michael@0: } michael@0: michael@0: test({length: 0}); michael@0: test({length: 0, 0: 'x', 1: 'y'}); michael@0: test({length: 2, 0: 'x', 1: 'y'}); michael@0: test(Object.create(['x', 'y', 'z'])); michael@0: test(Object.create({length: 2, 0: 'x', 1: 'y'})); michael@0: test(""); michael@0: test("ponies"); michael@0: michael@0: // Perverse length values. michael@0: test({length: 0x1f00000000}); michael@0: test({length: -0xfffffffe, 0: 'a', 1: 'b'}); michael@0: test({length: "011", 9: 9, 10: 10, 11: 11}); michael@0: test({length: -0}); michael@0: test({length: 2.7, 0: 0, 1: 1, 2: 2}); michael@0: test({length: {valueOf: function () { return 3; }}, 0: 0, 1: 1, 2: 2});