| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 case 64: break; | 215 case 64: break; |
| 216 default: break; | 216 default: break; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 return res; | 219 return res; |
| 220 } | 220 } |
| 221 | 221 |
| 222 assertEquals(190, f6(20), "largeSwitch.20"); | 222 assertEquals(190, f6(20), "largeSwitch.20"); |
| 223 assertEquals(2016, f6(64), "largeSwitch.64"); | 223 assertEquals(2016, f6(64), "largeSwitch.64"); |
| 224 assertEquals(4032, f6(128), "largeSwitch.128"); | 224 assertEquals(4032, f6(128), "largeSwitch.128"); |
| 225 assertEquals(4222, f6(148), "largeSwitch.148"); | 225 assertEquals(4222, f6(148), "largeSwitch.148"); |
| 226 | 226 |
| 227 | 227 |
| 228 function f7(value) { | 228 function f7(value) { |
| 229 switch (value) { | 229 switch (value) { |
| 230 case 0: return "0"; | 230 case 0: return "0"; |
| 231 case -0: return "-0"; | 231 case -0: return "-0"; |
| 232 case 1: case 2: case 3: case 4: // Dummy fillers. | 232 case 1: case 2: case 3: case 4: // Dummy fillers. |
| 233 } | 233 } |
| 234 switch (value) { | 234 switch (value) { |
| 235 case 0x3fffffff: return "MaxSmi"; | 235 case 0x3fffffff: return "MaxSmi"; |
| 236 case 0x3ffffffe: | 236 case 0x3ffffffe: |
| 237 case 0x3ffffffd: | 237 case 0x3ffffffd: |
| 238 case 0x3ffffffc: | 238 case 0x3ffffffc: |
| 239 case 0x3ffffffb: | 239 case 0x3ffffffb: |
| 240 case 0x3ffffffa: // Dummy fillers | 240 case 0x3ffffffa: // Dummy fillers |
| 241 } | 241 } |
| 242 switch (value) { | 242 switch (value) { |
| 243 case -0x40000000: return "MinSmi"; | 243 case -0x40000000: return "MinSmi"; |
| 244 case -0x3fffffff: | 244 case -0x3fffffff: |
| 245 case -0x3ffffffe: | 245 case -0x3ffffffe: |
| 246 case -0x3ffffffd: | 246 case -0x3ffffffd: |
| 247 case -0x3ffffffc: | 247 case -0x3ffffffc: |
| 248 case -0x3ffffffb: // Dummy fillers | 248 case -0x3ffffffb: // Dummy fillers |
| 249 } | 249 } |
| 250 switch (value) { | 250 switch (value) { |
| 251 case 10: return "A"; | 251 case 10: return "A"; |
| 252 case 11: | 252 case 11: |
| 253 case 12: | 253 case 12: |
| 254 case 13: | 254 case 13: |
| 255 case 14: | 255 case 14: |
| 256 case 15: // Dummy fillers | 256 case 15: // Dummy fillers |
| 257 } | 257 } |
| 258 return "default"; | 258 return "default"; |
| 259 } | 259 } |
| 260 | 260 |
| 261 | 261 |
| 262 assertEquals("default", f7(0.1), "0-1-switch.double-0.1"); | 262 assertEquals("default", f7(0.1), "0-1-switch.double-0.1"); |
| 263 assertEquals("0", f7(-0), "0-1-switch.double-neg0"); | 263 assertEquals("0", f7(-0), "0-1-switch.double-neg0"); |
| 264 assertEquals("MaxSmi", f7((1<<30)-1), "0-1-switch.maxsmi"); | 264 assertEquals("MaxSmi", f7((1<<30)-1), "0-1-switch.maxsmi"); |
| 265 assertEquals("MinSmi", f7(-(1<<30)), "0-1-switch.minsmi"); | 265 assertEquals("MinSmi", f7(-(1<<30)), "0-1-switch.minsmi"); |
| 266 assertEquals("default", f7(1<<30), "0-1-switch.maxsmi++"); | 266 assertEquals("default", f7(1<<30), "0-1-switch.maxsmi++"); |
| 267 assertEquals("default", f7(-(1<<30)-1), "0-1-switch.minsmi--"); | 267 assertEquals("default", f7(-(1<<30)-1), "0-1-switch.minsmi--"); |
| 268 assertEquals("A", f7((170/16)-(170%16/16)), "0-1-switch.heapnum"); | 268 assertEquals("A", f7((170/16)-(170%16/16)), "0-1-switch.heapnum"); |
| 269 | 269 |
| 270 | 270 |
| 271 function makeVeryLong(length) { | 271 function makeVeryLong(length) { |
| 272 var res = "function() {\n" + | 272 var res = "function() {\n" + |
| 273 " var res = 0;\n" + | 273 " var res = 0;\n" + |
| 274 " for (var i = 0; i <= " + length + "; i++) {\n" + | 274 " for (var i = 0; i <= " + length + "; i++) {\n" + |
| 275 " switch(i) {\n"; | 275 " switch(i) {\n"; |
| 276 for (var i = 0; i < length; i++) { | 276 for (var i = 0; i < length; i++) { |
| 277 res += " case " + i + ": res += 2; break;\n"; | 277 res += " case " + i + ": res += 2; break;\n"; |
| 278 } | 278 } |
| 279 res += " default: res += 1;\n" + | 279 res += " default: res += 1;\n" + |
| 280 " }\n" + | 280 " }\n" + |
| 281 " }\n" + | 281 " }\n" + |
| 282 " return res;\n" + | 282 " return res;\n" + |
| 283 "}"; | 283 "}"; |
| 284 return eval(res); | 284 return eval(res); |
| 285 } | 285 } |
| 286 var verylong_size = 1000; | 286 var verylong_size = 1000; |
| 287 var verylong = makeVeryLong(verylong_size); | 287 var verylong = makeVeryLong(verylong_size); |
| 288 | 288 |
| 289 assertEquals(verylong_size * 2 + 1, verylong()); | 289 assertEquals(verylong_size * 2 + 1, verylong()); |
| OLD | NEW |