Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-159334.js

raw symbols SCIP
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 gTestfile = 'regress-159334.js';
25 var UBound = 0;
26 var BUGNUMBER = 159334;
27 var summary = 'Testing script with at least 64K of different string literals';
28 var status = '';
29 var statusitems = [];
30 var actual = '';
31 var actualvalues = [];
32 var expect= '';
33 var expectedvalues = [];
34
35
36 var N = 0xFFFE;
37
38 // Create big string for eval recursively to avoid N*N behavior
39 // on string concatenation
40 var long_eval = buildEval_r(0, N);
41
42 // Run it
43 var test_sum = 0;
44 function f(str) { test_sum += Number(str); }
45 eval(long_eval);
46
47 status = inSection(1);
48 actual = (test_sum == N * (N - 1) / 2);
49 expect = true;
50 addThis();
51
52
53
54 //-----------------------------------------------------------------------------
55 test();
56 //-----------------------------------------------------------------------------
57
58
59
60 function buildEval_r(beginLine, endLine)
61 {
62 var count = endLine - beginLine;
63
64 if (count == 0)
65 return "";
66
67 if (count == 1)
68 return "f('" + beginLine + "')\n";
69
70 var middle = beginLine + (count >>> 1);
71 return buildEval_r(beginLine, middle) + buildEval_r(middle, endLine);
72 }
73
74
75 function addThis()
76 {
77 statusitems[UBound] = status;
78 actualvalues[UBound] = actual;
79 expectedvalues[UBound] = expect;
80 UBound++;
81 }
82
83
84 function test()
85 {
86 enterFunc('test');
87 printBugNumber(BUGNUMBER);
88 printStatus(summary);
89
90 for (var i=0; i<UBound; i++)
91 {
92 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
93 }
94
95 exitFunc ('test');
96 }