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.

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

mercurial