S12.14_A13_T2.js (3308B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: Using "try" with "catch" or "finally" statement with a "return" statement 6 es5id: 12.14_A13_T2 7 description: Using try/finally syntax construction 8 ---*/ 9 10 // CHECK#1 11 var c1=0; 12 function myFunction1(){ 13 try{ 14 return 1; 15 }finally{ 16 c1=1; 17 } 18 return 2; 19 } 20 var x1=myFunction1(); 21 if(x1!==1){ 22 throw new Test262Error('#1.1: x1===1. Actual: x1==='+x1); 23 } 24 if (c1!==1){ 25 throw new Test262Error('#1.2: "finally" block must be evaluated'); 26 } 27 28 // CHECK#2 29 var c2=0; 30 function myFunction2(){ 31 try{ 32 throw "exc"; 33 return 1; 34 }finally{ 35 c2=1; 36 } 37 return 2; 38 } 39 try{ 40 var x2=myFunction2(); 41 throw new Test262Error('#2.1: Throwing exception inside function lead to throwing exception outside this function'); 42 } 43 catch(e){ 44 if (c2!==1){ 45 throw new Test262Error('#2.2: "finally" block must be evaluated'); 46 } 47 } 48 49 // CHECK#3 50 var c3=0; 51 function myFunction3(){ 52 try{ 53 return someValue; 54 }finally{ 55 c3=1; 56 } 57 return 2; 58 } 59 try{ 60 var x3=myFunction3(); 61 throw new Test262Error('#3.1: Throwing exception inside function lead to throwing exception outside this function'); 62 } 63 catch(e){ 64 if (c3!==1){ 65 throw new Test262Error('#3.2: "finally" block must be evaluated'); 66 } 67 } 68 69 // CHECK#4 70 var c4=0; 71 function myFunction4(){ 72 try{ 73 return 1; 74 }finally{ 75 c4=1; 76 throw "exc"; 77 return 0; 78 } 79 return 2; 80 } 81 try{ 82 var x4=myFunction4(); 83 throw new Test262Error('#4.2: Throwing exception inside function lead to throwing exception outside this function'); 84 } 85 catch(e){ 86 if (c4!==1){ 87 throw new Test262Error('#4.3: "finally" block must be evaluated'); 88 } 89 } 90 91 // CHECK#5 92 var c5=0; 93 function myFunction5(){ 94 try{ 95 return 1; 96 }finally{ 97 c5=1; 98 return someValue; 99 return 0; 100 } 101 return 2; 102 } 103 try{ 104 var x5=myFunction5(); 105 throw new Test262Error('#5.2: Throwing exception inside function lead to throwing exception outside this function'); 106 } 107 catch(e){ 108 if (c5!==1){ 109 throw new Test262Error('#5.3: "finally" block must be evaluated'); 110 } 111 } 112 113 // CHECK#6 114 var c6=0; 115 function myFunction6(){ 116 try{ 117 throw "ex1"; 118 return 1; 119 }finally{ 120 c6=1; 121 throw "ex2"; 122 return 2; 123 } 124 return 3; 125 } 126 try{ 127 var x6=myFunction6(); 128 throw new Test262Error('#6.1: Throwing exception inside function lead to throwing exception outside this function'); 129 } 130 catch(e){ 131 if(e==="ex1"){ 132 throw new Test262Error('#6.2: Exception !=="ex1". Actual: catch previous exception'); 133 } 134 if(e!=="ex2"){ 135 throw new Test262Error('#6.3: Exception !=="ex1". Actual: '+e); 136 } 137 if (c6!==1){ 138 throw new Test262Error('#6.4: "finally" block must be evaluated'); 139 } 140 } 141 142 // CHECK#7 143 var c7=0; 144 function myFunction7(){ 145 try{ 146 return 1; 147 }finally{ 148 c7=1; 149 return 2; 150 } 151 return 3; 152 } 153 var x7=myFunction7(); 154 if(x7!==2){ 155 throw new Test262Error('#7.1: "catch" block must be evaluated'); 156 } 157 if (c7!==1){ 158 throw new Test262Error('#7.2: "finally" block must be evaluated'); 159 } 160 161 // CHECK#8 162 var c8=0; 163 function myFunction8(){ 164 try{ 165 throw "ex1"; 166 }finally{ 167 c8=1; 168 return 2; 169 } 170 return 3; 171 } 172 try{ 173 var x8=myFunction8(); 174 } 175 catch(ex1){ 176 c8=10; 177 } 178 if (c8!==1){ 179 throw new Test262Error('#8: "finally" block must be evaluated'); 180 } 181 182 reportCompare(0, 0);