Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-225831.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: 15 Nov 2003
9 * SUMMARY: Stressing the byte code generator
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=225831
12 *
13 */
14 //-----------------------------------------------------------------------------
15 var gTestfile = 'regress-225831.js';
16 var UBound = 0;
17 var BUGNUMBER = 225831;
18 var summary = 'Stressing the byte code generator';
19 var status = '';
20 var statusitems = [];
21 var actual = '';
22 var actualvalues = [];
23 var expect= '';
24 var expectedvalues = [];
25
26
27 function f() { return {x: 0}; }
28
29 var N = 300;
30 var a = new Array(N + 1);
31 a[N] = 10;
32 a[0] = 100;
33
34
35 status = inSection(1);
36
37 // build string of the form ++(a[++f().x + ++f().x + ... + ++f().x]) which
38 // gives ++a[N]
39 var str = "".concat("++(a[", repeat_str("++f().x + ", (N - 1)), "++f().x])");
40
41 // Use Script constructor instead of simple eval to test Rhino optimizer mode
42 // because in Rhino, eval always uses interpreted mode.
43 if (typeof Script == 'undefined')
44 {
45 print('Test skipped. Script not defined.');
46 }
47 else
48 {
49 var script = new Script(str);
50 script();
51
52 actual = a[N];
53 expect = 11;
54 }
55 addThis();
56
57 status = inSection(2);
58
59
60 // build string of the form (a[f().x-- + f().x-- + ... + f().x--])--
61 // which should give (a[0])--
62 if (typeof Script == 'undefined')
63 {
64 print('Test skipped. Script not defined.');
65 }
66 else
67 {
68 str = "".concat("(a[", repeat_str("f().x-- + ", (N - 1)), "f().x--])--");
69 script = new Script(str);
70 script();
71
72 actual = a[0];
73 expect = 99;
74 }
75 addThis();
76
77
78 status = inSection(3);
79
80 // build string of the form [[1], [1], ..., [1]]
81 if (typeof Script == 'undefined')
82 {
83 print('Test skipped. Script not defined.');
84 }
85 else
86 {
87 str = "".concat("[", repeat_str("[1], ", (N - 1)), "[1]]");
88 script = new Script(str);
89 script();
90
91 actual = uneval(script());
92 expect = str;
93 }
94 addThis();
95
96
97 status = inSection(4);
98
99 // build string of the form ({1:{a:1}, 2:{a:1}, ... N:{a:1}})
100 if (typeof Script == 'undefined')
101 {
102 print('Test skipped. Script not defined.');
103 }
104 else
105 {
106 str = function() {
107 var arr = new Array(N+1);
108 arr[0] = "({";
109 for (var i = 1; i < N; ++i) {
110 arr[i] = i+":{a:1}, ";
111 }
112 arr[N] = N+":{a:1}})";
113 return "".concat.apply("", arr);
114 }();
115
116 script = new Script(str);
117 script();
118
119 actual = uneval(script());
120 expect = str;
121 }
122 addThis();
123
124
125
126
127 //-----------------------------------------------------------------------------
128 test();
129 //-----------------------------------------------------------------------------
130
131
132
133 function repeat_str(str, repeat_count)
134 {
135 var arr = new Array(--repeat_count);
136 while (repeat_count != 0)
137 arr[--repeat_count] = str;
138 return str.concat.apply(str, arr);
139 }
140
141
142 function addThis()
143 {
144 statusitems[UBound] = status;
145 actualvalues[UBound] = actual;
146 expectedvalues[UBound] = expect;
147 UBound++;
148 }
149
150
151 function test()
152 {
153 enterFunc('test');
154 printBugNumber(BUGNUMBER);
155 printStatus(summary);
156
157 for (var i=0; i<UBound; i++)
158 {
159 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
160 }
161
162 exitFunc ('test');
163 }