• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// This test will not pass on FLOAT32 due to precision issues
16
17var len;
18var d = [];
19assert (d.length === 0);
20len = d.push();
21assert (d.length === 0);
22assert (d.length === len);
23len = d.push(1);
24assert (d.length === 1);
25assert (d.length === len);
26len = d.push(2);
27assert (d.length === 2);
28assert (d.length === len);
29len = d.push('a');
30assert (d.length === 3);
31assert (d.length === len);
32len = d.push('b', 'c', 3);
33assert (d.length == 6);
34assert (d.length === len);
35assert (d[0] === 1);
36assert (d[1] === 2);
37assert (d[2] === 'a');
38assert (d[3] === 'b');
39assert (d[4] === 'c');
40assert (d[5] === 3);
41
42var a = [];
43a.length = 4294967294;
44assert(a.push("x") === 4294967295);
45assert(a.length === 4294967295);
46assert(a[4294967294] === "x");
47
48try {
49  a.push("y");
50  assert(false);
51} catch (e) {
52  assert (e instanceof RangeError);
53}
54assert(a.length === 4294967295)
55
56var o = { length : 4294967294, push : Array.prototype.push };
57assert(o.push("x") === 4294967295);
58assert(o.length === 4294967295);
59assert(o[4294967294] === "x");
60
61try {
62  assert(o.push("y") === 4294967296);
63} catch (e) {
64  assert(false);
65}
66assert(o.length === 4294967296);
67assert(o[4294967295] === "y");
68
69/* ES v5.1 15.4.4.7.5.
70   Checking behavior when array is non-extensible while pushing */
71var arr = [];
72Object.freeze(arr);
73
74try {
75  arr.push(1, 2);
76  assert(false);
77} catch (e) {
78  assert(e instanceof TypeError);
79}
80