1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Array/15.4.5.2-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 15.4.5.2-2.js 1.12 + ECMA Section: Array.length 1.13 + Description: 1.14 + 15.4.5.2 length 1.15 + The length property of this Array object is always numerically greater 1.16 + than the name of every property whose name is an array index. 1.17 + 1.18 + The length property has the attributes { DontEnum, DontDelete }. 1.19 + 1.20 + This test verifies that the Array.length property is not Read Only. 1.21 + 1.22 + Author: christine@netscape.com 1.23 + Date: 12 november 1997 1.24 +*/ 1.25 + 1.26 +var SECTION = "15.4.5.2-2"; 1.27 +var VERSION = "ECMA_1"; 1.28 +startTest(); 1.29 +var TITLE = "Array.length"; 1.30 + 1.31 +writeHeaderToLog( SECTION + " "+ TITLE); 1.32 + 1.33 +addCase( new Array(), 0, Math.pow(2,14), Math.pow(2,14) ); 1.34 + 1.35 +addCase( new Array(), 0, 1, 1 ); 1.36 + 1.37 +addCase( new Array(Math.pow(2,12)), Math.pow(2,12), 0, 0 ); 1.38 +addCase( new Array(Math.pow(2,13)), Math.pow(2,13), Math.pow(2,12), Math.pow(2,12) ); 1.39 +addCase( new Array(Math.pow(2,12)), Math.pow(2,12), Math.pow(2,12), Math.pow(2,12) ); 1.40 +addCase( new Array(Math.pow(2,14)), Math.pow(2,14), Math.pow(2,12), Math.pow(2,12) ) 1.41 + 1.42 +// some tests where array is not empty 1.43 +// array is populated with strings 1.44 + for ( var arg = "", i = 0; i < Math.pow(2,12); i++ ) { 1.45 + arg += String(i) + ( i != Math.pow(2,12)-1 ? "," : "" ); 1.46 + 1.47 + } 1.48 +// print(i +":"+arg); 1.49 + 1.50 +var a = eval( "new Array("+arg+")" ); 1.51 + 1.52 +addCase( a, i, i, i ); 1.53 +addCase( a, i, Math.pow(2,12)+i+1, Math.pow(2,12)+i+1, true ); 1.54 +addCase( a, Math.pow(2,12)+5, 0, 0, true ); 1.55 + 1.56 +test(); 1.57 + 1.58 +function addCase( object, old_len, set_len, new_len, checkitems ) { 1.59 + object.length = set_len; 1.60 + 1.61 + new TestCase( SECTION, 1.62 + "array = new Array("+ old_len+"); array.length = " + set_len + 1.63 + "; array.length", 1.64 + new_len, 1.65 + object.length ); 1.66 + 1.67 + if ( checkitems ) { 1.68 + // verify that items between old and newlen are all undefined 1.69 + if ( new_len < old_len ) { 1.70 + var passed = true; 1.71 + for ( var i = new_len; i < old_len; i++ ) { 1.72 + if ( object[i] != void 0 ) { 1.73 + passed = false; 1.74 + } 1.75 + } 1.76 + new TestCase( SECTION, 1.77 + "verify that array items have been deleted", 1.78 + true, 1.79 + passed ); 1.80 + } 1.81 + if ( new_len > old_len ) { 1.82 + var passed = true; 1.83 + for ( var i = old_len; i < new_len; i++ ) { 1.84 + if ( object[i] != void 0 ) { 1.85 + passed = false; 1.86 + } 1.87 + } 1.88 + new TestCase( SECTION, 1.89 + "verify that new items are undefined", 1.90 + true, 1.91 + passed ); 1.92 + } 1.93 + } 1.94 + 1.95 +} 1.96 +