inlinable-native-accessor-6.js (1969B)
1 setJitCompilerOption("ion.forceinlineCaches", 1); 2 3 function testMathRandom() { 4 var obj = Object.defineProperty({}, "random", {get: Math.random}); 5 6 for (var i = 0; i < 100; ++i) { 7 var r = obj.random; 8 assertEq(0 <= r && r < 1, true); 9 } 10 } 11 testMathRandom(); 12 13 function testDateGetTime() { 14 Object.defineProperty(Date.prototype, "time", {get: Date.prototype.getTime}); 15 16 var d = new Date(0); 17 for (var i = 0; i < 100; ++i) { 18 assertEq(d.time, 0); 19 } 20 } 21 testDateGetTime(); 22 23 function testNumberToString() { 24 Object.defineProperty(Number.prototype, "tostr", {get: Number.prototype.toString}); 25 26 for (var i = 0; i < 100; ++i) { 27 assertEq(0..tostr, "0"); 28 assertEq(0.5.tostr, "0.5"); 29 } 30 } 31 testNumberToString(); 32 33 function testStringAt() { 34 Object.defineProperty(String.prototype, "at_", {get: String.prototype.at}); 35 36 for (var i = 0; i < 100; ++i) { 37 assertEq("a".at_, "a"); 38 } 39 } 40 testStringAt(); 41 42 function testArraySlice() { 43 Object.defineProperty(Array.prototype, "sliced", {get: Array.prototype.slice}); 44 45 for (var i = 0; i < 100; ++i) { 46 assertEq([1, 2].sliced.length, 2); 47 } 48 } 49 testArraySlice(); 50 51 function testArraySliceArguments() { 52 Object.defineProperty(arguments, "sliced", {get: Array.prototype.slice}); 53 54 for (var i = 0; i < 100; ++i) { 55 assertEq(arguments.sliced.length, 0); 56 } 57 } 58 testArraySliceArguments(); 59 60 function testArrayJoin() { 61 Object.defineProperty(Array.prototype, "joined", {get: Array.prototype.join}); 62 63 for (var i = 0; i < 100; ++i) { 64 assertEq([].joined, ""); 65 assertEq(["a"].joined, "a"); 66 } 67 } 68 testArrayJoin(); 69 70 function testFunctionBind() { 71 Object.defineProperty(Function.prototype, "bound", {get: Function.prototype.bind}); 72 73 for (var i = 0; i < 100; ++i) { 74 // |SpecializedBindFunctionResult| CacheIROp. 75 assertEq(function(){ return i; }.bound(), i); 76 77 // |BindFunctionResult| CacheIROp. 78 var r = Math.random.bound(); 79 assertEq(0 <= r && r < 1, true); 80 } 81 } 82 testFunctionBind();