Debian Codegraph @

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