1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/test262/ch12/12.14/S12.14_A13_T3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,186 @@ 1.4 +// Copyright 2009 the Sputnik authors. All rights reserved. 1.5 +// This code is governed by the BSD license found in the LICENSE file. 1.6 + 1.7 +/** 1.8 + * Using "try" with "catch" or "finally" statement with a "return" statement 1.9 + * 1.10 + * @path ch12/12.14/S12.14_A13_T3.js 1.11 + * @description Using try/catch/finally syntax construction 1.12 + */ 1.13 + 1.14 +// CHECK#1 1.15 +var c1=0; 1.16 +function myFunction1(){ 1.17 + try{ 1.18 + return 1; 1.19 + }catch(err){ 1.20 + $ERROR('#1.1: "return 1" inside function does not lead to throwing exception'); 1.21 + return 0; 1.22 + }finally{ 1.23 + c1=1; 1.24 + } 1.25 + return 2; 1.26 +} 1.27 +var x1=myFunction1(); 1.28 +if(x1!==1){ 1.29 + $ERROR('#1.3: x1===1. Actual: x1==='+x1); 1.30 +} 1.31 +if (c1!==1){ 1.32 + $ERROR('#1.4: "finally" block must be evaluated'); 1.33 +} 1.34 + 1.35 +// CHECK#2 1.36 +var c2=0; 1.37 +function myFunction2(){ 1.38 + try{ 1.39 + throw "exc"; 1.40 + return 1; 1.41 + }catch(err){ 1.42 + return 0; 1.43 + }finally{ 1.44 + c2=1; 1.45 + } 1.46 + return 2; 1.47 +} 1.48 +var x2=myFunction2(); 1.49 +if (c2!==1){ 1.50 + $ERROR('#2.1: "finally" block must be evaluated'); 1.51 +} 1.52 +if (x2!==0){ 1.53 + $ERROR('#2.2: x2===0. Actual: x2==='+x2); 1.54 +} 1.55 + 1.56 +// CHECK#3 1.57 +var c3=0; 1.58 +function myFunction3(){ 1.59 + try{ 1.60 + return someValue; 1.61 + }catch(err){ 1.62 + return 1; 1.63 + }finally{ 1.64 + c3=1; 1.65 + } 1.66 + return 2; 1.67 +} 1.68 +var x3=myFunction3(); 1.69 +if (c3!==1){ 1.70 + $ERROR('#3.1: "finally" block must be evaluated'); 1.71 +} 1.72 +if (x3!==1){ 1.73 + $ERROR('#3.2: x3===1. Actual: x3==='+x3); 1.74 +} 1.75 + 1.76 +// CHECK#4 1.77 +var c4=0; 1.78 +function myFunction4(){ 1.79 + try{ 1.80 + throw "ex1"; 1.81 + return 1; 1.82 + }catch(err){ 1.83 + throw "ex2" 1.84 + return 0; 1.85 + }finally{ 1.86 + c4=1; 1.87 + } 1.88 + return 2; 1.89 +} 1.90 +try{ 1.91 + var x4=myFunction4(); 1.92 + $ERROR('#4.1: Throwing exception inside function lead to throwing exception outside this function'); 1.93 +} 1.94 +catch(e){ 1.95 + if(e==="ex1"){ 1.96 + $ERROR('#4.2: Exception !== "ex1". Actual: catch previous exception'); 1.97 + } 1.98 + if(e!=="ex2"){ 1.99 + $ERROR('#4.3: Exception === "ex2". Actual: Exception ==='+ e ); 1.100 + } 1.101 + if (c4!==1){ 1.102 + $ERROR('#4.4: "finally" block must be evaluated'); 1.103 + } 1.104 +} 1.105 + 1.106 +// CHECK#5 1.107 +var c5=0; 1.108 +function myFunction5(){ 1.109 + try{ 1.110 + throw "ex1"; 1.111 + return 1; 1.112 + }catch(err){ 1.113 + return 0; 1.114 + }finally{ 1.115 + c5=1; 1.116 + throw "ex2"; 1.117 + } 1.118 + return 2; 1.119 +} 1.120 +try{ 1.121 + var x5=myFunction5(); 1.122 + $ERROR('#5.1: Throwing exception inside function lead to throwing exception outside this function'); 1.123 +} 1.124 +catch(e){ 1.125 + if(e==="ex1"){ 1.126 + $ERROR('#5.2: Exception !== "ex1". Actual: catch previous exception'); 1.127 + } 1.128 + if(e!=="ex2"){ 1.129 + $ERROR('#5.3: Exception === "ex2". Actual: Exception ==='+ e ); 1.130 + } 1.131 + if (c5!==1){ 1.132 + $ERROR('#5.4: "finally" block must be evaluated'); 1.133 + } 1.134 +} 1.135 + 1.136 +// CHECK#6 1.137 +var c6=0; 1.138 +function myFunction6(){ 1.139 + try{ 1.140 + throw "ex1"; 1.141 + return 1; 1.142 + }catch(err){ 1.143 + throw "ex2"; 1.144 + return 0; 1.145 + }finally{ 1.146 + c6=1; 1.147 + throw "ex3"; 1.148 + } 1.149 + return 2; 1.150 +} 1.151 +try{ 1.152 + var x6=myFunction6(); 1.153 + $ERROR('#6.1: Throwing exception inside function lead to throwing exception outside this function'); 1.154 +} 1.155 +catch(e){ 1.156 + if(e==="ex1"){ 1.157 + $ERROR('#6.2: Exception !== "ex1". Actual: catch previous exception'); 1.158 + } 1.159 + if(e==="ex2"){ 1.160 + $ERROR('#6.3: Exception !== "ex2". Actual: catch previous exception'); 1.161 + } 1.162 + if(e!=="ex3"){ 1.163 + $ERROR('#6.4: Exception === "ex3". Actual: Exception ==='+ e ); 1.164 + } 1.165 + if(c6!==1) $ERROR('#6.5: "finally" block must be evaluated'); 1.166 +} 1.167 + 1.168 +// CHECK#7 1.169 +var c7=0; 1.170 +function myFunction7(){ 1.171 + try{ 1.172 + throw "ex1"; 1.173 + return 1; 1.174 + }catch(err){ 1.175 + throw "ex2"; 1.176 + return 0; 1.177 + }finally{ 1.178 + c7=1; 1.179 + return 2; 1.180 + } 1.181 + return 3; 1.182 +} 1.183 +try{ 1.184 + var x7=myFunction7(); 1.185 + if(x7!==2) $ERROR('#7.1: x7===2. Actual: x7==='+x7); 1.186 +} 1.187 +catch(e){} 1.188 +if(c7!==1) $ERROR('#7.2: "finally" block must be evaluated'); 1.189 +