js/src/tests/test262/ch12/12.14/S12.14_A13_T1.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_T1.js
     8  * @description Using try/catch syntax construction
     9  */
    11 // CHECK#1
    12 function myFunction1(){
    13   try{
    14     return 1;
    15   }
    16   catch(err){
    17   	$ERROR('#1.1: "return 1" inside function does not lead to throwing exception');
    18     return 0;
    19   }
    20   return 2;
    21 }
    22 var x1=myFunction1();
    23 if(x1!==1){
    24   $ERROR('#1.2: x1===1. Actual: x1==='+x1);
    25 }
    27 // CHECK#2
    28 function myFunction2(){
    29   try{
    30     throw "exc";
    31     return 1;
    32   }catch(err){  	
    33     return 2;
    34   }
    35   return 3;
    36 }
    37 var x2=myFunction2();
    38 if (x2!==2){
    39   $ERROR('#2: x2===2. Actual: x2==='+x2);
    40 }
    42 // CHECK#3
    43 function myFunction3(){
    44   try{
    45     return someValue;
    46   }catch(err){  	
    47     return 1;
    48   }
    49   return 2;
    50 }
    51 var x3=myFunction3();
    52 if (x3!==1){
    53   $ERROR('#3: x3===1. Actual: x3==='+x3);
    54 }
    56 // CHECK#4
    57 function myFunction4(){
    58   try{
    59     throw "ex1";
    60     return 1;
    61   }catch(err){
    62     throw "ex2"
    63     return 0;
    64   }
    65   return 2;
    66 }
    67 try{
    68   var x4=myFunction4();
    69   $ERROR('#4.1: Throwing exception inside function lead to throwing exception outside this function');
    70 }
    71 catch(e){
    72   if(e==="ex1"){
    73     $ERROR('#4.2: Exception !=="ex1". Actual: catch previous exception');
    74   }
    75   if(e!=="ex2"){
    76     $ERROR('#4.3: Exception ==="ex2". Actual:  Exception ==='+ e  );
    77   }
    78 }

mercurial