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 | load(libdir + "asserts.js"); |
michael@0 | 2 | |
michael@0 | 3 | function f(arr, v1, v2) |
michael@0 | 4 | { |
michael@0 | 5 | // Ensure array_push_slowly is called by passing more than one argument. |
michael@0 | 6 | arr.push(v1, v2); |
michael@0 | 7 | } |
michael@0 | 8 | |
michael@0 | 9 | var N = 100; |
michael@0 | 10 | |
michael@0 | 11 | function test(out) |
michael@0 | 12 | { |
michael@0 | 13 | // Create an array of arrays, to be iterated over for [].push-calling. We |
michael@0 | 14 | // can't just loop on push on a single array with non-writable length because |
michael@0 | 15 | // push throws when called on an array with non-writable length. |
michael@0 | 16 | var arrs = out.arrs = []; |
michael@0 | 17 | for (var i = 0; i < N; i++) |
michael@0 | 18 | arrs.push([]); |
michael@0 | 19 | |
michael@0 | 20 | // Use a much-greater capacity than the eventual non-writable length. |
michael@0 | 21 | var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
michael@0 | 22 | Object.defineProperty(a, "length", { writable: false, value: 6 }); |
michael@0 | 23 | |
michael@0 | 24 | arrs.push(a); |
michael@0 | 25 | |
michael@0 | 26 | for (var i = 0, sz = arrs.length; i < sz; i++) |
michael@0 | 27 | { |
michael@0 | 28 | var arr = arrs[i]; |
michael@0 | 29 | f(arr, 8675309, 3141592); |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | var obj = {}; |
michael@0 | 34 | |
michael@0 | 35 | assertThrowsInstanceOf(function() { test(obj); }, TypeError); |
michael@0 | 36 | |
michael@0 | 37 | var arrs = obj.arrs; |
michael@0 | 38 | assertEq(arrs.length, N + 1); |
michael@0 | 39 | for (var i = 0; i < N; i++) |
michael@0 | 40 | { |
michael@0 | 41 | assertEq(arrs[i].length, 2, "unexpected length for arrs[" + i + "]"); |
michael@0 | 42 | assertEq(arrs[i][0], 8675309, "bad element for arrs[" + i + "][0]"); |
michael@0 | 43 | assertEq(arrs[i][1], 3141592, "bad element for arrs[" + i + "][1]"); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | var a = arrs[N]; |
michael@0 | 47 | assertEq(a.hasOwnProperty(6), false); |
michael@0 | 48 | assertEq(a[6], undefined); |
michael@0 | 49 | assertEq(a.hasOwnProperty(7), false); |
michael@0 | 50 | assertEq(a[7], undefined); |
michael@0 | 51 | assertEq(a.length, 6); |