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 | // Force recognition of a known-constant. |
michael@0 | 2 | var push = Array.prototype.push; |
michael@0 | 3 | |
michael@0 | 4 | function f(arr) |
michael@0 | 5 | { |
michael@0 | 6 | // Push an actual constant to trigger JIT-inlining of the effect of the push. |
michael@0 | 7 | push.call(arr, 99); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function basic(out) |
michael@0 | 11 | { |
michael@0 | 12 | // Create an array of arrays, to be iterated over for [].push-calling. We |
michael@0 | 13 | // can't just loop on push on a single array with non-writable length because |
michael@0 | 14 | // push throws when called on an array with non-writable length. |
michael@0 | 15 | var arrs = out.arrs = []; |
michael@0 | 16 | for (var i = 0; i < 100; i++) |
michael@0 | 17 | arrs.push([]); |
michael@0 | 18 | |
michael@0 | 19 | // Use a much-greater capacity than the eventual non-writable length. |
michael@0 | 20 | var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
michael@0 | 21 | Object.defineProperty(a, "length", { writable: false, value: 6 }); |
michael@0 | 22 | |
michael@0 | 23 | arrs.push(a); |
michael@0 | 24 | |
michael@0 | 25 | for (var i = 0, sz = arrs.length; i < sz; i++) |
michael@0 | 26 | { |
michael@0 | 27 | var arr = arrs[i]; |
michael@0 | 28 | f(arr); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | var obj = {}; |
michael@0 | 33 | var arrs, a; |
michael@0 | 34 | |
michael@0 | 35 | try |
michael@0 | 36 | { |
michael@0 | 37 | basic(obj); |
michael@0 | 38 | throw new Error("didn't throw!"); |
michael@0 | 39 | } |
michael@0 | 40 | catch (e) |
michael@0 | 41 | { |
michael@0 | 42 | assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); |
michael@0 | 43 | |
michael@0 | 44 | arrs = obj.arrs; |
michael@0 | 45 | assertEq(arrs.length, 101); |
michael@0 | 46 | for (var i = 0; i < 100; i++) |
michael@0 | 47 | { |
michael@0 | 48 | assertEq(arrs[i].length, 1, "unexpected length for arrs[" + i + "]"); |
michael@0 | 49 | assertEq(arrs[i][0], 99, "bad element for arrs[" + i + "]"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | a = arrs[100]; |
michael@0 | 53 | assertEq(a.hasOwnProperty(6), false); |
michael@0 | 54 | assertEq(a[6], undefined); |
michael@0 | 55 | assertEq(a.length, 6); |
michael@0 | 56 | } |