Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / extensions / regress-225831.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
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.
21  *
22  * Contributor(s):
23  *   igor@fastmail.fm, PhilSchwartau@aol.com
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    15 Nov 2003
42  * SUMMARY: Stressing the byte code generator
43  *
44  * See http://bugzilla.mozilla.org/show_bug.cgi?id=225831
45  *
46  */
47 //-----------------------------------------------------------------------------
48 var UBound = 0;
49 var BUGNUMBER = 225831;
50 var summary = 'Stressing the byte code generator';
51 var status = '';
52 var statusitems = [];
53 var actual = '';
54 var actualvalues = [];
55 var expect= '';
56 var expectedvalues = [];
57
58
59 function f() { return {x: 0}; }
60
61 var N = 300;
62 var a = new Array(N + 1);
63 a[N] = 10;
64 a[0] = 100;
65
66
67 status = inSection(1);
68
69 // build string of the form ++(a[++f().x + ++f().x + ... + ++f().x]) which
70 // gives ++a[N]
71 var str = "".concat("++(a[", repeat_str("++f().x + ", (N - 1)), "++f().x])");
72
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')
76 {
77   print('Test skipped. Script not defined.');
78 }
79 else
80 {
81   var script = new Script(str);
82   script();
83
84   actual = a[N];
85   expect = 11;
86 }
87 addThis();
88
89 status = inSection(2);
90
91
92 // build string of the form (a[f().x-- + f().x-- + ... + f().x--])--
93 // which should give (a[0])--
94 if (typeof Script == 'undefined')
95 {
96   print('Test skipped. Script not defined.');
97 }
98 else
99 {
100   str = "".concat("(a[", repeat_str("f().x-- + ", (N - 1)), "f().x--])--");
101   script = new Script(str);
102   script();
103
104   actual = a[0];
105   expect = 99;
106 }
107 addThis();
108
109
110 status = inSection(3);
111
112 // build string of the form [[1], [1], ..., [1]]
113 if (typeof Script == 'undefined')
114 {
115   print('Test skipped. Script not defined.');
116 }
117 else
118 {
119   str = "".concat("[", repeat_str("[1], ", (N - 1)), "[1]]");
120   script = new Script(str);
121   script();
122
123   actual = uneval(script());
124   expect = str;
125 }
126 addThis();
127
128
129 status = inSection(4);
130
131 // build string of the form ({1:{a:1}, 2:{a:1}, ... N:{a:1}})
132 if (typeof Script == 'undefined')
133 {
134   print('Test skipped. Script not defined.');
135 }
136 else
137 {
138   str = function() {
139     var arr = new Array(N+1);
140     arr[0] = "({";
141     for (var i = 1; i < N; ++i) {
142       arr[i] = i+":{a:1}, ";
143     }
144     arr[N] = N+":{a:1}})";
145     return "".concat.apply("", arr);
146   }();
147
148   script = new Script(str);
149   script();
150
151   actual = uneval(script());
152   expect = str;
153 }
154 addThis();
155
156
157
158
159 //-----------------------------------------------------------------------------
160 test();
161 //-----------------------------------------------------------------------------
162
163
164
165 function repeat_str(str, repeat_count)
166 {
167   var arr = new Array(--repeat_count);
168   while (repeat_count != 0)
169     arr[--repeat_count] = str;
170   return str.concat.apply(str, arr);
171 }
172
173
174 function addThis()
175 {
176   statusitems[UBound] = status;
177   actualvalues[UBound] = actual;
178   expectedvalues[UBound] = expect;
179   UBound++;
180 }
181
182
183 function test()
184 {
185   enterFunc('test');
186   printBugNumber(BUGNUMBER);
187   printStatus(summary);
188
189   for (var i=0; i<UBound; i++)
190   {
191     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
192   }
193
194   exitFunc ('test');
195 }