js/src/tests/test262/ch12/12.14/S12.14_A13_T3.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial