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.5.2-2.js michael@0: ECMA Section: Array.length michael@0: Description: michael@0: 15.4.5.2 length michael@0: The length property of this Array object is always numerically greater michael@0: than the name of every property whose name is an array index. michael@0: michael@0: The length property has the attributes { DontEnum, DontDelete }. michael@0: michael@0: This test verifies that the Array.length property is not Read Only. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.4.5.2-2"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Array.length"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: addCase( new Array(), 0, Math.pow(2,14), Math.pow(2,14) ); michael@0: michael@0: addCase( new Array(), 0, 1, 1 ); michael@0: michael@0: addCase( new Array(Math.pow(2,12)), Math.pow(2,12), 0, 0 ); michael@0: addCase( new Array(Math.pow(2,13)), Math.pow(2,13), Math.pow(2,12), Math.pow(2,12) ); michael@0: addCase( new Array(Math.pow(2,12)), Math.pow(2,12), Math.pow(2,12), Math.pow(2,12) ); michael@0: addCase( new Array(Math.pow(2,14)), Math.pow(2,14), Math.pow(2,12), Math.pow(2,12) ) michael@0: michael@0: // some tests where array is not empty michael@0: // array is populated with strings michael@0: for ( var arg = "", i = 0; i < Math.pow(2,12); i++ ) { michael@0: arg += String(i) + ( i != Math.pow(2,12)-1 ? "," : "" ); michael@0: michael@0: } michael@0: // print(i +":"+arg); michael@0: michael@0: var a = eval( "new Array("+arg+")" ); michael@0: michael@0: addCase( a, i, i, i ); michael@0: addCase( a, i, Math.pow(2,12)+i+1, Math.pow(2,12)+i+1, true ); michael@0: addCase( a, Math.pow(2,12)+5, 0, 0, true ); michael@0: michael@0: test(); michael@0: michael@0: function addCase( object, old_len, set_len, new_len, checkitems ) { michael@0: object.length = set_len; michael@0: michael@0: new TestCase( SECTION, michael@0: "array = new Array("+ old_len+"); array.length = " + set_len + michael@0: "; array.length", michael@0: new_len, michael@0: object.length ); michael@0: michael@0: if ( checkitems ) { michael@0: // verify that items between old and newlen are all undefined michael@0: if ( new_len < old_len ) { michael@0: var passed = true; michael@0: for ( var i = new_len; i < old_len; i++ ) { michael@0: if ( object[i] != void 0 ) { michael@0: passed = false; michael@0: } michael@0: } michael@0: new TestCase( SECTION, michael@0: "verify that array items have been deleted", michael@0: true, michael@0: passed ); michael@0: } michael@0: if ( new_len > old_len ) { michael@0: var passed = true; michael@0: for ( var i = old_len; i < new_len; i++ ) { michael@0: if ( object[i] != void 0 ) { michael@0: passed = false; michael@0: } michael@0: } michael@0: new TestCase( SECTION, michael@0: "verify that new items are undefined", michael@0: true, michael@0: passed ); michael@0: } michael@0: } michael@0: michael@0: } michael@0: