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: 31 Oct 2002 michael@0: * SUMMARY: Testing script with at least 64K of different string literals michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=159334 michael@0: * michael@0: * Testing that script engine can handle scripts with at least 64K of different michael@0: * string literals. The following will evaluate, via eval(), a script like this: michael@0: * michael@0: * f('0') michael@0: * f('1') michael@0: * ... michael@0: * f('N - 1') michael@0: * michael@0: * where N is 0xFFFE michael@0: * michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 159334; michael@0: var summary = 'Testing script with at least 64K of different string literals'; 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: var N = 0xFFFE; michael@0: michael@0: // Create big string for eval recursively to avoid N*N behavior michael@0: // on string concatenation michael@0: var long_eval = buildEval_r(0, N); michael@0: michael@0: // Run it michael@0: var test_sum = 0; michael@0: function f(str) { test_sum += Number(str); } michael@0: eval(long_eval); michael@0: michael@0: status = inSection(1); michael@0: actual = (test_sum == N * (N - 1) / 2); michael@0: expect = true; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: function buildEval_r(beginLine, endLine) michael@0: { michael@0: var count = endLine - beginLine; michael@0: michael@0: if (count == 0) michael@0: return ""; michael@0: michael@0: if (count == 1) michael@0: return "f('" + beginLine + "')\n"; michael@0: michael@0: var middle = beginLine + (count >>> 1); michael@0: return buildEval_r(beginLine, middle) + buildEval_r(middle, endLine); 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