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 | // An array iterator for a proxy calls the traps in a predictable order. |
michael@0 | 2 | |
michael@0 | 3 | load(libdir + "asserts.js"); |
michael@0 | 4 | load(libdir + "iteration.js"); |
michael@0 | 5 | |
michael@0 | 6 | var s = ''; |
michael@0 | 7 | |
michael@0 | 8 | var proxyObj = { |
michael@0 | 9 | get: function (recipient, name) { |
michael@0 | 10 | if (name == 'length') { |
michael@0 | 11 | s += 'L'; |
michael@0 | 12 | return 2; |
michael@0 | 13 | } else { |
michael@0 | 14 | s += name; |
michael@0 | 15 | return name; |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | }; |
michael@0 | 19 | |
michael@0 | 20 | var it = Array.prototype[std_iterator].call(Proxy.create(proxyObj)); |
michael@0 | 21 | |
michael@0 | 22 | assertIteratorNext(it, "0"); |
michael@0 | 23 | s += ' '; |
michael@0 | 24 | assertIteratorNext(it, "1"); |
michael@0 | 25 | s += ' '; |
michael@0 | 26 | assertIteratorDone(it, undefined); |
michael@0 | 27 | assertEq(s, "L0 L1 L"); |
michael@0 | 28 | |
michael@0 | 29 | s = ''; |
michael@0 | 30 | var ki = Array.prototype.keys.call(Proxy.create(proxyObj)); |
michael@0 | 31 | |
michael@0 | 32 | assertIteratorNext(ki, 0); |
michael@0 | 33 | s += ' '; |
michael@0 | 34 | assertIteratorNext(ki, 1); |
michael@0 | 35 | s += ' '; |
michael@0 | 36 | assertIteratorDone(ki, undefined); |
michael@0 | 37 | assertEq(s, "L L L"); |
michael@0 | 38 | |
michael@0 | 39 | s = ''; |
michael@0 | 40 | var ei = Array.prototype.entries.call(Proxy.create(proxyObj)); |
michael@0 | 41 | |
michael@0 | 42 | assertIteratorNext(ei, [0, "0"]); |
michael@0 | 43 | s += ' '; |
michael@0 | 44 | assertIteratorNext(ei, [1, "1"]); |
michael@0 | 45 | s += ' '; |
michael@0 | 46 | assertIteratorDone(ei, undefined); |
michael@0 | 47 | assertEq(s, "L0 L1 L"); |