Debian Codegraph @

rhino/testsrc/tests/ecma/Array/15.4.2.2-1.js

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