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/. */
8
* Date: 09 November 2002
9
* SUMMARY: Test that interpreter can handle string literals exceeding 64K
10
* See http://bugzilla.mozilla.org/show_bug.cgi?id=179068
12
* Test that the interpreter can handle string literals exceeding 64K limit.
13
* For that the script passes to eval() "str ='LONG_STRING_LITERAL';" where
14
* LONG_STRING_LITERAL is a string with 200K chars.
16
* Igor Bukanov explains the technique used below:
18
* > Philip Schwartau wrote:
20
* > Here is the heart of the testcase:
22
* > // Generate 200K long string
23
* > var long_str = duplicate(LONG_STR_SEED, N);
25
* > eval("str='".concat(long_str, "';"));
26
* > var test_is_ok = (str.length == LONG_STR_SEED.length * N);
29
* > The testcase creates two identical strings, |long_str| and |str|. It
30
* > uses eval() simply to assign the value of |long_str| to |str|. Why is
31
* > it necessary to have the variable |str|, then? Why not just create
32
* > |long_str| and test it? Wouldn't this be enough:
34
* > // Generate 200K long string
35
* > var long_str = duplicate(LONG_STR_SEED, N);
36
* > var test_is_ok = (long_str.length == LONG_STR_SEED.length * N);
38
* > Or do we specifically need to test eval() to exercise the interpreter?
40
* The reason for eval is to test string literals like in 'a string literal
41
* with 100 000 characters...', Rhino deals fine with strings generated at
42
* run time where lengths > 64K. Without eval it would be necessary to have
43
* a test file excedding 64K which is not that polite for CVS and then a
44
* special treatment for the compiled mode in Rhino should be added.
48
* > If so, is it important to use the concat() method in the assignment, as
49
* > you have done: |eval("str='".concat(long_str, "';"))|, or can we simply
50
* > do |eval("str = long_str;")| ?
52
* The concat is a replacement for eval("str='"+long_str+"';"), but as
53
* long_str is huge, this leads to constructing first a new string via
54
* "str='"+long_str and then another one via ("str='"+long_str) + "';"
55
* which takes time under JDK 1.1 on a something like StrongArm 200MHz.
56
* Calling concat makes less copies, that is why it is used in the
57
* duplicate function and this is faster then doing recursion like in the
58
* test case to test that 64K different string literals can be handled.
61
//-----------------------------------------------------------------------------
63
var BUGNUMBER = 179068;
64
var summary = 'Test that interpreter can handle string literals exceeding 64K';
68
var actualvalues = [];
70
var expectedvalues = [];
71
var LONG_STR_SEED = "0123456789";
76
// Generate 200K long string and assign it to |str| via eval()
77
var long_str = duplicate(LONG_STR_SEED, N);
78
eval("str='".concat(long_str, "';"));
80
status = inSection(1);
81
actual = str.length == LONG_STR_SEED.length * N
87
//-----------------------------------------------------------------------------
89
//-----------------------------------------------------------------------------
93
function duplicate(str, count)
95
var tmp = new Array(count);
100
return String.prototype.concat.apply("", tmp);
106
statusitems[UBound] = status;
107
actualvalues[UBound] = actual;
108
expectedvalues[UBound] = expect;
116
printBugNumber(BUGNUMBER);
117
printStatus(summary);
119
for (var i=0; i<UBound; i++)
121
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);