regress-146596.js (2470B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * 8 * Date: 18 Jun 2002 9 * SUMMARY: Shouldn't crash when catch parameter is "hidden" by varX 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=146596 11 * 12 */ 13 //----------------------------------------------------------------------------- 14 var UBound = 0; 15 var BUGNUMBER = 146596; 16 var summary = "Shouldn't crash when catch parameter is 'hidden' by varX"; 17 var status = ''; 18 var statusitems = []; 19 var actual = ''; 20 var actualvalues = []; 21 var expect= ''; 22 var expectedvalues = []; 23 24 25 /* 26 * Just seeing we don't crash when executing this function - 27 * This example provided by jim-patterson@ncf.ca 28 * 29 * Brendan: "Jim, thanks for the testcase. But note that |var| 30 * in a JS function makes a function-scoped variable -- JS lacks 31 * block scope apart from for catch variables within catch blocks. 32 * 33 * Therefore the catch variable hides the function-local variable." 34 */ 35 function F() 36 { 37 try 38 { 39 return "A simple exception"; 40 } 41 catch(e) 42 { 43 var e = "Another exception"; 44 } 45 46 return 'XYZ'; 47 } 48 49 status = inSection(1); 50 actual = F(); 51 expect = "A simple exception"; 52 addThis(); 53 54 55 56 /* 57 * Sanity check by Brendan: "This should output 58 * 59 * 24 60 * 42 61 * undefined 62 * 63 * and throw no uncaught exception." 64 * 65 */ 66 function f(obj) 67 { 68 var res = []; 69 70 try 71 { 72 throw 42; 73 } 74 catch(e) 75 { 76 with(obj) 77 { 78 var e; 79 res[0] = e; // |with| binds tighter than |catch|; s/b |obj.e| 80 } 81 82 res[1] = e; // |catch| binds tighter than function scope; s/b 42 83 } 84 85 res[2] = e; // |var e| has function scope; s/b visible but contain |undefined| 86 return res; 87 } 88 89 status = inSection(2); 90 actual = f({e:24}); 91 expect = [24, 42, undefined]; 92 addThis(); 93 94 95 96 97 //----------------------------------------------------------------------------- 98 test(); 99 //----------------------------------------------------------------------------- 100 101 102 103 function addThis() 104 { 105 statusitems[UBound] = status; 106 actualvalues[UBound] = actual.toString(); 107 expectedvalues[UBound] = expect.toString(); 108 UBound++; 109 } 110 111 112 function test() 113 { 114 printBugNumber(BUGNUMBER); 115 printStatus(summary); 116 117 for (var i=0; i<UBound; i++) 118 { 119 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 120 } 121 }