ArrayLengthGetPropertyIC.js (1637B)
1 function intLength (a, l) { 2 var res = 0; 3 for (var i = 0; i < l; i++) 4 res += a.length; 5 return res / l; 6 } 7 8 function valueLength (a, l) { 9 var res = 0; 10 for (var i = 0; i < l; i++) 11 res += a.length; 12 return res / l; 13 } 14 15 var denseArray = [0,1,2,3,4,5,6,7,8,9]; 16 var typedArray = new Uint8Array(10); 17 var hugeArray = new Array(4294967295); 18 var fakeArray1 = { length: 10 }; 19 var fakeArray2 = { length: 10.5 }; 20 21 // Check the interpreter result and play with TI type objects. 22 assertEq(intLength(denseArray, 10), 10); 23 assertEq(intLength(typedArray, 10), 10); 24 // assertEq(intLength(fakeArray1, 10), 10); 25 26 assertEq(valueLength(denseArray, 10), 10); 27 assertEq(valueLength(typedArray, 10), 10); 28 assertEq(valueLength(hugeArray , 10), 4294967295); 29 assertEq(valueLength(fakeArray2, 10), 10.5); 30 31 // Heat up to compile (either JM / Ion) 32 assertEq(intLength(denseArray, 100), 10); 33 assertEq(valueLength(denseArray, 100), 10); 34 35 // No bailout should occur during any of the following checks: 36 37 // Check get-property length IC with dense array. 38 assertEq(intLength(denseArray, 1), 10); 39 assertEq(valueLength(denseArray, 1), 10); 40 41 // Check get-property length IC with typed array. 42 assertEq(intLength(typedArray, 1), 10); 43 assertEq(valueLength(typedArray, 1), 10); 44 45 // Check length which do not fit on non-double value. 46 assertEq(valueLength(hugeArray, 1), 4294967295); 47 48 // Check object length property. 49 assertEq(intLength(fakeArray1, 1), 10); 50 assertEq(valueLength(fakeArray2, 1), 10.5); 51 52 // Cause invalidation of intLength by returning a double. 53 assertEq(intLength(hugeArray, 1), 4294967295); 54 assertEq(intLength(fakeArray2, 1), 10.5);