|
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 File Name: 15.4.2.2-1.js |
|
9 ECMA Section: 15.4.2.2 new Array(len) |
|
10 |
|
11 Description: This description only applies of the constructor is |
|
12 given two or more arguments. |
|
13 |
|
14 The [[Prototype]] property of the newly constructed |
|
15 object is set to the original Array prototype object, |
|
16 the one that is the initial value of Array.prototype(0) |
|
17 (15.4.3.1). |
|
18 |
|
19 The [[Class]] property of the newly constructed object |
|
20 is set to "Array". |
|
21 |
|
22 If the argument len is a number, then the length |
|
23 property of the newly constructed object is set to |
|
24 ToUint32(len). |
|
25 |
|
26 If the argument len is not a number, then the length |
|
27 property of the newly constructed object is set to 1 |
|
28 and the 0 property of the newly constructed object is |
|
29 set to len. |
|
30 |
|
31 This file tests cases where len is a number. |
|
32 |
|
33 The cases in this test need to be updated since the |
|
34 ToUint32_t description has changed. |
|
35 |
|
36 Author: christine@netscape.com |
|
37 Date: 7 october 1997 |
|
38 */ |
|
39 var SECTION = "15.4.2.2-1"; |
|
40 var VERSION = "ECMA_1"; |
|
41 startTest(); |
|
42 var TITLE = "The Array Constructor: new Array( len )"; |
|
43 |
|
44 writeHeaderToLog( SECTION + " "+ TITLE); |
|
45 |
|
46 new TestCase( SECTION, |
|
47 "new Array(0)", |
|
48 "", |
|
49 (new Array(0)).toString() ); |
|
50 |
|
51 new TestCase( SECTION, |
|
52 "typeof new Array(0)", |
|
53 "object", |
|
54 (typeof new Array(0)) ); |
|
55 |
|
56 new TestCase( SECTION, |
|
57 "(new Array(0)).length", |
|
58 0, |
|
59 (new Array(0)).length ); |
|
60 |
|
61 new TestCase( SECTION, |
|
62 "(new Array(0)).toString", |
|
63 Array.prototype.toString, |
|
64 (new Array(0)).toString ); |
|
65 |
|
66 new TestCase( SECTION, |
|
67 "new Array(1)", |
|
68 "", |
|
69 (new Array(1)).toString() ); |
|
70 |
|
71 new TestCase( SECTION, |
|
72 "new Array(1).length", |
|
73 1, |
|
74 (new Array(1)).length ); |
|
75 |
|
76 new TestCase( SECTION, |
|
77 "(new Array(1)).toString", |
|
78 Array.prototype.toString, |
|
79 (new Array(1)).toString ); |
|
80 |
|
81 new TestCase( SECTION, |
|
82 "(new Array(-0)).length", |
|
83 0, |
|
84 (new Array(-0)).length ); |
|
85 |
|
86 new TestCase( SECTION, |
|
87 "(new Array(0)).length", |
|
88 0, |
|
89 (new Array(0)).length ); |
|
90 |
|
91 new TestCase( SECTION, |
|
92 "(new Array(10)).length", |
|
93 10, |
|
94 (new Array(10)).length ); |
|
95 |
|
96 new TestCase( SECTION, |
|
97 "(new Array('1')).length", |
|
98 1, |
|
99 (new Array('1')).length ); |
|
100 |
|
101 new TestCase( SECTION, |
|
102 "(new Array(1000)).length", |
|
103 1000, |
|
104 (new Array(1000)).length ); |
|
105 |
|
106 new TestCase( SECTION, |
|
107 "(new Array('1000')).length", |
|
108 1, |
|
109 (new Array('1000')).length ); |
|
110 |
|
111 new TestCase( SECTION, |
|
112 "(new Array(4294967295)).length", |
|
113 ToUint32(4294967295), |
|
114 (new Array(4294967295)).length ); |
|
115 |
|
116 new TestCase( SECTION, |
|
117 "(new Array('8589934592')).length", |
|
118 1, |
|
119 (new Array("8589934592")).length ); |
|
120 |
|
121 new TestCase( SECTION, |
|
122 "(new Array('4294967296')).length", |
|
123 1, |
|
124 (new Array("4294967296")).length ); |
|
125 |
|
126 new TestCase( SECTION, |
|
127 "(new Array(1073741824)).length", |
|
128 ToUint32(1073741824), |
|
129 (new Array(1073741824)).length ); |
|
130 |
|
131 test(); |
|
132 |
|
133 function ToUint32( n ) { |
|
134 n = Number( n ); |
|
135 var sign = ( n < 0 ) ? -1 : 1; |
|
136 |
|
137 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { |
|
138 return 0; |
|
139 } |
|
140 n = sign * Math.floor( Math.abs(n) ) |
|
141 |
|
142 n = n % Math.pow(2,32); |
|
143 |
|
144 if ( n < 0 ){ |
|
145 n += Math.pow(2,32); |
|
146 } |
|
147 |
|
148 return ( n ); |
|
149 } |