js/src/jit-test/tests/ion/condswitch.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // This test case is made to be run with --ion-eager.
michael@0 2
michael@0 3 function ret2() {
michael@0 4 return 2;
michael@0 5 }
michael@0 6
michael@0 7 // Check with default case in the middle.
michael@0 8 function test0(x) {
michael@0 9 var res = 0;
michael@0 10 switch (x) {
michael@0 11 case (res |= 0x40, 1): // x === 1
michael@0 12 res |= 0x1;
michael@0 13 default: // otherwise
michael@0 14 res |= 0x2;
michael@0 15 case (res |= 0x80, ret2()): // x === 2
michael@0 16 res |= 0x4;
michael@0 17 case (res |= 0x100, 1 + ret2()): // x === 3
michael@0 18 res |= 0x8;
michael@0 19 break;
michael@0 20 case (res |= 0x200, 0): // x === 0
michael@0 21 res |= 0x10;
michael@0 22 }
michael@0 23 res |= 0x20;
michael@0 24 return res;
michael@0 25 }
michael@0 26
michael@0 27 assertEq(test0(0), 0x40 | 0x80 | 0x100 | 0x200 | 0x10 | 0x20);
michael@0 28 assertEq(test0(1), 0x40 | 0x1 | 0x2 | 0x4 | 0x8 | 0x20);
michael@0 29 assertEq(test0(2), 0x40 | 0x80 | 0x4 | 0x8 | 0x20);
michael@0 30 assertEq(test0(3), 0x40 | 0x80 | 0x100 | 0x8 | 0x20);
michael@0 31 assertEq(test0(4), 0x40 | 0x80 | 0x100 | 0x200 | 0x2 | 0x4 | 0x8 | 0x20);
michael@0 32
michael@0 33 // Check with no default and only one case.
michael@0 34 function test1(x) {
michael@0 35 var res = 0;
michael@0 36 switch (x) {
michael@0 37 case (res |= 0x1, ret2()): // x === 2
michael@0 38 res |= 0x2;
michael@0 39 }
michael@0 40 res |= 0x4;
michael@0 41 return res;
michael@0 42 }
michael@0 43
michael@0 44 assertEq(test1(1), 0x1 | 0x4); // default.
michael@0 45 assertEq(test1(2), 0x1 | 0x2 | 0x4); // case.
michael@0 46
michael@0 47 // Check with default case identical to a case.
michael@0 48 function test2(x) {
michael@0 49 var res = 0;
michael@0 50 switch (x) {
michael@0 51 case (res |= 0x1, 0):
michael@0 52 res |= 0x10;
michael@0 53 break;
michael@0 54 default:
michael@0 55 case (res |= 0x2, 1):
michael@0 56 res |= 0x20;
michael@0 57 break;
michael@0 58 case (res |= 0x4, ret2()): // x === 2
michael@0 59 res |= 0x40;
michael@0 60 }
michael@0 61 res |= 0x100;
michael@0 62 return res;
michael@0 63 }
michael@0 64
michael@0 65 assertEq(test2(0), 0x1 | 0x10 | 0x100);
michael@0 66 assertEq(test2(1), 0x1 | 0x2 | 0x20 | 0x100);
michael@0 67 assertEq(test2(2), 0x1 | 0x2 | 0x4 | 0x40 | 0x100);
michael@0 68 assertEq(test2(3), 0x1 | 0x2 | 0x4 | 0x20 | 0x100);
michael@0 69
michael@0 70 // Check a non-break, non-empty default at the end.
michael@0 71 function test3(x) {
michael@0 72 var res = 0;
michael@0 73 switch (x) {
michael@0 74 case (res |= 0x1, 1):
michael@0 75 res |= 0x10;
michael@0 76 case (res |= 0x2, ret2()): // x === 2
michael@0 77 res |= 0x20;
michael@0 78 default:
michael@0 79 res |= 0x40;
michael@0 80 }
michael@0 81 res |= 0x100;
michael@0 82 return res;
michael@0 83 }
michael@0 84
michael@0 85 assertEq(test3(1), 0x1 | 0x10 | 0x20 | 0x40 | 0x100);
michael@0 86 assertEq(test3(2), 0x1 | 0x2 | 0x20 | 0x40 | 0x100);
michael@0 87 assertEq(test3(3), 0x1 | 0x2 | 0x40 | 0x100);
michael@0 88
michael@0 89 // Check cfg in condition of non-last case with no break. (reverse post order failure ?)
michael@0 90 function test4(x) {
michael@0 91 var res = 0;
michael@0 92 switch (x) {
michael@0 93 case (res |= 0x1, (x ? 1 : 0)):
michael@0 94 res |= 0x10;
michael@0 95 case (res |= 0x2, ret2()): // x === 2
michael@0 96 res |= 0x20;
michael@0 97 }
michael@0 98 res |= 0x100;
michael@0 99 return res;
michael@0 100 }
michael@0 101
michael@0 102 assertEq(test4(0), 0x1 | 0x10 | 0x20 | 0x100);
michael@0 103 assertEq(test4(1), 0x1 | 0x10 | 0x20 | 0x100);
michael@0 104 assertEq(test4(2), 0x1 | 0x2 | 0x20 | 0x100);

mercurial