OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 (function TestSwitch0() { | 7 (function TestSwitch0() { |
8 function asmModule() { | 8 function asmModule() { |
9 "use asm" | 9 "use asm" |
10 | 10 |
11 function caller() { | 11 function caller() { |
12 var ret = 0; | 12 var ret = 0; |
13 var x = 7; | 13 var x = 7; |
14 switch (x) { | 14 switch (x|0) { |
15 case 1: { | 15 case 1: { |
16 return 0; | 16 return 0; |
17 } | 17 } |
18 case 7: { | 18 case 7: { |
19 ret = 5; | 19 ret = 5; |
20 break; | 20 break; |
21 } | 21 } |
22 default: return 0; | 22 default: return 0; |
23 } | 23 } |
24 return ret|0; | 24 return ret|0; |
25 } | 25 } |
26 | 26 |
27 return {caller:caller}; | 27 return {caller:caller}; |
28 } | 28 } |
29 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 29 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
30 assertEquals(5, wasm.caller()); | 30 assertEquals(5, wasm.caller()); |
31 })(); | 31 })(); |
32 | 32 |
33 (function TestSwitch() { | 33 (function TestSwitch() { |
34 function asmModule() { | 34 function asmModule() { |
35 "use asm" | 35 "use asm" |
36 | 36 |
37 function caller() { | 37 function caller() { |
38 var ret = 0; | 38 var ret = 0; |
39 var x = 7; | 39 var x = 7; |
40 switch (x) { | 40 switch (x|0) { |
41 case 1: return 0; | 41 case 1: return 0; |
42 case 7: { | 42 case 7: { |
43 ret = 12; | 43 ret = 12; |
44 break; | 44 break; |
45 } | 45 } |
46 default: return 0; | 46 default: return 0; |
47 } | 47 } |
48 switch (x) { | 48 switch (x|0) { |
49 case 1: return 0; | 49 case 1: return 0; |
50 case 8: return 0; | 50 case 8: return 0; |
51 default: ret = (ret + 11)|0; | 51 default: ret = (ret + 11)|0; |
52 } | 52 } |
53 return ret|0; | 53 return ret|0; |
54 } | 54 } |
55 | 55 |
56 return {caller:caller}; | 56 return {caller:caller}; |
57 } | 57 } |
58 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 58 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
59 assertEquals(23, wasm.caller()); | 59 assertEquals(23, wasm.caller()); |
60 })(); | 60 })(); |
61 | 61 |
62 (function TestSwitchFallthrough() { | 62 (function TestSwitchFallthrough() { |
63 function asmModule() { | 63 function asmModule() { |
64 "use asm" | 64 "use asm" |
65 | 65 |
66 function caller() { | 66 function caller() { |
67 var x = 17; | 67 var x = 17; |
68 var ret = 0; | 68 var ret = 0; |
69 switch (x) { | 69 switch (x|0) { |
70 case 17: | 70 case 17: |
71 case 14: ret = 39; | 71 case 14: ret = 39; |
72 case 1: ret = (ret + 3)|0; | 72 case 1: ret = (ret + 3)|0; |
73 case 4: break; | 73 case 4: break; |
74 default: ret = (ret + 1)|0; | 74 default: ret = (ret + 1)|0; |
75 } | 75 } |
76 return ret|0; | 76 return ret|0; |
77 } | 77 } |
78 | 78 |
79 return {caller:caller}; | 79 return {caller:caller}; |
80 } | 80 } |
81 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 81 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
82 assertEquals(42, wasm.caller()); | 82 assertEquals(42, wasm.caller()); |
83 })(); | 83 })(); |
84 | 84 |
85 (function TestNestedSwitch() { | 85 (function TestNestedSwitch() { |
86 function asmModule() { | 86 function asmModule() { |
87 "use asm" | 87 "use asm" |
88 | 88 |
89 function caller() { | 89 function caller() { |
90 var x = 3; | 90 var x = 3; |
91 var y = -13; | 91 var y = -13; |
92 switch (x) { | 92 switch (x|0) { |
93 case 1: return 0; | 93 case 1: return 0; |
94 case 3: { | 94 case 3: { |
95 switch (y) { | 95 switch (y|0) { |
96 case 2: return 0; | 96 case 2: return 0; |
97 case -13: return 43; | 97 case -13: return 43; |
98 default: return 0; | 98 default: return 0; |
99 } | 99 } |
100 } | 100 } |
101 default: return 0; | 101 default: return 0; |
102 } | 102 } |
103 return 0; | 103 return 0; |
104 } | 104 } |
105 | 105 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 if (k != 56) return "break;"; | 459 if (k != 56) return "break;"; |
460 else return "return 23;"; | 460 else return "return 23;"; |
461 } | 461 } |
462 wasm = LargeSwitchGenerator(0, 638, 2, handle_case); | 462 wasm = LargeSwitchGenerator(0, 638, 2, handle_case); |
463 for (var i = 0; i <= 638; i = i + 2) { | 463 for (var i = 0; i <= 638; i = i + 2) { |
464 if (i == 56) assertEquals(23, wasm.main(i)); | 464 if (i == 56) assertEquals(23, wasm.main(i)); |
465 else assertEquals(-2, wasm.main(i)); | 465 else assertEquals(-2, wasm.main(i)); |
466 } | 466 } |
467 assertEquals(-1, wasm.main(-1)); | 467 assertEquals(-1, wasm.main(-1)); |
468 })(); | 468 })(); |
OLD | NEW |