js/src/tests/js1_5/Regress/regress-159334.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9df70682ed31
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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: 31 Oct 2002
9 * SUMMARY: Testing script with at least 64K of different string literals
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=159334
11 *
12 * Testing that script engine can handle scripts with at least 64K of different
13 * string literals. The following will evaluate, via eval(), a script like this:
14 *
15 * f('0')
16 * f('1')
17 * ...
18 * f('N - 1')
19 *
20 * where N is 0xFFFE
21 *
22 */
23 //-----------------------------------------------------------------------------
24 var UBound = 0;
25 var BUGNUMBER = 159334;
26 var summary = 'Testing script with at least 64K of different string literals';
27 var status = '';
28 var statusitems = [];
29 var actual = '';
30 var actualvalues = [];
31 var expect= '';
32 var expectedvalues = [];
33
34
35 var N = 0xFFFE;
36
37 // Create big string for eval recursively to avoid N*N behavior
38 // on string concatenation
39 var long_eval = buildEval_r(0, N);
40
41 // Run it
42 var test_sum = 0;
43 function f(str) { test_sum += Number(str); }
44 eval(long_eval);
45
46 status = inSection(1);
47 actual = (test_sum == N * (N - 1) / 2);
48 expect = true;
49 addThis();
50
51
52
53 //-----------------------------------------------------------------------------
54 test();
55 //-----------------------------------------------------------------------------
56
57
58
59 function buildEval_r(beginLine, endLine)
60 {
61 var count = endLine - beginLine;
62
63 if (count == 0)
64 return "";
65
66 if (count == 1)
67 return "f('" + beginLine + "')\n";
68
69 var middle = beginLine + (count >>> 1);
70 return buildEval_r(beginLine, middle) + buildEval_r(middle, endLine);
71 }
72
73
74 function addThis()
75 {
76 statusitems[UBound] = status;
77 actualvalues[UBound] = actual;
78 expectedvalues[UBound] = expect;
79 UBound++;
80 }
81
82
83 function test()
84 {
85 enterFunc('test');
86 printBugNumber(BUGNUMBER);
87 printStatus(summary);
88
89 for (var i=0; i<UBound; i++)
90 {
91 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
92 }
93
94 exitFunc ('test');
95 }

mercurial