js/src/tests/ecma/Array/15.4.1.2.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:0400de247570
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.1.2.js
9 ECMA Section: 15.4.1.2 Array(len)
10
11 Description: When Array is called as a function rather than as a
12 constructor, it creates and initializes a new array
13 object. Thus, the function call Array(...) is
14 equivalent to the object creationi new Array(...) with
15 the same arguments.
16
17 An array is created and returned as if by the
18 expression new Array(len).
19
20 Author: christine@netscape.com
21 Date: 7 october 1997
22 */
23 var SECTION = "15.4.1.2";
24 var VERSION = "ECMA_1";
25 startTest();
26 var TITLE = "Array Constructor Called as a Function: Array(len)";
27
28 writeHeaderToLog( SECTION + " "+ TITLE);
29
30 new TestCase( SECTION,
31 "(Array()).length",
32 0,
33 (Array()).length );
34
35 new TestCase( SECTION,
36 "(Array(0)).length",
37 0,
38 (Array(0)).length );
39
40 new TestCase( SECTION,
41 "(Array(1)).length",
42 1,
43 (Array(1)).length );
44
45 new TestCase( SECTION,
46 "(Array(10)).length",
47 10,
48 (Array(10)).length );
49
50 new TestCase( SECTION,
51 "(Array('1')).length",
52 1,
53 (Array('1')).length );
54
55 new TestCase( SECTION,
56 "(Array(1000)).length",
57 1000,
58 (Array(1000)).length );
59
60 new TestCase( SECTION,
61 "(Array('1000')).length",
62 1,
63 (Array('1000')).length );
64
65 new TestCase( SECTION,
66 "(Array(4294967295)).length",
67 ToUint32(4294967295),
68 (Array(4294967295)).length );
69
70 new TestCase( SECTION,
71 "(Array(Math.pow(2,31)-1)).length",
72 ToUint32(Math.pow(2,31)-1),
73 (Array(Math.pow(2,31)-1)).length );
74
75 new TestCase( SECTION,
76 "(Array(Math.pow(2,31))).length",
77 ToUint32(Math.pow(2,31)),
78 (Array(Math.pow(2,31))).length );
79
80 new TestCase( SECTION,
81 "(Array(Math.pow(2,31)+1)).length",
82 ToUint32(Math.pow(2,31)+1),
83 (Array(Math.pow(2,31)+1)).length );
84
85 new TestCase( SECTION,
86 "(Array('8589934592')).length",
87 1,
88 (Array("8589934592")).length );
89
90 new TestCase( SECTION,
91 "(Array('4294967296')).length",
92 1,
93 (Array("4294967296")).length );
94
95 new TestCase( SECTION,
96 "(Array(1073741823)).length",
97 ToUint32(1073741823),
98 (Array(1073741823)).length );
99
100 new TestCase( SECTION,
101 "(Array(1073741824)).length",
102 ToUint32(1073741824),
103 (Array(1073741824)).length );
104
105 new TestCase( SECTION,
106 "(Array('a string')).length",
107 1,
108 (Array("a string")).length );
109
110 test();
111
112 function ToUint32( n ) {
113 n = Number( n );
114 var sign = ( n < 0 ) ? -1 : 1;
115
116 if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
117 return 0;
118 }
119 n = sign * Math.floor( Math.abs(n) )
120
121 n = n % Math.pow(2,32);
122
123 if ( n < 0 ){
124 n += Math.pow(2,32);
125 }
126
127 return ( n );
128 }

mercurial