]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/double-rep-with-null.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / double-rep-with-null.js
CommitLineData
ed1e77d3
A
1// Using full number + null for math.
2function addArgsNumberAndNull(a, b) {
3 return a + b;
4}
5noInline(addArgsNumberAndNull);
6
7for (var i = 0; i < 1e4; ++i) {
8 var value = addArgsNumberAndNull(i, 1);
9 if (value !== (i + 1))
10 throw "addArgsNumberAndNull(i, 1) failed with i = " + i + " returned value = " + value;
11
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;
15
16 var value = addArgsNumberAndNull(null, i);
17 if (value !== i)
18 throw "addArgsNumberAndNull(null, i) failed with i = " + i + " returned value = " + value;
19
20 var value = addArgsNumberAndNull(i, null);
21 if (value !== i)
22 throw "addArgsNumberAndNull(i, null) failed with i = " + i + " returned value = " + value;
23
24 var value = addArgsNumberAndNull(null, null);
25 if (value !== 0)
26 throw "addArgsNumberAndNull(null, null) failed with i = " + i + " returned value = " + value;
27}
28
29
30// Using int32 + null for math.
31function addArgsInt32AndNull(a, b) {
32 return a + b;
33}
34noInline(addArgsInt32AndNull);
35
36for (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;
40
41 var value = addArgsInt32AndNull(null, i);
42 if (value !== i)
43 throw "addArgsInt32AndNull(null, i) failed with i = " + i + " returned value = " + value;
44
45 var value = addArgsInt32AndNull(i, null);
46 if (value !== i)
47 throw "addArgsInt32AndNull(i, null) failed with i = " + i + " returned value = " + value;
48
49 var value = addArgsInt32AndNull(null, null);
50 if (value !== 0)
51 throw "addArgsInt32AndNull(null, null) failed with i = " + i + " returned value = " + value;
52}
53
54function 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;
58}
59testFallbackWithDouble();
60
61
62// Using full number + null for math.
63function addArgsDoubleAndNull(a, b) {
64 return a + b;
65}
66noInline(addArgsDoubleAndNull);
67
68for (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;
72
73 var value = addArgsDoubleAndNull(null, 0.1);
74 if (value !== 0.1)
75 throw "addArgsDoubleAndNull(null, i) failed with i = " + i + " returned value = " + value;
76
77 var value = addArgsDoubleAndNull(0.6, null);
78 if (value !== 0.6)
79 throw "addArgsDoubleAndNull(i, null) failed with i = " + i + " returned value = " + value;
80}
81
82function 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;
86}
87testFallbackWithObject();
88
89
90// Using only null
91function addArgsOnlyNull(a, b) {
92 return a + b;
93}
94noInline(addArgsOnlyNull);
95
96for (var i = 0; i < 1e4; ++i) {
97 var value = addArgsOnlyNull(null, null);
98 if (value !== 0)
99 throw "addArgsOnlyNull(null, null) failed with i = " + i + " returned value = " + value;
100}
101
102function testFallbackWithString() {
103 var value = addArgsOnlyNull("foo", "bar");
104 if (value !== "foobar")
105 throw "addArgsOnlyNull(\"foo\", \"bar\") failed with i = " + i + " returned value = " + value;
106}
107testFallbackWithString();