Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Array.prototype.iterator is generic. |
michael@0 | 2 | // That is, it can be applied to arraylike objects and strings, not just arrays. |
michael@0 | 3 | |
michael@0 | 4 | load(libdir + "asserts.js"); |
michael@0 | 5 | load(libdir + "iteration.js"); |
michael@0 | 6 | |
michael@0 | 7 | function test(obj) { |
michael@0 | 8 | var it = Array.prototype[std_iterator].call(obj); |
michael@0 | 9 | var ki = Array.prototype.keys.call(obj); |
michael@0 | 10 | var ei = Array.prototype.entries.call(obj); |
michael@0 | 11 | for (var i = 0; i < (obj.length >>> 0); i++) { |
michael@0 | 12 | assertIteratorNext(it, obj[i]); |
michael@0 | 13 | assertIteratorNext(ki, i); |
michael@0 | 14 | assertIteratorNext(ei, [i, obj[i]]); |
michael@0 | 15 | } |
michael@0 | 16 | assertIteratorDone(it, undefined); |
michael@0 | 17 | assertIteratorDone(ki, undefined); |
michael@0 | 18 | assertIteratorDone(ei, undefined); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | test({length: 0}); |
michael@0 | 22 | test({length: 0, 0: 'x', 1: 'y'}); |
michael@0 | 23 | test({length: 2, 0: 'x', 1: 'y'}); |
michael@0 | 24 | test(Object.create(['x', 'y', 'z'])); |
michael@0 | 25 | test(Object.create({length: 2, 0: 'x', 1: 'y'})); |
michael@0 | 26 | test(""); |
michael@0 | 27 | test("ponies"); |
michael@0 | 28 | |
michael@0 | 29 | // Perverse length values. |
michael@0 | 30 | test({length: 0x1f00000000}); |
michael@0 | 31 | test({length: -0xfffffffe, 0: 'a', 1: 'b'}); |
michael@0 | 32 | test({length: "011", 9: 9, 10: 10, 11: 11}); |
michael@0 | 33 | test({length: -0}); |
michael@0 | 34 | test({length: 2.7, 0: 0, 1: 1, 2: 2}); |
michael@0 | 35 | test({length: {valueOf: function () { return 3; }}, 0: 0, 1: 1, 2: 2}); |