michael@0: // This test case is made to be run with --ion-eager. michael@0: michael@0: function ret2() { michael@0: return 2; michael@0: } michael@0: michael@0: // Check with default case in the middle. michael@0: function test0(x) { michael@0: var res = 0; michael@0: switch (x) { michael@0: case (res |= 0x40, 1): // x === 1 michael@0: res |= 0x1; michael@0: default: // otherwise michael@0: res |= 0x2; michael@0: case (res |= 0x80, ret2()): // x === 2 michael@0: res |= 0x4; michael@0: case (res |= 0x100, 1 + ret2()): // x === 3 michael@0: res |= 0x8; michael@0: break; michael@0: case (res |= 0x200, 0): // x === 0 michael@0: res |= 0x10; michael@0: } michael@0: res |= 0x20; michael@0: return res; michael@0: } michael@0: michael@0: assertEq(test0(0), 0x40 | 0x80 | 0x100 | 0x200 | 0x10 | 0x20); michael@0: assertEq(test0(1), 0x40 | 0x1 | 0x2 | 0x4 | 0x8 | 0x20); michael@0: assertEq(test0(2), 0x40 | 0x80 | 0x4 | 0x8 | 0x20); michael@0: assertEq(test0(3), 0x40 | 0x80 | 0x100 | 0x8 | 0x20); michael@0: assertEq(test0(4), 0x40 | 0x80 | 0x100 | 0x200 | 0x2 | 0x4 | 0x8 | 0x20); michael@0: michael@0: // Check with no default and only one case. michael@0: function test1(x) { michael@0: var res = 0; michael@0: switch (x) { michael@0: case (res |= 0x1, ret2()): // x === 2 michael@0: res |= 0x2; michael@0: } michael@0: res |= 0x4; michael@0: return res; michael@0: } michael@0: michael@0: assertEq(test1(1), 0x1 | 0x4); // default. michael@0: assertEq(test1(2), 0x1 | 0x2 | 0x4); // case. michael@0: michael@0: // Check with default case identical to a case. michael@0: function test2(x) { michael@0: var res = 0; michael@0: switch (x) { michael@0: case (res |= 0x1, 0): michael@0: res |= 0x10; michael@0: break; michael@0: default: michael@0: case (res |= 0x2, 1): michael@0: res |= 0x20; michael@0: break; michael@0: case (res |= 0x4, ret2()): // x === 2 michael@0: res |= 0x40; michael@0: } michael@0: res |= 0x100; michael@0: return res; michael@0: } michael@0: michael@0: assertEq(test2(0), 0x1 | 0x10 | 0x100); michael@0: assertEq(test2(1), 0x1 | 0x2 | 0x20 | 0x100); michael@0: assertEq(test2(2), 0x1 | 0x2 | 0x4 | 0x40 | 0x100); michael@0: assertEq(test2(3), 0x1 | 0x2 | 0x4 | 0x20 | 0x100); michael@0: michael@0: // Check a non-break, non-empty default at the end. michael@0: function test3(x) { michael@0: var res = 0; michael@0: switch (x) { michael@0: case (res |= 0x1, 1): michael@0: res |= 0x10; michael@0: case (res |= 0x2, ret2()): // x === 2 michael@0: res |= 0x20; michael@0: default: michael@0: res |= 0x40; michael@0: } michael@0: res |= 0x100; michael@0: return res; michael@0: } michael@0: michael@0: assertEq(test3(1), 0x1 | 0x10 | 0x20 | 0x40 | 0x100); michael@0: assertEq(test3(2), 0x1 | 0x2 | 0x20 | 0x40 | 0x100); michael@0: assertEq(test3(3), 0x1 | 0x2 | 0x40 | 0x100); michael@0: michael@0: // Check cfg in condition of non-last case with no break. (reverse post order failure ?) michael@0: function test4(x) { michael@0: var res = 0; michael@0: switch (x) { michael@0: case (res |= 0x1, (x ? 1 : 0)): michael@0: res |= 0x10; michael@0: case (res |= 0x2, ret2()): // x === 2 michael@0: res |= 0x20; michael@0: } michael@0: res |= 0x100; michael@0: return res; michael@0: } michael@0: michael@0: assertEq(test4(0), 0x1 | 0x10 | 0x20 | 0x100); michael@0: assertEq(test4(1), 0x1 | 0x10 | 0x20 | 0x100); michael@0: assertEq(test4(2), 0x1 | 0x2 | 0x20 | 0x100);