michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * michael@0: * Date: 18 Jun 2002 michael@0: * SUMMARY: Shouldn't crash when catch parameter is "hidden" by varX michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=146596 michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 146596; michael@0: var summary = "Shouldn't crash when catch parameter is 'hidden' by varX"; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: michael@0: michael@0: /* michael@0: * Just seeing we don't crash when executing this function - michael@0: * This example provided by jim-patterson@ncf.ca michael@0: * michael@0: * Brendan: "Jim, thanks for the testcase. But note that |var| michael@0: * in a JS function makes a function-scoped variable -- JS lacks michael@0: * block scope apart from for catch variables within catch blocks. michael@0: * michael@0: * Therefore the catch variable hides the function-local variable." michael@0: */ michael@0: function F() michael@0: { michael@0: try michael@0: { michael@0: return "A simple exception"; michael@0: } michael@0: catch(e) michael@0: { michael@0: var e = "Another exception"; michael@0: } michael@0: michael@0: return 'XYZ'; michael@0: } michael@0: michael@0: status = inSection(1); michael@0: actual = F(); michael@0: expect = "A simple exception"; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: /* michael@0: * Sanity check by Brendan: "This should output michael@0: * michael@0: * 24 michael@0: * 42 michael@0: * undefined michael@0: * michael@0: * and throw no uncaught exception." michael@0: * michael@0: */ michael@0: function f(obj) michael@0: { michael@0: var res = []; michael@0: michael@0: try michael@0: { michael@0: throw 42; michael@0: } michael@0: catch(e) michael@0: { michael@0: with(obj) michael@0: { michael@0: var e; michael@0: res[0] = e; // |with| binds tighter than |catch|; s/b |obj.e| michael@0: } michael@0: michael@0: res[1] = e; // |catch| binds tighter than function scope; s/b 42 michael@0: } michael@0: michael@0: res[2] = e; // |var e| has function scope; s/b visible but contain |undefined| michael@0: return res; michael@0: } michael@0: michael@0: status = inSection(2); michael@0: actual = f({e:24}); michael@0: expect = [24, 42, undefined]; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual.toString(); michael@0: expectedvalues[UBound] = expect.toString(); michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus(summary); michael@0: michael@0: for (var i=0; i