1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/arrays/push-densely-loopy-nonwritable-length.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +// Force recognition of a known-constant. 1.5 +var push = Array.prototype.push; 1.6 + 1.7 +function f(arr) 1.8 +{ 1.9 + // Push an actual constant to trigger JIT-inlining of the effect of the push. 1.10 + push.call(arr, 99); 1.11 +} 1.12 + 1.13 +function basic(out) 1.14 +{ 1.15 + // Create an array of arrays, to be iterated over for [].push-calling. We 1.16 + // can't just loop on push on a single array with non-writable length because 1.17 + // push throws when called on an array with non-writable length. 1.18 + var arrs = out.arrs = []; 1.19 + for (var i = 0; i < 100; i++) 1.20 + arrs.push([]); 1.21 + 1.22 + // Use a much-greater capacity than the eventual non-writable length. 1.23 + var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; 1.24 + Object.defineProperty(a, "length", { writable: false, value: 6 }); 1.25 + 1.26 + arrs.push(a); 1.27 + 1.28 + for (var i = 0, sz = arrs.length; i < sz; i++) 1.29 + { 1.30 + var arr = arrs[i]; 1.31 + f(arr); 1.32 + } 1.33 +} 1.34 + 1.35 +var obj = {}; 1.36 +var arrs, a; 1.37 + 1.38 +try 1.39 +{ 1.40 + basic(obj); 1.41 + throw new Error("didn't throw!"); 1.42 +} 1.43 +catch (e) 1.44 +{ 1.45 + assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); 1.46 + 1.47 + arrs = obj.arrs; 1.48 + assertEq(arrs.length, 101); 1.49 + for (var i = 0; i < 100; i++) 1.50 + { 1.51 + assertEq(arrs[i].length, 1, "unexpected length for arrs[" + i + "]"); 1.52 + assertEq(arrs[i][0], 99, "bad element for arrs[" + i + "]"); 1.53 + } 1.54 + 1.55 + a = arrs[100]; 1.56 + assertEq(a.hasOwnProperty(6), false); 1.57 + assertEq(a[6], undefined); 1.58 + assertEq(a.length, 6); 1.59 +}