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