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.1-1.js michael@0: ECMA Section: [[ Put]] (P, V) michael@0: Description: michael@0: Array objects use a variation of the [[Put]] method used for other native michael@0: ECMAScript objects (section 8.6.2.2). michael@0: michael@0: Assume A is an Array object and P is a string. michael@0: michael@0: When the [[Put]] method of A is called with property P and value V, the michael@0: following steps are taken: michael@0: michael@0: 1. Call the [[CanPut]] method of A with name P. michael@0: 2. If Result(1) is false, return. michael@0: 3. If A doesn't have a property with name P, go to step 7. michael@0: 4. If P is "length", go to step 12. michael@0: 5. Set the value of property P of A to V. michael@0: 6. Go to step 8. michael@0: 7. Create a property with name P, set its value to V and give it empty michael@0: attributes. michael@0: 8. If P is not an array index, return. michael@0: 9. If A itself has a property (not an inherited property) named "length", michael@0: andToUint32(P) is less than the value of the length property of A, then michael@0: return. michael@0: 10. Change (or set) the value of the length property of A to ToUint32(P)+1. michael@0: 11. Return. michael@0: 12. Compute ToUint32(V). michael@0: 13. For every integer k that is less than the value of the length property michael@0: of A but not less than Result(12), if A itself has a property (not an michael@0: inherited property) named ToString(k), then delete that property. michael@0: 14. Set the value of property P of A to Result(12). michael@0: 15. Return. michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.4.5.1-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Array [[Put]] (P, V)"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: michael@0: // P is "length" michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(); A.length = 1000; A.length", michael@0: 1000, michael@0: eval("var A = new Array(); A.length = 1000; A.length") ); michael@0: michael@0: // A has Property P, and P is not length or an array index michael@0: new TestCase( SECTION, michael@0: "var A = new Array(1000); A.name = 'name of this array'; A.name", michael@0: 'name of this array', michael@0: eval("var A = new Array(1000); A.name = 'name of this array'; A.name") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(1000); A.name = 'name of this array'; A.length", michael@0: 1000, michael@0: eval("var A = new Array(1000); A.name = 'name of this array'; A.length") ); michael@0: michael@0: michael@0: // A has Property P, P is not length, P is an array index, and ToUint32(p) is less than the michael@0: // value of length michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(1000); A[123] = 'hola'; A[123]", michael@0: 'hola', michael@0: eval("var A = new Array(1000); A[123] = 'hola'; A[123]") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(1000); A[123] = 'hola'; A.length", michael@0: 1000, michael@0: eval("var A = new Array(1000); A[123] = 'hola'; A.length") ); michael@0: michael@0: michael@0: for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) { michael@0: if (i === "u".charCodeAt(0) || i === "x".charCodeAt(0)) michael@0: continue; michael@0: TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'"; michael@0: if ( i < 0x00FF - 1 ) { michael@0: TEST_STRING += ","; michael@0: } else { michael@0: TEST_STRING += ");" michael@0: } michael@0: } michael@0: michael@0: var LENGTH = 0x00ff - 0x0020 - 2 /* "u"/"x" exclusions above */; michael@0: michael@0: new TestCase( SECTION, michael@0: TEST_STRING +" A[150] = 'hello'; A[150]", michael@0: 'hello', michael@0: eval( TEST_STRING + " A[150] = 'hello'; A[150]" ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: TEST_STRING +" A[150] = 'hello'; A[150]", michael@0: LENGTH, michael@0: eval( TEST_STRING + " A[150] = 'hello'; A.length" ) ); michael@0: michael@0: // A has Property P, P is not length, P is an array index, and ToUint32(p) is not less than the michael@0: // value of length michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(); A[123] = true; A.length", michael@0: 124, michael@0: eval("var A = new Array(); A[123] = true; A.length") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length", michael@0: 16, michael@0: eval("var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length") ); michael@0: michael@0: for ( var i = 0; i < A.length; i++ ) { michael@0: new TestCase( SECTION, michael@0: "var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A[" +i +"]", michael@0: (i <= 10) ? i : ( i == 15 ? '15' : void 0 ), michael@0: A[i] ); michael@0: } michael@0: // P is not an array index, and P is not "length" michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(); A.join.length = 4; A.join.length", michael@0: 1, michael@0: eval("var A = new Array(); A.join.length = 4; A.join.length") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "var A = new Array(); A.join.length = 4; A.length", michael@0: 0, michael@0: eval("var A = new Array(); A.join.length = 4; A.length") ); michael@0: michael@0: test();