]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Array/15.4.2.2-1.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.2.2-1.js
24 ECMA Section: 15.4.2.2 new Array(len)
26 Description: This description only applies of the constructor is
27 given two or more arguments.
29 The [[Prototype]] property of the newly constructed
30 object is set to the original Array prototype object,
31 the one that is the initial value of Array.prototype(0)
34 The [[Class]] property of the newly constructed object
37 If the argument len is a number, then the length
38 property of the newly constructed object is set to
41 If the argument len is not a number, then the length
42 property of the newly constructed object is set to 1
43 and the 0 property of the newly constructed object is
46 This file tests cases where len is a number.
48 The cases in this test need to be updated since the
49 ToUint32 description has changed.
51 Author: christine@netscape.com
54 var SECTION
= "15.4.2.2-1";
55 var VERSION
= "ECMA_1";
57 var TITLE
= "The Array Constructor: new Array( len )";
59 writeHeaderToLog( SECTION
+ " "+ TITLE
);
61 var testcases
= getTestCases();
64 function getTestCases() {
65 var array
= new Array();
68 array
[item
++] = new TestCase( SECTION
, "new Array(0)", "", (new Array(0)).toString() );
69 array
[item
++] = new TestCase( SECTION
, "typeof new Array(0)", "object", (typeof new Array(0)) );
70 array
[item
++] = new TestCase( SECTION
, "(new Array(0)).length", 0, (new Array(0)).length
);
71 array
[item
++] = new TestCase( SECTION
, "(new Array(0)).toString", Array
.prototype.toString
, (new Array(0)).toString
);
73 array
[item
++] = new TestCase( SECTION
, "new Array(1)", "", (new Array(1)).toString() );
74 array
[item
++] = new TestCase( SECTION
, "new Array(1).length", 1, (new Array(1)).length
);
75 array
[item
++] = new TestCase( SECTION
, "(new Array(1)).toString", Array
.prototype.toString
, (new Array(1)).toString
);
77 array
[item
++] = new TestCase( SECTION
, "(new Array(-0)).length", 0, (new Array(-0)).length
);
78 array
[item
++] = new TestCase( SECTION
, "(new Array(0)).length", 0, (new Array(0)).length
);
80 array
[item
++] = new TestCase( SECTION
, "(new Array(10)).length", 10, (new Array(10)).length
);
81 array
[item
++] = new TestCase( SECTION
, "(new Array('1')).length", 1, (new Array('1')).length
);
82 array
[item
++] = new TestCase( SECTION
, "(new Array(1000)).length", 1000, (new Array(1000)).length
);
83 array
[item
++] = new TestCase( SECTION
, "(new Array('1000')).length", 1, (new Array('1000')).length
);
85 array
[item
++] = new TestCase( SECTION
, "(new Array(4294967295)).length", ToUint32(4294967295), (new Array(4294967295)).length
);
87 array
[item
++] = new TestCase( SECTION
, "(new Array('8589934592')).length", 1, (new Array("8589934592")).length
);
88 array
[item
++] = new TestCase( SECTION
, "(new Array('4294967296')).length", 1, (new Array("4294967296")).length
);
89 array
[item
++] = new TestCase( SECTION
, "(new Array(1073741824)).length", ToUint32(1073741824), (new Array(1073741824)).length
);
94 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
95 testcases
[tc
].passed
= writeTestCaseResult(
98 testcases
[tc
].description
+" = "+
99 testcases
[tc
].actual
);
101 testcases
[tc
].reason
+= ( testcases
[tc
].passed
)
106 return ( testcases
);
108 function ToUint32( n
) {
110 var sign
= ( n
< 0 ) ? -1 : 1;
112 if ( Math
.abs( n
) == 0 || Math
.abs( n
) == Number
.POSITIVE_INFINITY
) {
115 n
= sign
* Math
.floor( Math
.abs(n
) )
117 n
= n
% Math
.pow(2,32);