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: 10 October 2001 michael@0: * SUMMARY: Regression test for Bugzilla bug 104077 michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077 michael@0: * "JS crash: with/finally/return" michael@0: * michael@0: * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571 michael@0: * "JS crash: try/catch/continue." michael@0: * michael@0: * SpiderMonkey crashed on this code - it shouldn't. michael@0: * michael@0: * NOTE: the finally-blocks below should execute even if their try-blocks michael@0: * have return or throw statements in them: michael@0: * michael@0: * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 ------- michael@0: * finally trumps return, and all other control-flow constructs that cause michael@0: * program execution to jump out of the try block: throw, break, etc. Once you michael@0: * enter a try block, you will execute the finally block after leaving the try, michael@0: * regardless of what happens to make you leave the try. michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 104077; michael@0: var summary = "Just testing that we don't crash on with/finally/return -"; 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: function addValues_3(obj) michael@0: { michael@0: var sum = 0; michael@0: michael@0: with (obj) michael@0: { michael@0: try michael@0: { michael@0: sum = arg1 + arg2; michael@0: with (arg3) michael@0: { michael@0: while (sum < 10) michael@0: { michael@0: try michael@0: { michael@0: if (sum > 5) michael@0: return sum; michael@0: sum += 1; michael@0: } michael@0: catch (e) michael@0: { michael@0: sum += 1; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: finally michael@0: { michael@0: try michael@0: { michael@0: sum +=1; michael@0: print("In finally block of addValues_3() function: sum = " + sum); michael@0: } michael@0: catch (e if e == 42) michael@0: { michael@0: sum +=1; michael@0: print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e); michael@0: } michael@0: finally michael@0: { michael@0: sum +=1; michael@0: print("In finally finally block of addValues_3() function: sum = " + sum); michael@0: return sum; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: status = inSection(9); michael@0: obj = new Object(); michael@0: obj.arg1 = 1; michael@0: obj.arg2 = 2; michael@0: obj.arg3 = new Object(); michael@0: obj.arg3.a = 10; michael@0: obj.arg3.b = 20; michael@0: actual = addValues_3(obj); michael@0: expect = 8; michael@0: captureThis(); michael@0: michael@0: michael@0: michael@0: michael@0: function addValues_4(obj) michael@0: { michael@0: var sum = 0; michael@0: michael@0: with (obj) michael@0: { michael@0: try michael@0: { michael@0: sum = arg1 + arg2; michael@0: with (arg3) michael@0: { michael@0: while (sum < 10) michael@0: { michael@0: try michael@0: { michael@0: if (sum > 5) michael@0: return sum; michael@0: sum += 1; michael@0: } michael@0: catch (e) michael@0: { michael@0: sum += 1; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: finally michael@0: { michael@0: try michael@0: { michael@0: sum += 1; michael@0: print("In finally block of addValues_4() function: sum = " + sum); michael@0: } michael@0: catch (e if e == 42) michael@0: { michael@0: sum += 1; michael@0: print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e); michael@0: } michael@0: catch (e if e == 43) michael@0: { michael@0: sum += 1; michael@0: print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e); michael@0: } michael@0: finally michael@0: { michael@0: sum += 1; michael@0: print("In finally finally block of addValues_4() function: sum = " + sum); michael@0: return sum; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: status = inSection(10); michael@0: obj = new Object(); michael@0: obj.arg1 = 1; michael@0: obj.arg2 = 2; michael@0: obj.arg3 = new Object(); michael@0: obj.arg3.a = 10; michael@0: obj.arg3.b = 20; michael@0: actual = addValues_4(obj); michael@0: expect = 8; michael@0: captureThis(); michael@0: michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function captureThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; 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