]>
Commit | Line | Data |
---|---|---|
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/ | |
5 | * | |
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. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
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 | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: 15.4.1.2.js | |
24 | ECMA Section: 15.4.1.2 Array(len) | |
25 | ||
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 | |
30 | the same arguments. | |
31 | ||
32 | An array is created and returned as if by the | |
33 | expression new Array(len). | |
34 | ||
35 | Author: christine@netscape.com | |
36 | Date: 7 october 1997 | |
37 | */ | |
38 | var SECTION = "15.4.1.2"; | |
39 | var VERSION = "ECMA_1"; | |
40 | startTest(); | |
41 | var TITLE = "Array Constructor Called as a Function: Array(len)"; | |
42 | ||
43 | writeHeaderToLog( SECTION + " "+ TITLE); | |
44 | ||
45 | var testcases = getTestCases(); | |
46 | test(); | |
47 | ||
48 | function getTestCases() { | |
49 | var array = new Array(); | |
50 | var item = 0; | |
51 | ||
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 ); | |
68 | ||
69 | return ( array ); | |
70 | } | |
71 | function test() { | |
72 | for ( tc=0; tc < testcases.length; tc++ ) { | |
73 | testcases[tc].passed = writeTestCaseResult( | |
74 | testcases[tc].expect, | |
75 | testcases[tc].actual, | |
76 | testcases[tc].description +" = "+ testcases[tc].actual ); | |
77 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
78 | } | |
79 | stopTest(); | |
80 | return ( testcases ); | |
81 | } | |
82 | function ToUint32( n ) { | |
83 | n = Number( n ); | |
84 | var sign = ( n < 0 ) ? -1 : 1; | |
85 | ||
86 | if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { | |
87 | return 0; | |
88 | } | |
89 | n = sign * Math.floor( Math.abs(n) ) | |
90 | ||
91 | n = n % Math.pow(2,32); | |
92 | ||
93 | if ( n < 0 ){ | |
94 | n += Math.pow(2,32); | |
95 | } | |
96 | ||
97 | return ( n ); | |
98 | } |