|
1 // |reftest| skip -- slow |
|
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 //----------------------------------------------------------------------------- |
|
8 var BUGNUMBER = 465980; |
|
9 var summary = 'Do not crash @ InitArrayElements'; |
|
10 var actual = ''; |
|
11 var expect = ''; |
|
12 |
|
13 |
|
14 //----------------------------------------------------------------------------- |
|
15 test(); |
|
16 //----------------------------------------------------------------------------- |
|
17 |
|
18 function test() |
|
19 { |
|
20 enterFunc ('test'); |
|
21 printBugNumber(BUGNUMBER); |
|
22 printStatus (summary); |
|
23 |
|
24 function describe(name, startLength, pushArgs, expectThrow, expectLength) |
|
25 { |
|
26 return name + "(" + startLength + ", " + |
|
27 "[" + pushArgs.join(", ") + "], " + |
|
28 expectThrow + ", " + |
|
29 expectLength + ")"; |
|
30 } |
|
31 |
|
32 var push = Array.prototype.push; |
|
33 var unshift = Array.prototype.unshift; |
|
34 |
|
35 function testArrayPush(startLength, pushArgs, expectThrow, expectLength) |
|
36 { |
|
37 print("running testArrayPush(" + |
|
38 startLength + ", " + |
|
39 "[" + pushArgs.join(", ") + "], " + |
|
40 expectThrow + ", " + |
|
41 expectLength + ")..."); |
|
42 var a = new Array(startLength); |
|
43 try |
|
44 { |
|
45 push.apply(a, pushArgs); |
|
46 if (expectThrow) |
|
47 { |
|
48 throw "expected to throw for " + |
|
49 describe("testArrayPush", startLength, pushArgs, expectThrow, |
|
50 expectLength); |
|
51 } |
|
52 } |
|
53 catch (e) |
|
54 { |
|
55 if (!(e instanceof RangeError)) |
|
56 { |
|
57 throw "unexpected exception type thrown: " + e + " for " + |
|
58 describe("testArrayPush", startLength, pushArgs, expectThrow, |
|
59 expectLength); |
|
60 } |
|
61 if (!expectThrow) |
|
62 { |
|
63 throw "unexpected exception " + e + " for " + |
|
64 describe("testArrayPush", startLength, pushArgs, expectThrow, |
|
65 expectLength); |
|
66 } |
|
67 } |
|
68 |
|
69 if (a.length !== expectLength) |
|
70 { |
|
71 throw "unexpected modified-array length for " + |
|
72 describe("testArrayPush", startLength, pushArgs, expectThrow, |
|
73 expectLength); |
|
74 } |
|
75 |
|
76 for (var i = 0, sz = pushArgs.length; i < sz; i++) |
|
77 { |
|
78 var index = i + startLength; |
|
79 if (a[index] !== pushArgs[i]) |
|
80 { |
|
81 throw "unexpected value " + a[index] + |
|
82 " at index " + index + " (" + i + ") during " + |
|
83 describe("testArrayPush", startLength, pushArgs, expectThrow, |
|
84 expectLength) + ", expected " + pushArgs[i]; |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 function testArrayUnshift(startLength, unshiftArgs, expectThrow, expectLength) |
|
90 { |
|
91 print("running testArrayUnshift(" + |
|
92 startLength + ", " + |
|
93 "[" + unshiftArgs.join(", ") + "], " + |
|
94 expectThrow + ", " + |
|
95 expectLength + ")..."); |
|
96 var a = new Array(startLength); |
|
97 try |
|
98 { |
|
99 unshift.apply(a, unshiftArgs); |
|
100 if (expectThrow) |
|
101 { |
|
102 throw "expected to throw for " + |
|
103 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, |
|
104 expectLength); |
|
105 } |
|
106 } |
|
107 catch (e) |
|
108 { |
|
109 if (!(e instanceof RangeError)) |
|
110 { |
|
111 throw "unexpected exception type thrown: " + e + " for " + |
|
112 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, |
|
113 expectLength); |
|
114 } |
|
115 if (!expectThrow) |
|
116 { |
|
117 throw "unexpected exception " + e + " for " + |
|
118 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, |
|
119 expectLength); |
|
120 } |
|
121 } |
|
122 |
|
123 if (a.length !== expectLength) |
|
124 { |
|
125 throw "unexpected modified-array length for " + |
|
126 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, |
|
127 expectLength); |
|
128 } |
|
129 |
|
130 for (var i = 0, sz = unshiftArgs.length; i < sz; i++) |
|
131 { |
|
132 if (a[i] !== unshiftArgs[i]) |
|
133 { |
|
134 throw "unexpected value at index " + i + " during " + |
|
135 describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, |
|
136 expectLength); |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 var failed = true; |
|
142 |
|
143 try |
|
144 { |
|
145 var foo = "foo", bar = "bar", baz = "baz"; |
|
146 |
|
147 testArrayPush(4294967294, [foo], false, 4294967295); |
|
148 testArrayPush(4294967294, [foo, bar], true, 4294967295); |
|
149 testArrayPush(4294967294, [foo, bar, baz], true, 4294967295); |
|
150 testArrayPush(4294967295, [foo], true, 4294967295); |
|
151 testArrayPush(4294967295, [foo, bar], true, 4294967295); |
|
152 testArrayPush(4294967295, [foo, bar, baz], true, 4294967295); |
|
153 |
|
154 testArrayUnshift(4294967294, [foo], false, 4294967295); |
|
155 testArrayUnshift(4294967294, [foo, bar], true, 4294967294); |
|
156 testArrayUnshift(4294967294, [foo, bar, baz], true, 4294967294); |
|
157 testArrayUnshift(4294967295, [foo], true, 4294967295); |
|
158 testArrayUnshift(4294967295, [foo, bar], true, 4294967295); |
|
159 testArrayUnshift(4294967295, [foo, bar, baz], true, 4294967295); |
|
160 |
|
161 } |
|
162 catch (e) |
|
163 { |
|
164 actual = e + ''; |
|
165 } |
|
166 |
|
167 reportCompare(expect, actual, summary); |
|
168 |
|
169 exitFunc ('test'); |
|
170 } |