]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.1.2.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.4.1.2.js
24 ECMA Section: 15.4.1.2 Array(len)
26 Description: When Array is called as a function rather than as a
27 constructor, it creates and initializes a new array
28 object. Thus, the function call Array(...) is
29 equivalent to the object creationi new Array(...) with
32 An array is created and returned as if by the
33 expression new Array(len).
35 Author: christine@netscape.com
38 var SECTION
= "15.4.1.2";
39 var VERSION
= "ECMA_1";
41 var TITLE
= "Array Constructor Called as a Function: Array(len)";
43 writeHeaderToLog( SECTION
+ " "+ TITLE
);
45 var testcases
= getTestCases();
48 function getTestCases() {
49 var array
= new Array();
52 array
[item
++] = new TestCase( SECTION
, "(Array()).length", 0, (Array()).length
);
53 array
[item
++] = new TestCase( SECTION
, "(Array(0)).length", 0, (Array(0)).length
);
54 array
[item
++] = new TestCase( SECTION
, "(Array(1)).length", 1, (Array(1)).length
);
55 array
[item
++] = new TestCase( SECTION
, "(Array(10)).length", 10, (Array(10)).length
);
56 array
[item
++] = new TestCase( SECTION
, "(Array('1')).length", 1, (Array('1')).length
);
57 array
[item
++] = new TestCase( SECTION
, "(Array(1000)).length", 1000, (Array(1000)).length
);
58 array
[item
++] = new TestCase( SECTION
, "(Array('1000')).length", 1, (Array('1000')).length
);
59 array
[item
++] = new TestCase( SECTION
, "(Array(4294967295)).length", ToUint32(4294967295), (Array(4294967295)).length
);
60 array
[item
++] = new TestCase( SECTION
, "(Array(Math.pow(2,31)-1)).length", ToUint32(Math
.pow(2,31)-1), (Array(Math
.pow(2,31)-1)).length
);
61 array
[item
++] = new TestCase( SECTION
, "(Array(Math.pow(2,31))).length", ToUint32(Math
.pow(2,31)), (Array(Math
.pow(2,31))).length
);
62 array
[item
++] = new TestCase( SECTION
, "(Array(Math.pow(2,31)+1)).length", ToUint32(Math
.pow(2,31)+1), (Array(Math
.pow(2,31)+1)).length
);
63 array
[item
++] = new TestCase( SECTION
, "(Array('8589934592')).length", 1, (Array("8589934592")).length
);
64 array
[item
++] = new TestCase( SECTION
, "(Array('4294967296')).length", 1, (Array("4294967296")).length
);
65 array
[item
++] = new TestCase( SECTION
, "(Array(1073741823)).length", ToUint32(1073741823), (Array(1073741823)).length
);
66 array
[item
++] = new TestCase( SECTION
, "(Array(1073741824)).length", ToUint32(1073741824), (Array(1073741824)).length
);
67 array
[item
++] = new TestCase( SECTION
, "(Array('a string')).length", 1, (Array("a string")).length
);
72 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
73 testcases
[tc
].passed
= writeTestCaseResult(
76 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
);
77 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
82 function ToUint32( n
) {
84 var sign
= ( n
< 0 ) ? -1 : 1;
86 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
89 n
= sign
* Math
.floor( Math
.abs(n
) )
91 n
= n
% Math
.pow(2,32);