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