| 1 |
// Test inlining bound function to inlinable natives when additional bound |
| 2 |
// arguments are used. |
| 3 |
|
| 4 |
function testMathMinBound1() { |
| 5 |
// Bind the inlinable native |Math.min|. |
| 6 |
// |Math.min| is inlined when up to four arguments are present. |
| 7 |
var MathMin = Math.min.bind(null, 4); |
| 8 |
|
| 9 |
for (var i = 0; i < 100; ++i) { |
| 10 |
assertEq(MathMin(i & 7), Math.min(i & 7, 4)); |
| 11 |
} |
| 12 |
} |
| 13 |
testMathMinBound1(); |
| 14 |
|
| 15 |
function testMathMinBound2() { |
| 16 |
// Bind the inlinable native |Math.min|. |
| 17 |
// |Math.min| is inlined when up to four arguments are present. |
| 18 |
var MathMin = Math.min.bind(null, 4, 3); |
| 19 |
|
| 20 |
for (var i = 0; i < 100; ++i) { |
| 21 |
assertEq(MathMin(i & 7), Math.min(i & 7, 3)); |
| 22 |
} |
| 23 |
} |
| 24 |
testMathMinBound2(); |
| 25 |
|
| 26 |
function testMathMinBound3() { |
| 27 |
// Bind the inlinable native |Math.min|. |
| 28 |
// |Math.min| is inlined when up to four arguments are present. |
| 29 |
var MathMin = Math.min.bind(null, 4, 3, 2); |
| 30 |
|
| 31 |
for (var i = 0; i < 100; ++i) { |
| 32 |
assertEq(MathMin(i & 7), Math.min(i & 7, 2)); |
| 33 |
} |
| 34 |
} |
| 35 |
testMathMinBound3(); |
| 36 |
|
| 37 |
function testMathMinBound4() { |
| 38 |
// Bind the inlinable native |Math.min|. |
| 39 |
// |Math.min| is inlined when up to four arguments are present. |
| 40 |
var MathMin = Math.min.bind(null, 4, 3, 2, 1); |
| 41 |
|
| 42 |
for (var i = 0; i < 100; ++i) { |
| 43 |
assertEq(MathMin(), 1); |
| 44 |
} |
| 45 |
} |
| 46 |
testMathMinBound4(); |
| 47 |
|
| 48 |
function testMathMinBound4NoInline() { |
| 49 |
// Bind the inlinable native |Math.min|. |
| 50 |
// |Math.min| is inlined when up to four arguments are present. |
| 51 |
var MathMin = Math.min.bind(null, 4, 3, 2, 1); |
| 52 |
|
| 53 |
for (var i = 0; i < 100; ++i) { |
| 54 |
assertEq(MathMin(i & 7), Math.min(i & 7, 1)); |
| 55 |
} |
| 56 |
} |
| 57 |
testMathMinBound4NoInline(); |
| 58 |
|
| 59 |
function testStringCharAt() { |
| 60 |
// Bind the inlinable native |String.prototype.charCodeAt| to |
| 61 |
// cover reading the |this| value. |
| 62 |
var str = "abcdefgh"; |
| 63 |
var CharAt = String.prototype.charAt.bind(str, 0); |
| 64 |
|
| 65 |
for (var i = 0; i < 100; ++i) { |
| 66 |
assertEq(CharAt(), "a"); |
| 67 |
} |
| 68 |
} |
| 69 |
testStringCharAt(); |
| 70 |
|
| 71 |
function testArrayConstructor() { |
| 72 |
// Bind the Array constructor function. |
| 73 |
var A = Array.bind(null, 10); |
| 74 |
|
| 75 |
for (var i = 0; i < 100; ++i) { |
| 76 |
var a = new A(); |
| 77 |
assertEq(a.length, 10); |
| 78 |
assertEq(Object.getPrototypeOf(a), Array.prototype); |
| 79 |
} |
| 80 |
} |
| 81 |
testArrayConstructor(); |
| 82 |
|
| 83 |
function testMathMaxSpreadNoInline() { |
| 84 |
// Spread calls to bound functions aren't supported when additional bound |
| 85 |
// arguments are present. |
| 86 |
var MathMax = Math.max.bind(null, 0); |
| 87 |
|
| 88 |
for (var i = 0; i < 100; ++i) { |
| 89 |
var args = [i - 1, i, i + 1]; |
| 90 |
assertEq(MathMax(...args), i + 1); |
| 91 |
} |
| 92 |
} |
| 93 |
testMathMaxSpreadNoInline(); |
| 94 |
|
| 95 |
function testMathMaxVariableBoundArgs() { |
| 96 |
// Bound Math.max with different number of bound arguments. |
| 97 |
var MathMax = [ |
| 98 |
Math.max.bind(null, 4), |
| 99 |
Math.max.bind(null, 4, 5), |
| 100 |
]; |
| 101 |
|
| 102 |
for (var i = 0; i < 100; ++i) { |
| 103 |
assertEq(MathMax[i & 1](i & 7), Math.max(i & 7, 4 + (i & 1))); |
| 104 |
} |
| 105 |
} |
| 106 |
testMathMaxVariableBoundArgs(); |
| 107 |
|
| 108 |
function testFunctionBindWithBoundArgNoInline() { |
| 109 |
var array = []; |
| 110 |
|
| 111 |
// Bound function whose target is |Function.prototype.bind| and whose |
| 112 |
// this-value is |Array.prototype.push|. Also pass |array| as the this-value |
| 113 |
// for bound function which is returned when calling |FunBind()|. |
| 114 |
var FunBind = Function.prototype.bind.bind(Array.prototype.push, array); |
| 115 |
|
| 116 |
for (var i = 0; i < 100; ++i) { |
| 117 |
// Create a new bound function. |
| 118 |
// |
| 119 |
// This call to the bound target |Function.prototype.bind| won't be inlined, |
| 120 |
// because |FunBind| has additional bound arguments. |
| 121 |
var push = FunBind(); |
| 122 |
|
| 123 |
assertEq(array.length, i * 3); |
| 124 |
push(1, 2, 3); |
| 125 |
assertEq(array.length, (i + 1) * 3); |
| 126 |
} |
| 127 |
} |
| 128 |
testFunctionBindWithBoundArgNoInline(); |