S12.14_A14.js (1965B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: | 6 Using "try" with "catch" or "finally" statement within/without a "with" 7 statement 8 es5id: 12.14_A14 9 description: Using try/catch/finally in With and With in try/catch/finally 10 flags: [noStrict] 11 ---*/ 12 13 var myObj = {p1: 'a', 14 p2: 'b', 15 p3: 'c', 16 value: 'myObj_value', 17 valueOf : function(){return 'obj_valueOf';}, 18 parseInt : function(){return 'obj_parseInt';}, 19 NaN : 'obj_NaN', 20 Infinity : 'obj_Infinity', 21 eval : function(){return 'obj_eval';}, 22 parseFloat : function(){return 'obj_parseFloat';}, 23 isNaN : function(){return 'obj_isNaN';}, 24 isFinite : function(){return 'obj_isFinite';} 25 } 26 27 // CHECK#1 28 try{ 29 with(myObj){ 30 throw "ex"; 31 } 32 } 33 catch(e){ 34 if (e!=="ex") throw new Test262Error('#1: Exception ==="ex". Actual: Exception ==='+ e ); 35 } 36 37 // CHECK#2 38 with(myObj){ 39 try{ 40 throw p1; 41 } 42 catch(e){ 43 if (e!=="a") throw new Test262Error('#2.1: Exception ==="a". Actual: Exception ==='+ e ); 44 p1='pass'; 45 } 46 } 47 if(myObj.p1!=='pass') throw new Test262Error('#2.2: "throw p1" lead to throwing exception'); 48 49 // CHECK#3 50 with(myObj){ 51 try{ 52 p1='fail'; 53 throw p2; 54 } 55 catch(e){ 56 if (e!=="b") throw new Test262Error('#3.1: Exception ==="b". Actual: Exception ==='+ e ); 57 p1='pass'; 58 } 59 finally{ 60 p2='pass'; 61 } 62 } 63 if(myObj.p1!=='pass') throw new Test262Error('#3.2: "throw p2" lead to throwing exception'); 64 if(myObj.p2!=='pass') throw new Test262Error('#3.3: "finally" block must be evaluated'); 65 66 // CHECK#4 67 myObj.p1='fail'; 68 try{ 69 with(myObj){ 70 try{ 71 throw p3; 72 } 73 finally{ 74 p1='pass'; 75 } 76 } 77 } 78 catch(e){} 79 if(myObj.p1!=='pass') throw new Test262Error('#4: "finally" block must be evaluated'); 80 81 reportCompare(0, 0);