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.2.js michael@0: ECMA Section: 15.4.1.2 Array(len) 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 creationi new Array(...) with michael@0: the same arguments. michael@0: michael@0: An array is created and returned as if by the michael@0: expression new Array(len). michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 7 october 1997 michael@0: */ michael@0: var SECTION = "15.4.1.2"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Array Constructor Called as a Function: Array(len)"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array()).length", michael@0: 0, michael@0: (Array()).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(0)).length", michael@0: 0, michael@0: (Array(0)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1)).length", michael@0: 1, michael@0: (Array(1)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(10)).length", michael@0: 10, michael@0: (Array(10)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array('1')).length", michael@0: 1, michael@0: (Array('1')).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1000)).length", michael@0: 1000, michael@0: (Array(1000)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array('1000')).length", michael@0: 1, michael@0: (Array('1000')).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(4294967295)).length", michael@0: ToUint32(4294967295), michael@0: (Array(4294967295)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(Math.pow(2,31)-1)).length", michael@0: ToUint32(Math.pow(2,31)-1), michael@0: (Array(Math.pow(2,31)-1)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(Math.pow(2,31))).length", michael@0: ToUint32(Math.pow(2,31)), michael@0: (Array(Math.pow(2,31))).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(Math.pow(2,31)+1)).length", michael@0: ToUint32(Math.pow(2,31)+1), michael@0: (Array(Math.pow(2,31)+1)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array('8589934592')).length", michael@0: 1, michael@0: (Array("8589934592")).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array('4294967296')).length", michael@0: 1, michael@0: (Array("4294967296")).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1073741823)).length", michael@0: ToUint32(1073741823), michael@0: (Array(1073741823)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array(1073741824)).length", michael@0: ToUint32(1073741824), michael@0: (Array(1073741824)).length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "(Array('a string')).length", michael@0: 1, michael@0: (Array("a string")).length ); michael@0: michael@0: test(); michael@0: michael@0: function ToUint32( n ) { michael@0: n = Number( n ); michael@0: var sign = ( n < 0 ) ? -1 : 1; michael@0: michael@0: if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) { michael@0: return 0; michael@0: } michael@0: n = sign * Math.floor( Math.abs(n) ) michael@0: michael@0: n = n % Math.pow(2,32); michael@0: michael@0: if ( n < 0 ){ michael@0: n += Math.pow(2,32); michael@0: } michael@0: michael@0: return ( n ); michael@0: }