| 1 |
// Test non-constructor calls |
| 2 |
|
| 3 |
var funcs = [Math.max, Math.min, Math.floor, Math.ceil, Math.sin, |
| 4 |
Math.cos, Math.tan, Math.log, Math.acos, Math.asin]; |
| 5 |
|
| 6 |
// Calculate expected values |
| 7 |
var expected = [Math.max(0.5, 2), Math.min(0.5, 2), |
| 8 |
Math.floor(0.5, 2), Math.ceil(0.5, 2), |
| 9 |
Math.sin(0.5, 2), Math.cos(0.5, 2), |
| 10 |
Math.tan(0.5, 2), Math.log(0.5, 2), |
| 11 |
Math.acos(0.5, 2), Math.asin(0.5, 2)]; |
| 12 |
|
| 13 |
// Test a polymorphic call site |
| 14 |
for (var n = 0; n < 50; n++) { |
| 15 |
for (var i = 0; i < funcs.length; i++) { |
| 16 |
assertEq(funcs[i](0.5, 2), expected[i]); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
// Test a polymorphic spread call site |
| 21 |
var spreadinput = [0.5, 2]; |
| 22 |
for (var n = 0; n < 50; n++) { |
| 23 |
for (var i = 0; i < funcs.length; i++) { |
| 24 |
assertEq(funcs[i](...spreadinput), expected[i]); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
// Test constructors |
| 29 |
|
| 30 |
function f1(x) {this[0] = x; this.length = 3;} |
| 31 |
function f2(x) {this[0] = x; this.length = 3;} |
| 32 |
function f3(x) {this[0] = x; this.length = 3;} |
| 33 |
function f4(x) {this[0] = x; this.length = 3;} |
| 34 |
function f5(x) {this[0] = x; this.length = 3;} |
| 35 |
function f6(x) {this[0] = x; this.length = 3;} |
| 36 |
function f7(x) {this[0] = x; this.length = 3;} |
| 37 |
function f8(x) {this[0] = x; this.length = 3;} |
| 38 |
function f9(x) {this[0] = x; this.length = 3;} |
| 39 |
|
| 40 |
var constructors = [f1,f2,f3,f4,f5,f6,f7,f8,f9,Array]; |
| 41 |
|
| 42 |
// Test a polymorphic constructor site |
| 43 |
for (var n = 0; n < 50; n++) { |
| 44 |
for (var i = 0; i < constructors.length; i++) { |
| 45 |
let x = new constructors[i](1,2,3); |
| 46 |
assertEq(x.length, 3); |
| 47 |
assertEq(x[0], 1); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
var constructorinput = [1,2,3]; |
| 52 |
// Test a polymorphic spread constructor site |
| 53 |
for (var n = 0; n < 50; n++) { |
| 54 |
for (var i = 0; i < constructors.length; i++) { |
| 55 |
let x = new constructors[i](...constructorinput); |
| 56 |
assertEq(x.length, 3); |
| 57 |
assertEq(x[0], 1); |
| 58 |
} |
| 59 |
} |