]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/double-rep-with-null.js
1 // Using full number + null for math.
2 function addArgsNumberAndNull(a
, b
) {
5 noInline(addArgsNumberAndNull
);
7 for (var i
= 0; i
< 1e4
; ++i
) {
8 var value
= addArgsNumberAndNull(i
, 1);
10 throw "addArgsNumberAndNull(i, 1) failed with i = " + i
+ " returned value = " + value
;
12 var value
= addArgsNumberAndNull(0.5, i
);
13 if (value
!== (i
+ 0.5))
14 throw "addArgsNumberAndNull(0.5, i) failed with i = " + i
+ " returned value = " + value
;
16 var value
= addArgsNumberAndNull(null, i
);
18 throw "addArgsNumberAndNull(null, i) failed with i = " + i
+ " returned value = " + value
;
20 var value
= addArgsNumberAndNull(i
, null);
22 throw "addArgsNumberAndNull(i, null) failed with i = " + i
+ " returned value = " + value
;
24 var value
= addArgsNumberAndNull(null, null);
26 throw "addArgsNumberAndNull(null, null) failed with i = " + i
+ " returned value = " + value
;
30 // Using int32 + null for math.
31 function addArgsInt32AndNull(a
, b
) {
34 noInline(addArgsInt32AndNull
);
36 for (var i
= 0; i
< 1e4
; ++i
) {
37 var value
= addArgsInt32AndNull(i
, 1);
38 if (value
!== (i
+ 1))
39 throw "addArgsInt32AndNull(i, 1) failed with i = " + i
+ " returned value = " + value
;
41 var value
= addArgsInt32AndNull(null, i
);
43 throw "addArgsInt32AndNull(null, i) failed with i = " + i
+ " returned value = " + value
;
45 var value
= addArgsInt32AndNull(i
, null);
47 throw "addArgsInt32AndNull(i, null) failed with i = " + i
+ " returned value = " + value
;
49 var value
= addArgsInt32AndNull(null, null);
51 throw "addArgsInt32AndNull(null, null) failed with i = " + i
+ " returned value = " + value
;
54 function testFallbackWithDouble() {
55 var value
= addArgsNumberAndNull(Math
.PI
, Math
.PI
);
56 if (value
!== 2 * Math
.PI
)
57 throw "addArgsNumberAndNull(Math.PI, Math.PI) failed with i = " + i
+ " returned value = " + value
;
59 testFallbackWithDouble();
62 // Using full number + null for math.
63 function addArgsDoubleAndNull(a
, b
) {
66 noInline(addArgsDoubleAndNull
);
68 for (var i
= 0; i
< 1e4
; ++i
) {
69 var value
= addArgsDoubleAndNull(0.5, i
);
70 if (value
!== (i
+ 0.5))
71 throw "addArgsDoubleAndNull(0.5, i) failed with i = " + i
+ " returned value = " + value
;
73 var value
= addArgsDoubleAndNull(null, 0.1);
75 throw "addArgsDoubleAndNull(null, i) failed with i = " + i
+ " returned value = " + value
;
77 var value
= addArgsDoubleAndNull(0.6, null);
79 throw "addArgsDoubleAndNull(i, null) failed with i = " + i
+ " returned value = " + value
;
82 function testFallbackWithObject() {
83 var value
= addArgsDoubleAndNull(Math
.PI
, { valueOf: function() { return 5; }});
84 if (value
!== 5 + Math
.PI
)
85 throw "addArgsDoubleAndNull(Math.PI, { valueOf: function() { return 5; }}) failed with i = " + i
+ " returned value = " + value
;
87 testFallbackWithObject();
91 function addArgsOnlyNull(a
, b
) {
94 noInline(addArgsOnlyNull
);
96 for (var i
= 0; i
< 1e4
; ++i
) {
97 var value
= addArgsOnlyNull(null, null);
99 throw "addArgsOnlyNull(null, null) failed with i = " + i
+ " returned value = " + value
;
102 function testFallbackWithString() {
103 var value
= addArgsOnlyNull("foo", "bar");
104 if (value
!== "foobar")
105 throw "addArgsOnlyNull(\"foo\", \"bar\") failed with i = " + i
+ " returned value = " + value
;
107 testFallbackWithString();