1 // Using full number + undefined for math.
2 function addArgsNumberAndUndefined(a
, b
) {
5 noInline(addArgsNumberAndUndefined
);
7 for (var i
= 0; i
< 1e4
; ++i
) {
8 var value
= addArgsNumberAndUndefined(i
, 1);
10 throw "addArgsNumberAndUndefined(i, 1) failed with i = " + i
+ " returned value = " + value
;
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
;
16 var value
= addArgsNumberAndUndefined(undefined, i
);
18 throw "addArgsNumberAndUndefined(undefined, i) failed with i = " + i
+ " returned value = " + value
;
20 var value
= addArgsNumberAndUndefined(i
, undefined);
22 throw "addArgsNumberAndUndefined(i, undefined) failed with i = " + i
+ " returned value = " + value
;
24 var value
= addArgsNumberAndUndefined(i
);
26 throw "addArgsNumberAndUndefined(i) failed with i = " + i
+ " returned value = " + value
;
28 var value
= addArgsNumberAndUndefined(undefined, undefined);
30 throw "addArgsNumberAndUndefined(undefined, undefined) failed with i = " + i
+ " returned value = " + value
;
32 var value
= addArgsNumberAndUndefined();
34 throw "addArgsNumberAndUndefined() failed with i = " + i
+ " returned value = " + value
;
38 // Using int32 + undefined for math.
39 function addArgsInt32AndUndefined(a
, b
) {
42 noInline(addArgsInt32AndUndefined
);
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
;
49 var value
= addArgsInt32AndUndefined(undefined, i
);
51 throw "addArgsInt32AndUndefined(undefined, i) failed with i = " + i
+ " returned value = " + value
;
53 var value
= addArgsInt32AndUndefined(i
, undefined);
55 throw "addArgsInt32AndUndefined(i, undefined) failed with i = " + i
+ " returned value = " + value
;
57 var value
= addArgsInt32AndUndefined(i
);
59 throw "addArgsInt32AndUndefined(i) failed with i = " + i
+ " returned value = " + value
;
61 var value
= addArgsInt32AndUndefined(undefined, undefined);
63 throw "addArgsInt32AndUndefined(undefined, undefined) failed with i = " + i
+ " returned value = " + value
;
65 var value
= addArgsInt32AndUndefined();
67 throw "addArgsInt32AndUndefined() failed with i = " + i
+ " returned value = " + value
;
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
;
75 testFallbackWithDouble();
78 // Using full number + undefined for math.
79 function addArgsDoubleAndUndefined(a
, b
) {
82 noInline(addArgsDoubleAndUndefined
);
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
;
89 var value
= addArgsDoubleAndUndefined(undefined, 0.1);
91 throw "addArgsDoubleAndUndefined(undefined, i) failed with i = " + i
+ " returned value = " + value
;
93 var value
= addArgsDoubleAndUndefined(0.6, undefined);
95 throw "addArgsDoubleAndUndefined(i, undefined) failed with i = " + i
+ " returned value = " + value
;
97 var value
= addArgsDoubleAndUndefined(42.8);
99 throw "addArgsDoubleAndUndefined(i) failed with i = " + i
+ " returned value = " + value
;
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
;
107 testFallbackWithObject();
110 // Using full number + undefined for math.
111 function addArgsOnlyUndefined(a
, b
) {
114 noInline(addArgsOnlyUndefined
);
116 for (var i
= 0; i
< 1e4
; ++i
) {
117 var value
= addArgsOnlyUndefined(undefined, undefined);
119 throw "addArgsOnlyUndefined(undefined, undefined) failed with i = " + i
+ " returned value = " + value
;
121 var value
= addArgsOnlyUndefined();
123 throw "addArgsOnlyUndefined() failed with i = " + i
+ " returned value = " + value
;
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
;
131 testFallbackWithString();