1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/ion/ArrayLengthGetPropertyIC.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +function intLength (a, l) { 1.5 + var res = 0; 1.6 + for (var i = 0; i < l; i++) 1.7 + res += a.length; 1.8 + return res / l; 1.9 +} 1.10 + 1.11 +function valueLength (a, l) { 1.12 + var res = 0; 1.13 + for (var i = 0; i < l; i++) 1.14 + res += a.length; 1.15 + return res / l; 1.16 +} 1.17 + 1.18 +var denseArray = [0,1,2,3,4,5,6,7,8,9]; 1.19 +var typedArray = new Uint8Array(10); 1.20 +var hugeArray = new Array(4294967295); 1.21 +var fakeArray1 = { length: 10 }; 1.22 +var fakeArray2 = { length: 10.5 }; 1.23 + 1.24 +// Check the interpreter result and play with TI type objects. 1.25 +assertEq(intLength(denseArray, 10), 10); 1.26 +assertEq(intLength(typedArray, 10), 10); 1.27 +// assertEq(intLength(fakeArray1, 10), 10); 1.28 + 1.29 +assertEq(valueLength(denseArray, 10), 10); 1.30 +assertEq(valueLength(typedArray, 10), 10); 1.31 +assertEq(valueLength(hugeArray , 10), 4294967295); 1.32 +assertEq(valueLength(fakeArray2, 10), 10.5); 1.33 + 1.34 +// Heat up to compile (either JM / Ion) 1.35 +assertEq(intLength(denseArray, 100), 10); 1.36 +assertEq(valueLength(denseArray, 100), 10); 1.37 + 1.38 +// No bailout should occur during any of the following checks: 1.39 + 1.40 +// Check get-property length IC with dense array. 1.41 +assertEq(intLength(denseArray, 1), 10); 1.42 +assertEq(valueLength(denseArray, 1), 10); 1.43 + 1.44 +// Check get-property length IC with typed array. 1.45 +assertEq(intLength(typedArray, 1), 10); 1.46 +assertEq(valueLength(typedArray, 1), 10); 1.47 + 1.48 +// Check length which do not fit on non-double value. 1.49 +assertEq(valueLength(hugeArray, 1), 4294967295); 1.50 + 1.51 +// Check object length property. 1.52 +assertEq(intLength(fakeArray1, 1), 10); 1.53 +assertEq(valueLength(fakeArray2, 1), 10.5); 1.54 + 1.55 +// Cause invalidation of intLength by returning a double. 1.56 +assertEq(intLength(hugeArray, 1), 4294967295); 1.57 +assertEq(intLength(fakeArray2, 1), 10.5);