]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // Using full number + undefined for math. |
2 | function addArgsNumberAndUndefined(a, b) { | |
3 | return a + b; | |
4 | } | |
5 | noInline(addArgsNumberAndUndefined); | |
6 | ||
7 | for (var i = 0; i < 1e4; ++i) { | |
8 | var value = addArgsNumberAndUndefined(i, 1); | |
9 | if (value !== (i + 1)) | |
10 | throw "addArgsNumberAndUndefined(i, 1) failed with i = " + i + " returned value = " + value; | |
11 | ||
12 | var value = addArgsNumberAndUndefined(0.5, i); | |
13 | if (value !== (i + 0.5)) | |
14 | throw "addArgsNumberAndUndefined(0.5, i) failed with i = " + i + " returned value = " + value; | |
15 | ||
16 | var value = addArgsNumberAndUndefined(undefined, i); | |
17 | if (value === value) | |
18 | throw "addArgsNumberAndUndefined(undefined, i) failed with i = " + i + " returned value = " + value; | |
19 | ||
20 | var value = addArgsNumberAndUndefined(i, undefined); | |
21 | if (value === value) | |
22 | throw "addArgsNumberAndUndefined(i, undefined) failed with i = " + i + " returned value = " + value; | |
23 | ||
24 | var value = addArgsNumberAndUndefined(i); | |
25 | if (value === value) | |
26 | throw "addArgsNumberAndUndefined(i) failed with i = " + i + " returned value = " + value; | |
27 | ||
28 | var value = addArgsNumberAndUndefined(undefined, undefined); | |
29 | if (value === value) | |
30 | throw "addArgsNumberAndUndefined(undefined, undefined) failed with i = " + i + " returned value = " + value; | |
31 | ||
32 | var value = addArgsNumberAndUndefined(); | |
33 | if (value === value) | |
34 | throw "addArgsNumberAndUndefined() failed with i = " + i + " returned value = " + value; | |
35 | } | |
36 | ||
37 | ||
38 | // Using int32 + undefined for math. | |
39 | function addArgsInt32AndUndefined(a, b) { | |
40 | return a + b; | |
41 | } | |
42 | noInline(addArgsInt32AndUndefined); | |
43 | ||
44 | for (var i = 0; i < 1e4; ++i) { | |
45 | var value = addArgsInt32AndUndefined(i, 1); | |
46 | if (value !== (i + 1)) | |
47 | throw "addArgsInt32AndUndefined(i, 1) failed with i = " + i + " returned value = " + value; | |
48 | ||
49 | var value = addArgsInt32AndUndefined(undefined, i); | |
50 | if (value === value) | |
51 | throw "addArgsInt32AndUndefined(undefined, i) failed with i = " + i + " returned value = " + value; | |
52 | ||
53 | var value = addArgsInt32AndUndefined(i, undefined); | |
54 | if (value === value) | |
55 | throw "addArgsInt32AndUndefined(i, undefined) failed with i = " + i + " returned value = " + value; | |
56 | ||
57 | var value = addArgsInt32AndUndefined(i); | |
58 | if (value === value) | |
59 | throw "addArgsInt32AndUndefined(i) failed with i = " + i + " returned value = " + value; | |
60 | ||
61 | var value = addArgsInt32AndUndefined(undefined, undefined); | |
62 | if (value === value) | |
63 | throw "addArgsInt32AndUndefined(undefined, undefined) failed with i = " + i + " returned value = " + value; | |
64 | ||
65 | var value = addArgsInt32AndUndefined(); | |
66 | if (value === value) | |
67 | throw "addArgsInt32AndUndefined() failed with i = " + i + " returned value = " + value; | |
68 | } | |
69 | ||
70 | function testFallbackWithDouble() { | |
71 | var value = addArgsNumberAndUndefined(Math.PI, Math.PI); | |
72 | if (value !== 2 * Math.PI) | |
73 | throw "addArgsNumberAndUndefined(Math.PI, Math.PI) failed with i = " + i + " returned value = " + value; | |
74 | } | |
75 | testFallbackWithDouble(); | |
76 | ||
77 | ||
78 | // Using full number + undefined for math. | |
79 | function addArgsDoubleAndUndefined(a, b) { | |
80 | return a + b; | |
81 | } | |
82 | noInline(addArgsDoubleAndUndefined); | |
83 | ||
84 | for (var i = 0; i < 1e4; ++i) { | |
85 | var value = addArgsDoubleAndUndefined(0.5, i); | |
86 | if (value !== (i + 0.5)) | |
87 | throw "addArgsDoubleAndUndefined(0.5, i) failed with i = " + i + " returned value = " + value; | |
88 | ||
89 | var value = addArgsDoubleAndUndefined(undefined, 0.1); | |
90 | if (value === value) | |
91 | throw "addArgsDoubleAndUndefined(undefined, i) failed with i = " + i + " returned value = " + value; | |
92 | ||
93 | var value = addArgsDoubleAndUndefined(0.6, undefined); | |
94 | if (value === value) | |
95 | throw "addArgsDoubleAndUndefined(i, undefined) failed with i = " + i + " returned value = " + value; | |
96 | ||
97 | var value = addArgsDoubleAndUndefined(42.8); | |
98 | if (value === value) | |
99 | throw "addArgsDoubleAndUndefined(i) failed with i = " + i + " returned value = " + value; | |
100 | } | |
101 | ||
102 | function testFallbackWithObject() { | |
103 | var value = addArgsDoubleAndUndefined(Math.PI, { valueOf: function() { return 5; }}); | |
104 | if (value !== 5 + Math.PI) | |
105 | throw "addArgsDoubleAndUndefined(Math.PI, { valueOf: function() { return 5; }}) failed with i = " + i + " returned value = " + value; | |
106 | } | |
107 | testFallbackWithObject(); | |
108 | ||
109 | ||
110 | // Using full number + undefined for math. | |
111 | function addArgsOnlyUndefined(a, b) { | |
112 | return a + b; | |
113 | } | |
114 | noInline(addArgsOnlyUndefined); | |
115 | ||
116 | for (var i = 0; i < 1e4; ++i) { | |
117 | var value = addArgsOnlyUndefined(undefined, undefined); | |
118 | if (value === value) | |
119 | throw "addArgsOnlyUndefined(undefined, undefined) failed with i = " + i + " returned value = " + value; | |
120 | ||
121 | var value = addArgsOnlyUndefined(); | |
122 | if (value === value) | |
123 | throw "addArgsOnlyUndefined() failed with i = " + i + " returned value = " + value; | |
124 | } | |
125 | ||
126 | function testFallbackWithString() { | |
127 | var value = addArgsOnlyUndefined("foo", "bar"); | |
128 | if (value !== "foobar") | |
129 | throw "addArgsOnlyUndefined(\"foo\", \"bar\") failed with i = " + i + " returned value = " + value; | |
130 | } | |
131 | testFallbackWithString(); |