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

changeset 0
6474c204b198
     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_T1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     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_T1.js
    1.11 + * @description Using try/catch syntax construction
    1.12 + */
    1.13 +
    1.14 +// CHECK#1
    1.15 +function myFunction1(){
    1.16 +  try{
    1.17 +    return 1;
    1.18 +  }
    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 +  }
    1.23 +  return 2;
    1.24 +}
    1.25 +var x1=myFunction1();
    1.26 +if(x1!==1){
    1.27 +  $ERROR('#1.2: x1===1. Actual: x1==='+x1);
    1.28 +}
    1.29 +
    1.30 +// CHECK#2
    1.31 +function myFunction2(){
    1.32 +  try{
    1.33 +    throw "exc";
    1.34 +    return 1;
    1.35 +  }catch(err){  	
    1.36 +    return 2;
    1.37 +  }
    1.38 +  return 3;
    1.39 +}
    1.40 +var x2=myFunction2();
    1.41 +if (x2!==2){
    1.42 +  $ERROR('#2: x2===2. Actual: x2==='+x2);
    1.43 +}
    1.44 +
    1.45 +// CHECK#3
    1.46 +function myFunction3(){
    1.47 +  try{
    1.48 +    return someValue;
    1.49 +  }catch(err){  	
    1.50 +    return 1;
    1.51 +  }
    1.52 +  return 2;
    1.53 +}
    1.54 +var x3=myFunction3();
    1.55 +if (x3!==1){
    1.56 +  $ERROR('#3: x3===1. Actual: x3==='+x3);
    1.57 +}
    1.58 +
    1.59 +// CHECK#4
    1.60 +function myFunction4(){
    1.61 +  try{
    1.62 +    throw "ex1";
    1.63 +    return 1;
    1.64 +  }catch(err){
    1.65 +    throw "ex2"
    1.66 +    return 0;
    1.67 +  }
    1.68 +  return 2;
    1.69 +}
    1.70 +try{
    1.71 +  var x4=myFunction4();
    1.72 +  $ERROR('#4.1: Throwing exception inside function lead to throwing exception outside this function');
    1.73 +}
    1.74 +catch(e){
    1.75 +  if(e==="ex1"){
    1.76 +    $ERROR('#4.2: Exception !=="ex1". Actual: catch previous exception');
    1.77 +  }
    1.78 +  if(e!=="ex2"){
    1.79 +    $ERROR('#4.3: Exception ==="ex2". Actual:  Exception ==='+ e  );
    1.80 +  }
    1.81 +}
    1.82 +

mercurial