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