js/src/tests/test262/ch12/12.14/S12.14_A15.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 // Copyright 2009 the Sputnik authors. All rights reserved.
michael@0 2 // This code is governed by the BSD license found in the LICENSE file.
michael@0 3
michael@0 4 /**
michael@0 5 * Using "try" with "catch" or "finally" statement within/without a "switch" statement
michael@0 6 *
michael@0 7 * @path ch12/12.14/S12.14_A15.js
michael@0 8 * @description Insert try/catch/finally to switch statement
michael@0 9 */
michael@0 10
michael@0 11 // CHECK#1
michael@0 12 function SwitchTest1(value){
michael@0 13 var result = 0;
michael@0 14 try{
michael@0 15 switch(value) {
michael@0 16 case 1:
michael@0 17 result += 4;
michael@0 18 throw result;
michael@0 19 break;
michael@0 20 default:
michael@0 21 result += 32;
michael@0 22 break;
michael@0 23 case 4:
michael@0 24 result += 64;
michael@0 25 throw "ex";
michael@0 26 }
michael@0 27 return result;
michael@0 28 }
michael@0 29 catch(e){
michael@0 30 if ((value===1)&&(e!==4)) $ERROR('#1.1: Exception ===4. Actual: Exception ==='+ e );
michael@0 31 if ((value===4)&&(e!=="ex")) $ERROR('#1.2: Exception ==="ex". Actual: Exception ==='+ e );
michael@0 32 }
michael@0 33 finally{
michael@0 34 return result;
michael@0 35 }
michael@0 36 }
michael@0 37 if (SwitchTest1(1)!==4) $ERROR('#1.3: SwitchTest1(1)===4. Actual: SwitchTest1(1)==='+ SwitchTest1(1) );
michael@0 38 if (SwitchTest1(4)!==64) $ERROR('#1.4: SwitchTest1(4)===64. Actual: SwitchTest1(4)==='+ SwitchTest1(4) );
michael@0 39
michael@0 40 // CHECK#2
michael@0 41 var c2=0;
michael@0 42 function SwitchTest2(value){
michael@0 43 var result = 0;
michael@0 44 switch(value) {
michael@0 45 case 0:
michael@0 46 try{
michael@0 47 result += 2;
michael@0 48 break;
michael@0 49 }
michael@0 50 finally{
michael@0 51 c2=1;
michael@0 52 }
michael@0 53 case 1:
michael@0 54 result += 4;
michael@0 55 break;
michael@0 56 default:
michael@0 57 result += 32;
michael@0 58 break;
michael@0 59 }
michael@0 60 return result;
michael@0 61 }
michael@0 62 if (SwitchTest2(1)!==4) $ERROR('#2.1: SwitchTest1(1)===4. Actual: SwitchTest1(1)==='+ SwitchTest1(1) );
michael@0 63 if (c2===1) $ERROR('#2.2: Evaluate finally block');
michael@0 64 if (SwitchTest2(0)!==2) $ERROR('#2.3: SwitchTest1(0)===2. Actual: SwitchTest1(0)==='+ SwitchTest1(0) );
michael@0 65 if (c2!==1) $ERROR('#2.4: "finally" block must be evaluated');
michael@0 66
michael@0 67 // CHECK#3
michael@0 68 function SwitchTest3(value){
michael@0 69 var result = 0;
michael@0 70 switch(value) {
michael@0 71 case 0:
michael@0 72 try{
michael@0 73 result += 2;
michael@0 74 throw "ex";
michael@0 75 }
michael@0 76 finally{
michael@0 77 break;
michael@0 78 }
michael@0 79 default:
michael@0 80 result += 32;
michael@0 81 break;
michael@0 82 }
michael@0 83 return result;
michael@0 84 }
michael@0 85 try{
michael@0 86 var x3=SwitchTest3(0);
michael@0 87 if (x3!==2) $ERROR('#3.1: x3===2. Actual: x3==='+x3);
michael@0 88 }
michael@0 89 catch(e){
michael@0 90 $ERROR('#3.2: Catching exception inside function does not lead to throwing exception outside this function');
michael@0 91 }
michael@0 92

mercurial