js/src/tests/test262/ch12/12.14/S12.14_A13_T2.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_T2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     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_T2.js
    1.11 + * @description Using try/finally syntax construction
    1.12 + */
    1.13 +
    1.14 +// CHECK#1
    1.15 +var c1=0;
    1.16 +function myFunction1(){
    1.17 +  try{
    1.18 +    return 1;
    1.19 +  }finally{
    1.20 +    c1=1;
    1.21 +  }
    1.22 +  return 2;
    1.23 +}
    1.24 +var x1=myFunction1();
    1.25 +if(x1!==1){
    1.26 +  $ERROR('#1.1: x1===1. Actual: x1==='+x1);
    1.27 +}
    1.28 +if (c1!==1){
    1.29 +  $ERROR('#1.2: "finally" block must be evaluated');
    1.30 +}
    1.31 +
    1.32 +// CHECK#2
    1.33 +var c2=0;
    1.34 +function myFunction2(){
    1.35 +  try{
    1.36 +    throw "exc";
    1.37 +    return 1;
    1.38 +  }finally{
    1.39 +    c2=1;
    1.40 +  }
    1.41 +  return 2;
    1.42 +}
    1.43 +try{
    1.44 +  var x2=myFunction2();
    1.45 +  $ERROR('#2.1: Throwing exception inside function lead to throwing exception outside this function');
    1.46 +}
    1.47 +catch(e){
    1.48 +  if (c2!==1){
    1.49 +    $ERROR('#2.2: "finally" block must be evaluated');
    1.50 +  }
    1.51 +}
    1.52 +
    1.53 +// CHECK#3
    1.54 +var c3=0;
    1.55 +function myFunction3(){
    1.56 +  try{
    1.57 +    return someValue;
    1.58 +  }finally{
    1.59 +    c3=1;
    1.60 +  }
    1.61 +  return 2;
    1.62 +}
    1.63 +try{
    1.64 +  var x3=myFunction3();
    1.65 +  $ERROR('#3.1: Throwing exception inside function lead to throwing exception outside this function');
    1.66 +}
    1.67 +catch(e){
    1.68 +  if (c3!==1){
    1.69 +    $ERROR('#3.2: "finally" block must be evaluated');
    1.70 +  }
    1.71 +}
    1.72 +
    1.73 +// CHECK#4
    1.74 +var c4=0;
    1.75 +function myFunction4(){
    1.76 +  try{
    1.77 +    return 1;
    1.78 +  }finally{
    1.79 +    c4=1;
    1.80 +    throw "exc";
    1.81 +    return 0;
    1.82 +  }
    1.83 +  return 2;
    1.84 +}
    1.85 +try{
    1.86 +  var x4=myFunction4();
    1.87 +  $ERROR('#4.2: Throwing exception inside function lead to throwing exception outside this function');
    1.88 +}
    1.89 +catch(e){
    1.90 +  if (c4!==1){
    1.91 +    $ERROR('#4.3: "finally" block must be evaluated');
    1.92 +  }
    1.93 +}
    1.94 +
    1.95 +// CHECK#5
    1.96 +var c5=0;
    1.97 +function myFunction5(){
    1.98 +  try{
    1.99 +    return 1;
   1.100 +  }finally{
   1.101 +    c5=1;
   1.102 +    return someValue;
   1.103 +    return 0;
   1.104 +  }
   1.105 +  return 2;
   1.106 +}
   1.107 +try{
   1.108 +  var x5=myFunction5();
   1.109 +  $ERROR('#5.2: Throwing exception inside function lead to throwing exception outside this function');
   1.110 +}
   1.111 +catch(e){
   1.112 +  if (c5!==1){
   1.113 +    $ERROR('#5.3: "finally" block must be evaluated');
   1.114 +  }
   1.115 +}
   1.116 +
   1.117 +// CHECK#6
   1.118 +var c6=0;
   1.119 +function myFunction6(){
   1.120 +  try{
   1.121 +    throw "ex1";
   1.122 +    return 1;
   1.123 +  }finally{
   1.124 +    c6=1;
   1.125 +    throw "ex2";
   1.126 +    return 2;
   1.127 +  }
   1.128 +  return 3;
   1.129 +}
   1.130 +try{
   1.131 +  var x6=myFunction6();
   1.132 +  $ERROR('#6.1: Throwing exception inside function lead to throwing exception outside this function');
   1.133 +}
   1.134 +catch(e){
   1.135 +  if(e==="ex1"){
   1.136 +    $ERROR('#6.2: Exception !=="ex1". Actual: catch previous exception');
   1.137 +  }
   1.138 +  if(e!=="ex2"){
   1.139 +    $ERROR('#6.3: Exception !=="ex1". Actual: '+e);
   1.140 +  }
   1.141 +  if (c6!==1){
   1.142 +    $ERROR('#6.4: "finally" block must be evaluated');
   1.143 +  }
   1.144 +}
   1.145 +
   1.146 +// CHECK#7
   1.147 +var c7=0;
   1.148 +function myFunction7(){
   1.149 +  try{
   1.150 +    return 1;
   1.151 +  }finally{
   1.152 +    c7=1;
   1.153 +    return 2;
   1.154 +  }
   1.155 +  return 3;
   1.156 +}
   1.157 +var x7=myFunction7();
   1.158 +if(x7!==2){
   1.159 +  $ERROR('#7.1: "catch" block must be evaluated');
   1.160 +}
   1.161 +if (c7!==1){
   1.162 +  $ERROR('#7.2: "finally" block must be evaluated');
   1.163 +}
   1.164 +
   1.165 +// CHECK#8
   1.166 +var c8=0;
   1.167 +function myFunction8(){
   1.168 +  try{
   1.169 +    throw "ex1";
   1.170 +  }finally{
   1.171 +    c8=1;
   1.172 +    return 2;
   1.173 +  }
   1.174 +  return 3;
   1.175 +}
   1.176 +try{
   1.177 +  var x8=myFunction8();
   1.178 +}
   1.179 +catch(ex1){
   1.180 +  c8=10;
   1.181 +}
   1.182 +if (c8!==1){
   1.183 +  $ERROR('#8: "finally" block must be evaluated');
   1.184 +}
   1.185 +

mercurial