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

mercurial