| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 var r; | 47 var r; |
| 48 switch (x) { | 48 switch (x) { |
| 49 case 0: | 49 case 0: |
| 50 r = "zero"; | 50 r = "zero"; |
| 51 break; | 51 break; |
| 52 case 1: | 52 case 1: |
| 53 r = "one"; | 53 r = "one"; |
| 54 break; | 54 break; |
| 55 case 2: | 55 case 2: |
| 56 r = "two"; | 56 r = "two"; |
| 57 break | 57 break; |
| 58 case 3: | 58 case 3: |
| 59 r = "three"; | 59 r = "three"; |
| 60 break; | 60 break; |
| 61 default: | 61 default: |
| 62 r = "default"; | 62 r = "default"; |
| 63 } | 63 } |
| 64 return r; | 64 return r; |
| 65 } | 65 } |
| 66 | 66 |
| 67 assertEquals("zero", f2(0), "0-1-switch.0"); | 67 assertEquals("zero", f2(0), "0-1-switch.0"); |
| 68 assertEquals("one", f2(1), "0-1-switch.1"); | 68 assertEquals("one", f2(1), "0-1-switch.1"); |
| 69 assertEquals("default", f2(7), "0-1-switch.2"); | 69 assertEquals("default", f2(7), "0-1-switch.2"); |
| 70 assertEquals("default", f2(-1), "0-1-switch.-1"); | 70 assertEquals("default", f2(-1), "0-1-switch.-1"); |
| 71 assertEquals("default", f2(NaN), "0-1-switch.NaN"); | 71 assertEquals("default", f2(NaN), "0-1-switch.NaN"); |
| 72 assertEquals("default", f2(Math.pow(2,34)), "0-1-switch.largeNum"); |
| 73 assertEquals("default", f2("0"), "0-1-switch.string"); |
| 74 assertEquals("default", f2(false), "0-1-switch.bool"); |
| 75 assertEquals("default", f2(null), "0-1-switch.null"); |
| 76 assertEquals("default", f2(undefined), "0-1-switch.undef"); |
| 77 assertEquals("default", f2(new Number(2)), "0-1-switch.undef"); |
| 78 assertEquals("default", f2({valueOf: function(){return 2; }}), "0-1-switch.obj")
; |
| 72 | 79 |
| 73 | 80 |
| 74 function f3(x, c) { | 81 function f3(x, c) { |
| 75 var r = 0; | 82 var r = 0; |
| 76 switch (x) { | 83 switch (x) { |
| 77 default: | 84 default: |
| 78 r = "default"; | 85 r = "default"; |
| 79 break; | 86 break; |
| 80 case c: | 87 case c: |
| 81 r = "value is c = " + c; | 88 r = "value is c = " + c; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 107 x++; | 114 x++; |
| 108 default: | 115 default: |
| 109 x++; | 116 x++; |
| 110 case 2: | 117 case 2: |
| 111 x++; | 118 x++; |
| 112 } | 119 } |
| 113 return x; | 120 return x; |
| 114 } | 121 } |
| 115 | 122 |
| 116 | 123 |
| 117 assertEquals(3, f4(0), "fallthrough-switch.0") | 124 assertEquals(3, f4(0), "fallthrough-switch.0"); |
| 118 assertEquals(3, f4(1), "fallthrough-switch.1") | 125 assertEquals(3, f4(1), "fallthrough-switch.1"); |
| 119 assertEquals(3, f4(2), "fallthrough-switch.2") | 126 assertEquals(3, f4(2), "fallthrough-switch.2"); |
| 120 assertEquals(5, f4(3), "fallthrough-switch.3") | 127 assertEquals(5, f4(3), "fallthrough-switch.3"); |
| 121 | 128 |
| 122 | 129 |
| 123 function f5(x) { | 130 function f5(x) { |
| 124 switch(x) { | 131 switch(x) { |
| 125 case -2: return true; | 132 case -2: return true; |
| 126 case -1: return false; | 133 case -1: return false; |
| 127 case 0: return true; | 134 case 0: return true; |
| 128 case 2: return false; | 135 case 2: return false; |
| 129 default: return 42; | 136 default: return 42; |
| 130 } | 137 } |
| 131 } | 138 } |
| 132 | 139 |
| 133 assertTrue(f5(-2), "negcase.-2") | 140 assertTrue(f5(-2), "negcase.-2"); |
| 134 assertFalse(f5(-1), "negcase.-1") | 141 assertFalse(f5(-1), "negcase.-1"); |
| 135 assertTrue(f5(0), "negcase.-0") | 142 assertTrue(f5(0), "negcase.-0"); |
| 136 assertEquals(42, f5(1), "negcase.1") | 143 assertEquals(42, f5(1), "negcase.1"); |
| 137 assertFalse(f5(2), "negcase.2") | 144 assertFalse(f5(2), "negcase.2"); |
| 138 | 145 |
| 139 function f6(N) { | 146 function f6(N) { |
| 140 // long enough case that code buffer grows while it is code-generated. | 147 // long enough case that code buffer grows during code-generation |
| 141 var res = 0; | 148 var res = 0; |
| 142 for(var i = 0; i < N; i++) { | 149 for(var i = 0; i < N; i++) { |
| 143 switch(i & 0x3f) { | 150 switch(i & 0x3f) { |
| 144 case 0: res += 0; break; | 151 case 0: res += 0; break; |
| 145 case 1: res += 1; break; | 152 case 1: res += 1; break; |
| 146 case 2: res += 2; break; | 153 case 2: res += 2; break; |
| 147 case 3: res += 3; break; | 154 case 3: res += 3; break; |
| 148 case 4: res += 4; break; | 155 case 4: res += 4; break; |
| 149 case 5: res += 5; break; | 156 case 5: res += 5; break; |
| 150 case 6: res += 6; break; | 157 case 6: res += 6; break; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 217 } |
| 211 } | 218 } |
| 212 return res; | 219 return res; |
| 213 } | 220 } |
| 214 | 221 |
| 215 assertEquals(190, f6(20), "largeSwitch.20"); | 222 assertEquals(190, f6(20), "largeSwitch.20"); |
| 216 assertEquals(2016, f6(64), "largeSwitch.64"); | 223 assertEquals(2016, f6(64), "largeSwitch.64"); |
| 217 assertEquals(4032, f6(128), "largeSwitch.128"); | 224 assertEquals(4032, f6(128), "largeSwitch.128"); |
| 218 assertEquals(4222, f6(148), "largeSwitch.148"); | 225 assertEquals(4222, f6(148), "largeSwitch.148"); |
| 219 | 226 |
| 220 | 227 |
| OLD | NEW |