| 1 |
// Test inlining bound fun_call to inlinable natives. |
| 2 |
|
| 3 |
function testMathMin() { |
| 4 |
// Bind the inlinable native |Math.min|. |
| 5 |
var MathMin = Function.prototype.call.bind(Math.min); |
| 6 |
|
| 7 |
for (var i = 0; i < 100; ++i) { |
| 8 |
// Pass `undefined` as the unused |this|-value. |
| 9 |
assertEq(MathMin(undefined, i, 50), Math.min(i, 50)); |
| 10 |
} |
| 11 |
} |
| 12 |
testMathMin(); |
| 13 |
|
| 14 |
function testMathMinMax() { |
| 15 |
// Bind the inlinable natives |Math.min| and |Math.max|. |
| 16 |
var MathMinMax = [ |
| 17 |
Function.prototype.call.bind(Math.min), |
| 18 |
Function.prototype.call.bind(Math.max), |
| 19 |
]; |
| 20 |
|
| 21 |
// Compare against the non-bound |Math.min| and |Math.max|. |
| 22 |
var minmax = [ |
| 23 |
Math.min, |
| 24 |
Math.max, |
| 25 |
]; |
| 26 |
|
| 27 |
for (var i = 0; i < 200; ++i) { |
| 28 |
// Pass `null` as the unused |this|-value. |
| 29 |
assertEq(MathMinMax[i & 1](null, i, 50), minmax[i & 1](i, 50)); |
| 30 |
} |
| 31 |
} |
| 32 |
testMathMinMax(); |
| 33 |
|
| 34 |
function testMathMinBoundAndNonBound() { |
| 35 |
// Use bound and non-bound |Math.min|. |
| 36 |
var MathMin = [ |
| 37 |
Function.prototype.call.bind(Math.min), |
| 38 |
Math.min, |
| 39 |
]; |
| 40 |
|
| 41 |
for (var i = 0; i < 200; ++i) { |
| 42 |
// Pass `Infinity` as the first argument. It's unused for the bound case and |
| 43 |
// never the result for the non-bound case. |
| 44 |
assertEq(MathMin[i & 1](Infinity, i, 50), Math.min(i, 50)); |
| 45 |
} |
| 46 |
} |
| 47 |
testMathMinBoundAndNonBound(); |
| 48 |
|
| 49 |
function testStringCharCodeAt() { |
| 50 |
// Bind the inlinable native |String.prototype.charCodeAt| to |
| 51 |
// cover reading the |this| value. |
| 52 |
var str = "abcdefgh"; |
| 53 |
var CharCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt); |
| 54 |
|
| 55 |
for (var i = 0; i < 100; ++i) { |
| 56 |
assertEq(CharCodeAt(str, i & 7), str.charCodeAt(i & 7)); |
| 57 |
} |
| 58 |
} |
| 59 |
testStringCharCodeAt(); |
| 60 |
|
| 61 |
function testStringCharCodeAtWithBoundThis() { |
| 62 |
// Bound |this| value. |
| 63 |
var str = "abcdefgh"; |
| 64 |
var CharCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt, str); |
| 65 |
|
| 66 |
for (var i = 0; i < 100; ++i) { |
| 67 |
assertEq(CharCodeAt(i & 7), str.charCodeAt(i & 7)); |
| 68 |
} |
| 69 |
} |
| 70 |
testStringCharCodeAtWithBoundThis(); |
| 71 |
|
| 72 |
function testStringCharCodeAtWithBoundArgs() { |
| 73 |
// Bound |this| value and bound arguments. |
| 74 |
var str = "abcdefgh"; |
| 75 |
var CharCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt, str, 0); |
| 76 |
|
| 77 |
for (var i = 0; i < 100; ++i) { |
| 78 |
assertEq(CharCodeAt(), str.charCodeAt(0)); |
| 79 |
} |
| 80 |
} |
| 81 |
testStringCharCodeAtWithBoundArgs(); |
| 82 |
|
| 83 |
function testMathRandomWithNoArgs() { |
| 84 |
// Bound fun_call called with no additional stack args. |
| 85 |
var MathRandom = Function.prototype.call.bind(Math.random); |
| 86 |
|
| 87 |
for (var i = 0; i < 100; ++i) { |
| 88 |
var r = MathRandom(); |
| 89 |
assertEq(0 <= r && r < 1, true); |
| 90 |
} |
| 91 |
} |
| 92 |
testMathRandomWithNoArgs(); |
| 93 |
|
| 94 |
function testMathMinBoundArgsAndStackArgs() { |
| 95 |
// Bound |this| value and bound arguments. |
| 96 |
var str = "abcdefgh"; |
| 97 |
var MathMin = Function.prototype.call.bind(Math.min, null, 50); |
| 98 |
|
| 99 |
for (var i = 0; i < 100; ++i) { |
| 100 |
assertEq(MathMin(i), Math.min(50, i)); |
| 101 |
} |
| 102 |
} |
| 103 |
testMathMinBoundArgsAndStackArgs(); |