js/src/tests/test262/ch12/12.14/S12.14_A14.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_A14.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 within/without a "with" statement
     1.9 + *
    1.10 + * @path ch12/12.14/S12.14_A14.js
    1.11 + * @description Using try/catch/finally in With and With in try/catch/finally
    1.12 + * @noStrict
    1.13 + */
    1.14 +
    1.15 +var myObj = {p1: 'a',
    1.16 +             p2: 'b',
    1.17 +             p3: 'c',
    1.18 +             value: 'myObj_value',
    1.19 +             valueOf : function(){return 'obj_valueOf';},
    1.20 +             parseInt : function(){return 'obj_parseInt';},
    1.21 +             NaN : 'obj_NaN',
    1.22 +             Infinity : 'obj_Infinity',
    1.23 +             eval     : function(){return 'obj_eval';},
    1.24 +             parseFloat : function(){return 'obj_parseFloat';},
    1.25 +             isNaN      : function(){return 'obj_isNaN';},
    1.26 +             isFinite   : function(){return 'obj_isFinite';}
    1.27 +}
    1.28 +
    1.29 +// CHECK#1
    1.30 +try{
    1.31 +  with(myObj){
    1.32 +    throw "ex";
    1.33 +  }
    1.34 +}
    1.35 +catch(e){
    1.36 +  if (e!=="ex") $ERROR('#1: Exception ==="ex". Actual:  Exception ==='+ e  );
    1.37 +}
    1.38 +
    1.39 +// CHECK#2
    1.40 +with(myObj){
    1.41 +  try{
    1.42 +    throw p1;
    1.43 +  }
    1.44 +  catch(e){
    1.45 +    if (e!=="a") $ERROR('#2.1: Exception ==="a". Actual:  Exception ==='+ e  );
    1.46 +    p1='pass';
    1.47 +  }
    1.48 +}
    1.49 +if(myObj.p1!=='pass') $ERROR('#2.2: "throw p1" lead to throwing exception');
    1.50 +
    1.51 +// CHECK#3
    1.52 +with(myObj){
    1.53 +  try{
    1.54 +    p1='fail';
    1.55 +    throw p2;
    1.56 +  }
    1.57 +  catch(e){
    1.58 +    if (e!=="b") $ERROR('#3.1: Exception ==="b". Actual:  Exception ==='+ e  );
    1.59 +    p1='pass';
    1.60 +  }
    1.61 +  finally{
    1.62 +    p2='pass';
    1.63 +  }
    1.64 +}
    1.65 +if(myObj.p1!=='pass') $ERROR('#3.2: "throw p2" lead to throwing exception');
    1.66 +if(myObj.p2!=='pass') $ERROR('#3.3: "finally" block must be evaluated');
    1.67 +
    1.68 +// CHECK#4
    1.69 +myObj.p1='fail';
    1.70 +try{
    1.71 +  with(myObj){
    1.72 +    try{
    1.73 +      throw p3;
    1.74 +    }
    1.75 +    finally{
    1.76 +      p1='pass';
    1.77 +    }
    1.78 +  }
    1.79 +}
    1.80 +catch(e){}
    1.81 +if(myObj.p1!=='pass') $ERROR('#4: "finally" block must be evaluated');
    1.82 +

mercurial