js/src/tests/test262/ch12/12.14/S12.14_A15.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_A15.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     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 within/without a "switch" statement
     1.9 + *
    1.10 + * @path ch12/12.14/S12.14_A15.js
    1.11 + * @description Insert try/catch/finally to switch statement
    1.12 + */
    1.13 +
    1.14 +// CHECK#1
    1.15 +function SwitchTest1(value){
    1.16 +  var result = 0;
    1.17 +  try{  
    1.18 +    switch(value) {
    1.19 +      case 1:
    1.20 +        result += 4;
    1.21 +        throw result;
    1.22 +        break;
    1.23 +      default:
    1.24 +        result += 32;
    1.25 +        break;
    1.26 +      case 4:
    1.27 +        result += 64;
    1.28 +        throw "ex";
    1.29 +    }
    1.30 +    return result;
    1.31 +  }
    1.32 +  catch(e){	
    1.33 +    if ((value===1)&&(e!==4)) $ERROR('#1.1: Exception ===4. Actual:  Exception ==='+ e  );
    1.34 +    if ((value===4)&&(e!=="ex")) $ERROR('#1.2: Exception ==="ex". Actual:  Exception ==='+ e  );
    1.35 +  }
    1.36 +  finally{
    1.37 +    return result;
    1.38 +  }
    1.39 +}
    1.40 +if (SwitchTest1(1)!==4) $ERROR('#1.3: SwitchTest1(1)===4. Actual:  SwitchTest1(1)==='+ SwitchTest1(1) );
    1.41 +if (SwitchTest1(4)!==64) $ERROR('#1.4: SwitchTest1(4)===64. Actual:  SwitchTest1(4)==='+ SwitchTest1(4) );
    1.42 +
    1.43 +// CHECK#2
    1.44 +var c2=0;
    1.45 +function SwitchTest2(value){
    1.46 +  var result = 0;
    1.47 +  switch(value) {
    1.48 +    case 0:
    1.49 +      try{  
    1.50 +        result += 2;
    1.51 +        break;
    1.52 +      }
    1.53 +      finally{
    1.54 +        c2=1;
    1.55 +      }
    1.56 +    case 1:
    1.57 +      result += 4;
    1.58 +      break;
    1.59 +    default:
    1.60 +      result += 32;
    1.61 +      break;
    1.62 +  }
    1.63 +  return result;
    1.64 +}
    1.65 +if (SwitchTest2(1)!==4) $ERROR('#2.1: SwitchTest1(1)===4. Actual:  SwitchTest1(1)==='+ SwitchTest1(1) );
    1.66 +if (c2===1) $ERROR('#2.2: Evaluate finally block');
    1.67 +if (SwitchTest2(0)!==2) $ERROR('#2.3: SwitchTest1(0)===2. Actual:  SwitchTest1(0)==='+ SwitchTest1(0) );
    1.68 +if (c2!==1) $ERROR('#2.4: "finally" block must be evaluated');
    1.69 +
    1.70 +// CHECK#3
    1.71 +function SwitchTest3(value){
    1.72 +  var result = 0;
    1.73 +  switch(value) {
    1.74 +    case 0:
    1.75 +      try{  
    1.76 +        result += 2;
    1.77 +        throw "ex";
    1.78 +      }
    1.79 +      finally{
    1.80 +        break;
    1.81 +      }
    1.82 +    default:
    1.83 +      result += 32;
    1.84 +      break;
    1.85 +  }
    1.86 +  return result;
    1.87 +}
    1.88 +try{
    1.89 +  var x3=SwitchTest3(0);
    1.90 +  if (x3!==2) $ERROR('#3.1: x3===2. Actual: x3==='+x3);
    1.91 +}
    1.92 +catch(e){
    1.93 +  $ERROR('#3.2: Catching exception inside function does not lead to throwing exception outside this function');
    1.94 +}
    1.95 +

mercurial