js/src/tests/ecma/Array/15.4.1.1.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:ec2a93959737
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.1.js
9 ECMA Section: 15.4.1 Array( item0, item1,... )
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 creation new Array(...) with
15 the same arguments.
16
17 An array is created and returned as if by the expression
18 new Array( item0, item1, ... ).
19
20 Author: christine@netscape.com
21 Date: 7 october 1997
22 */
23 var SECTION = "15.4.1.1";
24 var VERSION = "ECMA_1";
25 startTest();
26 var TITLE = "Array Constructor Called as a Function";
27
28 writeHeaderToLog( SECTION + " "+ TITLE);
29
30 new TestCase( SECTION,
31 "typeof Array(1,2)",
32 "object",
33 typeof Array(1,2) );
34
35 new TestCase( SECTION,
36 "(Array(1,2)).toString",
37 Array.prototype.toString,
38 (Array(1,2)).toString );
39
40 new TestCase( SECTION,
41 "var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()",
42 "[object Array]",
43 eval("var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()") );
44
45 new TestCase( SECTION,
46 "(Array(1,2)).length",
47 2,
48 (Array(1,2)).length );
49
50 new TestCase( SECTION,
51 "var arr = (Array(1,2)); arr[0]",
52 1,
53 eval("var arr = (Array(1,2)); arr[0]") );
54
55 new TestCase( SECTION,
56 "var arr = (Array(1,2)); arr[1]",
57 2,
58 eval("var arr = (Array(1,2)); arr[1]") );
59
60 new TestCase( SECTION,
61 "var arr = (Array(1,2)); String(arr)",
62 "1,2",
63 eval("var arr = (Array(1,2)); String(arr)") );
64
65 test();
66
67 function ToUint32( n ) {
68 n = Number( n );
69 if( isNaN(n) || n == 0 || n == Number.POSITIVE_INFINITY ||
70 n == Number.NEGATIVE_INFINITY ) {
71 return 0;
72 }
73 var sign = n < 0 ? -1 : 1;
74
75 return ( sign * ( n * Math.floor( Math.abs(n) ) ) ) % Math.pow(2, 32);
76 }
77

mercurial