michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Using "try" with "catch" or "finally" statement within/without a "with" statement michael@0: * michael@0: * @path ch12/12.14/S12.14_A14.js michael@0: * @description Using try/catch/finally in With and With in try/catch/finally michael@0: * @noStrict michael@0: */ michael@0: michael@0: var myObj = {p1: 'a', michael@0: p2: 'b', michael@0: p3: 'c', michael@0: value: 'myObj_value', michael@0: valueOf : function(){return 'obj_valueOf';}, michael@0: parseInt : function(){return 'obj_parseInt';}, michael@0: NaN : 'obj_NaN', michael@0: Infinity : 'obj_Infinity', michael@0: eval : function(){return 'obj_eval';}, michael@0: parseFloat : function(){return 'obj_parseFloat';}, michael@0: isNaN : function(){return 'obj_isNaN';}, michael@0: isFinite : function(){return 'obj_isFinite';} michael@0: } michael@0: michael@0: // CHECK#1 michael@0: try{ michael@0: with(myObj){ michael@0: throw "ex"; michael@0: } michael@0: } michael@0: catch(e){ michael@0: if (e!=="ex") $ERROR('#1: Exception ==="ex". Actual: Exception ==='+ e ); michael@0: } michael@0: michael@0: // CHECK#2 michael@0: with(myObj){ michael@0: try{ michael@0: throw p1; michael@0: } michael@0: catch(e){ michael@0: if (e!=="a") $ERROR('#2.1: Exception ==="a". Actual: Exception ==='+ e ); michael@0: p1='pass'; michael@0: } michael@0: } michael@0: if(myObj.p1!=='pass') $ERROR('#2.2: "throw p1" lead to throwing exception'); michael@0: michael@0: // CHECK#3 michael@0: with(myObj){ michael@0: try{ michael@0: p1='fail'; michael@0: throw p2; michael@0: } michael@0: catch(e){ michael@0: if (e!=="b") $ERROR('#3.1: Exception ==="b". Actual: Exception ==='+ e ); michael@0: p1='pass'; michael@0: } michael@0: finally{ michael@0: p2='pass'; michael@0: } michael@0: } michael@0: if(myObj.p1!=='pass') $ERROR('#3.2: "throw p2" lead to throwing exception'); michael@0: if(myObj.p2!=='pass') $ERROR('#3.3: "finally" block must be evaluated'); michael@0: michael@0: // CHECK#4 michael@0: myObj.p1='fail'; michael@0: try{ michael@0: with(myObj){ michael@0: try{ michael@0: throw p3; michael@0: } michael@0: finally{ michael@0: p1='pass'; michael@0: } michael@0: } michael@0: } michael@0: catch(e){} michael@0: if(myObj.p1!=='pass') $ERROR('#4: "finally" block must be evaluated'); michael@0: