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