michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.4.1.1.js michael@0: ECMA Section: 15.4.1 Array( item0, item1,... ) michael@0: michael@0: Description: When Array is called as a function rather than as a michael@0: constructor, it creates and initializes a new array michael@0: object. Thus, the function call Array(...) is michael@0: equivalent to the object creation new Array(...) with michael@0: the same arguments. michael@0: michael@0: An array is created and returned as if by the expression michael@0: new Array( item0, item1, ... ). michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 7 october 1997 michael@0: */ michael@0: var SECTION = "15.4.1.1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Array Constructor Called as a Function"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "typeof Array(1,2)", michael@0: "object", michael@0: typeof Array(1,2) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1,2)).toString", michael@0: Array.prototype.toString, michael@0: (Array(1,2)).toString ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()", michael@0: "[object Array]", michael@0: eval("var arr = Array(1,2,3); arr.toString = Object.prototype.toString; arr.toString()") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1,2)).length", michael@0: 2, michael@0: (Array(1,2)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var arr = (Array(1,2)); arr[0]", michael@0: 1, michael@0: eval("var arr = (Array(1,2)); arr[0]") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var arr = (Array(1,2)); arr[1]", michael@0: 2, michael@0: eval("var arr = (Array(1,2)); arr[1]") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var arr = (Array(1,2)); String(arr)", michael@0: "1,2", michael@0: eval("var arr = (Array(1,2)); String(arr)") ); michael@0: michael@0: test(); michael@0: michael@0: function ToUint32( n ) { michael@0: n = Number( n ); michael@0: if( isNaN(n) || n == 0 || n == Number.POSITIVE_INFINITY || michael@0: n == Number.NEGATIVE_INFINITY ) { michael@0: return 0; michael@0: } michael@0: var sign = n < 0 ? -1 : 1; michael@0: michael@0: return ( sign * ( n * Math.floor( Math.abs(n) ) ) ) % Math.pow(2, 32); michael@0: } michael@0: