OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 22 matching lines...) Expand all Loading... |
33 v.valueOf = vv; | 33 v.valueOf = vv; |
34 w.valueOf = ww; | 34 w.valueOf = ww; |
35 assertEquals(1, Math.min(v,w)); | 35 assertEquals(1, Math.min(v,w)); |
36 assertEquals("hestfisk", x, "min"); | 36 assertEquals("hestfisk", x, "min"); |
37 | 37 |
38 x = ""; | 38 x = ""; |
39 assertEquals(2, Math.max(v,w)); | 39 assertEquals(2, Math.max(v,w)); |
40 assertEquals("hestfisk", x, "max"); | 40 assertEquals("hestfisk", x, "max"); |
41 | 41 |
42 x = ""; | 42 x = ""; |
| 43 assertEquals(1, Math.max(v,v)); |
| 44 assertEquals("hesthest", x, "max_identical"); |
| 45 |
| 46 x = ""; |
| 47 assertEquals(2, Math.min(w,w)); |
| 48 assertEquals("fiskfisk", x, "max"); |
| 49 |
| 50 x = ""; |
43 assertEquals(Math.atan2(1, 2), Math.atan2(v, w)); | 51 assertEquals(Math.atan2(1, 2), Math.atan2(v, w)); |
44 // JSC says fiskhest. | 52 // JSC says fiskhest. |
45 assertEquals("hestfisk", x, "atan2"); | 53 assertEquals("hestfisk", x, "atan2"); |
46 | 54 |
47 x = ""; | 55 x = ""; |
48 assertEquals(1, Math.pow(v, w)); | 56 assertEquals(1, Math.pow(v, w)); |
49 assertEquals("hestfisk", x, "pow"); | 57 assertEquals("hestfisk", x, "pow"); |
50 | 58 |
51 var year = { valueOf: function() { x += 1; return 2007; } }; | 59 var year = { valueOf: function() { x += 1; return 2007; } }; |
52 var month = { valueOf: function() { x += 2; return 2; } }; | 60 var month = { valueOf: function() { x += 2; return 2; } }; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 assertEquals("23", x, "Date.setUTCMonth"); | 123 assertEquals("23", x, "Date.setUTCMonth"); |
116 | 124 |
117 x = ""; | 125 x = ""; |
118 new Date().setFullYear(year, month, date, hours, minutes, seconds, ms); | 126 new Date().setFullYear(year, month, date, hours, minutes, seconds, ms); |
119 assertEquals("123", x, "Date.setFullYear"); | 127 assertEquals("123", x, "Date.setFullYear"); |
120 | 128 |
121 x = ""; | 129 x = ""; |
122 new Date().setUTCFullYear(year, month, date, hours, minutes, seconds, ms); | 130 new Date().setUTCFullYear(year, month, date, hours, minutes, seconds, ms); |
123 assertEquals("123", x, "Date.setUTCFullYear"); | 131 assertEquals("123", x, "Date.setUTCFullYear"); |
124 | 132 |
| 133 x = ""; |
125 var a = { valueOf: function() { x += "hest"; return 97; } }; | 134 var a = { valueOf: function() { x += "hest"; return 97; } }; |
126 var b = { valueOf: function() { x += "fisk"; return 98; } }; | 135 var b = { valueOf: function() { x += "fisk"; return 98; } }; |
127 assertEquals("ab", String.fromCharCode(a, b), "String.fromCharCode"); | 136 assertEquals("ab", String.fromCharCode(a, b), "String.fromCharCode"); |
| 137 assertEquals("hestfisk", x, "String.fromCharCode valueOf order"); |
| 138 |
| 139 |
| 140 |
| 141 // Test whether valueOf is called when comparing identical objects |
| 142 x = ""; |
| 143 assertTrue(a < b, "Compare objects a < b"); |
| 144 assertEquals("hestfisk", x, "Compare objects a < b valueOf order"); |
| 145 |
| 146 x = ""; |
| 147 assertFalse(a < a, "Compare objects a < a"); |
| 148 // assertEquals("hesthest", x, "Compare objects a < a valueOf order"); |
| 149 |
| 150 x = ""; |
| 151 assertTrue(a == a, "Compare objects a == a"); |
| 152 assertEquals("", x, "Compare objects a == a valueOf not called"); |
| 153 |
| 154 x = ""; |
| 155 assertFalse(b > b, "Compare objects b > b"); |
| 156 assertEquals("fiskfisk", x, "Compare objects b > b valueOf order"); |
| 157 |
| 158 x = ""; |
| 159 assertTrue(b >= b, "Compare objects b >= b"); |
| 160 assertEquals("fiskfisk", x, "Compare objects b >= b valueOf order"); |
| 161 |
| 162 x = ""; |
| 163 assertFalse(a > b, "Compare objects a > b"); |
| 164 assertEquals("fiskhest", x, "Compare objects a > b valueOf order"); |
| 165 |
| 166 x = ""; |
| 167 assertFalse(a > void(0), "Compare objects a > undefined"); |
| 168 assertEquals("hest", x, "Compare objects a > undefined valueOf order"); |
| 169 |
| 170 x = ""; |
| 171 assertFalse(void(0) > b, "Compare objects undefined > b"); |
| 172 assertEquals("fisk", x, "Compare objects undefined > b valueOf order"); |
| 173 |
| 174 |
| 175 function identical_object_comparison() { |
| 176 x = ""; |
| 177 assertTrue(a < b, "Compare objects a < b"); |
| 178 assertEquals("hestfisk", x, "Compare objects a < b valueOf order"); |
| 179 |
| 180 x = ""; |
| 181 assertFalse(a < a, "Compare objects a < a"); |
| 182 // assertEquals("hesthest", x, "Compare objects a < a valueOf order"); |
| 183 |
| 184 x = ""; |
| 185 assertTrue(a == a, "Compare objects a == a"); |
| 186 assertEquals("", x, "Compare objects a == a valueOf not called"); |
| 187 |
| 188 x = ""; |
| 189 assertFalse(b > b, "Compare objects b > b"); |
| 190 assertEquals("fiskfisk", x, "Compare objects b > b valueOf order"); |
| 191 |
| 192 x = ""; |
| 193 assertTrue(b >= b, "Compare objects b >= b"); |
| 194 assertEquals("fiskfisk", x, "Compare objects b >= b valueOf order"); |
| 195 |
| 196 x = ""; |
| 197 assertFalse(a > b, "Compare objects a > b"); |
| 198 assertEquals("fiskhest", x, "Compare objects a > b valueOf order"); |
| 199 |
| 200 x = ""; |
| 201 assertFalse(a > void(0), "Compare objects a > undefined"); |
| 202 assertEquals("hest", x, "Compare objects a > undefined valueOf order"); |
| 203 |
| 204 x = ""; |
| 205 assertFalse(void(0) > b, "Compare objects undefined > b"); |
| 206 assertEquals("fisk", x, "Compare objects undefined > b valueOf order"); |
| 207 } |
| 208 |
| 209 // Call inside loop to test optimization and possible caching. |
| 210 for (i = 0; i < 3; ++i) { |
| 211 identical_object_comparison(); |
| 212 } |
| 213 |
128 | 214 |
129 print("ok"); | 215 print("ok"); |
OLD | NEW |