1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * igor@icesoft.no, pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 * Date: 09 November 2002
42 * SUMMARY: Test that interpreter can handle string literals exceeding 64K
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=179068
45 * Test that the interpreter can handle string literals exceeding 64K limit.
46 * For that the script passes to eval() "str ='LONG_STRING_LITERAL';" where
47 * LONG_STRING_LITERAL is a string with 200K chars.
49 * Igor Bukanov explains the technique used below:
51 * > Philip Schwartau wrote:
53 * > Here is the heart of the testcase:
55 * > // Generate 200K long string
56 * > var long_str = duplicate(LONG_STR_SEED, N);
58 * > eval("str='".concat(long_str, "';"));
59 * > var test_is_ok = (str.length == LONG_STR_SEED.length * N);
62 * > The testcase creates two identical strings, |long_str| and |str|. It
63 * > uses eval() simply to assign the value of |long_str| to |str|. Why is
64 * > it necessary to have the variable |str|, then? Why not just create
65 * > |long_str| and test it? Wouldn't this be enough:
67 * > // Generate 200K long string
68 * > var long_str = duplicate(LONG_STR_SEED, N);
69 * > var test_is_ok = (long_str.length == LONG_STR_SEED.length * N);
71 * > Or do we specifically need to test eval() to exercise the interpreter?
73 * The reason for eval is to test string literals like in 'a string literal
74 * with 100 000 characters...', Rhino deals fine with strings generated at
75 * run time where lengths > 64K. Without eval it would be necessary to have
76 * a test file excedding 64K which is not that polite for CVS and then a
77 * special treatment for the compiled mode in Rhino should be added.
81 * > If so, is it important to use the concat() method in the assignment, as
82 * > you have done: |eval("str='".concat(long_str, "';"))|, or can we simply
83 * > do |eval("str = long_str;")| ?
85 * The concat is a replacement for eval("str='"+long_str+"';"), but as
86 * long_str is huge, this leads to constructing first a new string via
87 * "str='"+long_str and then another one via ("str='"+long_str) + "';"
88 * which takes time under JDK 1.1 on a something like StrongArm 200MHz.
89 * Calling concat makes less copies, that is why it is used in the
90 * duplicate function and this is faster then doing recursion like in the
91 * test case to test that 64K different string literals can be handled.
94 //-----------------------------------------------------------------------------
96 var BUGNUMBER = 179068;
97 var summary = 'Test that interpreter can handle string literals exceeding 64K';
101 var actualvalues = [];
103 var expectedvalues = [];
104 var LONG_STR_SEED = "0123456789";
109 // Generate 200K long string and assign it to |str| via eval()
110 var long_str = duplicate(LONG_STR_SEED, N);
111 eval("str='".concat(long_str, "';"));
113 status = inSection(1);
114 actual = str.length == LONG_STR_SEED.length * N
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
126 function duplicate(str, count)
128 var tmp = new Array(count);
133 return String.prototype.concat.apply("", tmp);
139 statusitems[UBound] = status;
140 actualvalues[UBound] = actual;
141 expectedvalues[UBound] = expect;
149 printBugNumber(BUGNUMBER);
150 printStatus(summary);
152 for (var i=0; i<UBound; i++)
154 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);