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) 2003
20 * the Initial Developer. All Rights Reserved.
23 * igor@fastmail.fm, PhilSchwartau@aol.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 ***** */
42 * SUMMARY: Stressing the byte code generator
44 * See http://bugzilla.mozilla.org/show_bug.cgi?id=225831
47 //-----------------------------------------------------------------------------
49 var BUGNUMBER = 225831;
50 var summary = 'Stressing the byte code generator';
54 var actualvalues = [];
56 var expectedvalues = [];
59 function f() { return {x: 0}; }
62 var a = new Array(N + 1);
67 status = inSection(1);
69 // build string of the form ++(a[++f().x + ++f().x + ... + ++f().x]) which
71 var str = "".concat("++(a[", repeat_str("++f().x + ", (N - 1)), "++f().x])");
73 // Use Script constructor instead of simple eval to test Rhino optimizer mode
74 // because in Rhino, eval always uses interpreted mode.
75 if (typeof Script == 'undefined')
77 print('Test skipped. Script not defined.');
81 var script = new Script(str);
89 status = inSection(2);
92 // build string of the form (a[f().x-- + f().x-- + ... + f().x--])--
93 // which should give (a[0])--
94 if (typeof Script == 'undefined')
96 print('Test skipped. Script not defined.');
100 str = "".concat("(a[", repeat_str("f().x-- + ", (N - 1)), "f().x--])--");
101 script = new Script(str);
110 status = inSection(3);
112 // build string of the form [[1], [1], ..., [1]]
113 if (typeof Script == 'undefined')
115 print('Test skipped. Script not defined.');
119 str = "".concat("[", repeat_str("[1], ", (N - 1)), "[1]]");
120 script = new Script(str);
123 actual = uneval(script());
129 status = inSection(4);
131 // build string of the form ({1:{a:1}, 2:{a:1}, ... N:{a:1}})
132 if (typeof Script == 'undefined')
134 print('Test skipped. Script not defined.');
139 var arr = new Array(N+1);
141 for (var i = 1; i < N; ++i) {
142 arr[i] = i+":{a:1}, ";
144 arr[N] = N+":{a:1}})";
145 return "".concat.apply("", arr);
148 script = new Script(str);
151 actual = uneval(script());
159 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
165 function repeat_str(str, repeat_count)
167 var arr = new Array(--repeat_count);
168 while (repeat_count != 0)
169 arr[--repeat_count] = str;
170 return str.concat.apply(str, arr);
176 statusitems[UBound] = status;
177 actualvalues[UBound] = actual;
178 expectedvalues[UBound] = expect;
186 printBugNumber(BUGNUMBER);
187 printStatus(summary);
189 for (var i=0; i<UBound; i++)
191 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);