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 February 2003 michael@0: * SUMMARY: Object.toSource() recursion should check stack overflow michael@0: * michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=192465 michael@0: * michael@0: * MODIFIED: 27 February 2003 michael@0: * michael@0: * We are adding an early return to this testcase, since it is causing michael@0: * big problems on Linux RedHat8! For a discussion of this issue, see michael@0: * http://bugzilla.mozilla.org/show_bug.cgi?id=174341#c24 and following. michael@0: * michael@0: * michael@0: * MODIFIED: 20 March 2003 michael@0: * michael@0: * Removed the early return and changed |N| below from 1000 to 90. michael@0: * Note |make_deep_nest(N)| returns an object graph of length N(N+1). michael@0: * So the graph has now been reduced from 1,001,000 to 8190. michael@0: * michael@0: * With this reduction, the bug still manifests on my WinNT and Linux michael@0: * boxes (crash due to stack overflow). So the testcase is again of use michael@0: * on those boxes. At the same time, Linux RedHat8 boxes can now run michael@0: * the test in a reasonable amount of time. michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 192465; michael@0: var summary = 'Object.toSource() recursion should check stack overflow'; 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: * We're just testing that this script will compile and run. michael@0: * Set both |actual| and |expect| to a dummy value. michael@0: */ michael@0: status = inSection(1); michael@0: var N = 90; michael@0: try michael@0: { michael@0: make_deep_nest(N); michael@0: } michael@0: catch (e) michael@0: { michael@0: // An exception is OK, as the runtime can throw one in response to too deep michael@0: // recursion. We haven't crashed; good! Continue on to set the dummy values - michael@0: } michael@0: actual = 1; michael@0: expect = 1; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: /* michael@0: * EXAMPLE: michael@0: * michael@0: * If the global variable |N| is 2, then for |level| == 0, 1, 2, the return michael@0: * value of this function will be toSource() of these objects, respectively: michael@0: * michael@0: * {next:{next:END}} michael@0: * {next:{next:{next:{next:END}}}} michael@0: * {next:{next:{next:{next:{next:{next:END}}}}}} michael@0: * michael@0: */ michael@0: function make_deep_nest(level) michael@0: { michael@0: var head = {}; michael@0: var cursor = head; michael@0: michael@0: for (var i=0; i!=N; ++i) michael@0: { michael@0: cursor.next = {}; michael@0: cursor = cursor.next; michael@0: } michael@0: michael@0: cursor.toSource = function() michael@0: { michael@0: if (level != 0) michael@0: return make_deep_nest(level - 1); michael@0: return "END"; michael@0: } michael@0: michael@0: return head.toSource(); michael@0: } michael@0: michael@0: michael@0: function addThis() 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