Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | var typedSwitch0 = function (a) { |
michael@0 | 2 | switch (a) { |
michael@0 | 3 | case null: |
michael@0 | 4 | return 0; |
michael@0 | 5 | case 1.1: |
michael@0 | 6 | return 1; |
michael@0 | 7 | case "2": |
michael@0 | 8 | return 2; |
michael@0 | 9 | case 3: |
michael@0 | 10 | return 3; |
michael@0 | 11 | } |
michael@0 | 12 | return 4; |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | // reuse the same function for testing with different inputs & type. |
michael@0 | 16 | var typedSwitch1 = eval(typedSwitch0.toSource()); |
michael@0 | 17 | var typedSwitch2 = eval(typedSwitch0.toSource()); |
michael@0 | 18 | var typedSwitch3 = eval(typedSwitch0.toSource()); |
michael@0 | 19 | var typedSwitch4 = eval(typedSwitch0.toSource()); |
michael@0 | 20 | |
michael@0 | 21 | for (var i = 0; i < 100; i++) { |
michael@0 | 22 | assertEq(typedSwitch0(null), 0); |
michael@0 | 23 | assertEq(typedSwitch1(1.1), 1); |
michael@0 | 24 | assertEq(typedSwitch2("2"), 2); |
michael@0 | 25 | assertEq(typedSwitch3(3), 3); |
michael@0 | 26 | assertEq(typedSwitch4(undefined), 4); |
michael@0 | 27 | } |