1// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28var a = [0,1,2,3];
29assertEquals(0, a.length = 0);
30
31assertEquals('undefined', typeof a[0]);
32assertEquals('undefined', typeof a[1]);
33assertEquals('undefined', typeof a[2]);
34assertEquals('undefined', typeof a[3]);
35
36
37var a = [0,1,2,3];
38assertEquals(2, a.length = 2);
39
40assertEquals(0, a[0]);
41assertEquals(1, a[1]);
42assertEquals('undefined', typeof a[2]);
43assertEquals('undefined', typeof a[3]);
44
45
46var a = new Array();
47a[0] = 0;
48a[1000] = 1000;
49a[1000000] = 1000000;
50a[2000000] = 2000000;
51
52assertEquals(2000001, a.length);
53assertEquals(0, a.length = 0);
54assertEquals(0, a.length);
55assertEquals('undefined', typeof a[0]);
56assertEquals('undefined', typeof a[1000]);
57assertEquals('undefined', typeof a[1000000]);
58assertEquals('undefined', typeof a[2000000]);
59
60
61var a = new Array();
62a[0] = 0;
63a[1000] = 1000;
64a[1000000] = 1000000;
65a[2000000] = 2000000;
66
67assertEquals(2000001, a.length);
68assertEquals(2000, a.length = 2000);
69assertEquals(2000, a.length);
70assertEquals(0, a[0]);
71assertEquals(1000, a[1000]);
72assertEquals('undefined', typeof a[1000000]);
73assertEquals('undefined', typeof a[2000000]);
74
75
76var a = new Array();
77a[Math.pow(2,31)-1] = 0;
78a[Math.pow(2,30)-1] = 0;
79assertEquals(Math.pow(2,31), a.length);
80
81
82var a = new Array();
83a[0] = 0;
84a[1000] = 1000;
85a[Math.pow(2,30)-1] = Math.pow(2,30)-1;
86a[Math.pow(2,31)-1] = Math.pow(2,31)-1;
87a[Math.pow(2,32)-2] = Math.pow(2,32)-2;
88
89assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]);
90assertEquals(Math.pow(2,31)-1, a[Math.pow(2,31)-1]);
91assertEquals(Math.pow(2,32)-2, a[Math.pow(2,32)-2]);
92
93assertEquals(Math.pow(2,32)-1, a.length);
94assertEquals(Math.pow(2,30) + 1, a.length = Math.pow(2,30)+1);  // not a smi!
95assertEquals(Math.pow(2,30)+1, a.length);
96
97assertEquals(0, a[0]);
98assertEquals(1000, a[1000]);
99assertEquals(Math.pow(2,30)-1, a[Math.pow(2,30)-1]);
100assertEquals('undefined', typeof a[Math.pow(2,31)-1]);
101assertEquals('undefined', typeof a[Math.pow(2,32)-2], "top");
102
103
104var a = new Array();
105assertEquals(Object(12), a.length = new Number(12));
106assertEquals(12, a.length);
107
108
109var o = { length: -23 };
110Array.prototype.pop.apply(o);
111assertEquals(4294967272, o.length);
112
113// Check case of compiled stubs.
114var a = [];
115for (var i = 0; i < 7; i++) {
116  assertEquals(3, a.length = 3);
117
118  var t = 239;
119  t = a.length = 7;
120  assertEquals(7, t);
121}
122