js/src/tests/ecma/Array/15.4.5.1-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Array/15.4.5.1-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     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.1-1.js
    1.12 +   ECMA Section:       [[ Put]] (P, V)
    1.13 +   Description:
    1.14 +   Array objects use a variation of the [[Put]] method used for other native
    1.15 +   ECMAScript objects (section 8.6.2.2).
    1.16 +
    1.17 +   Assume A is an Array object and P is a string.
    1.18 +
    1.19 +   When the [[Put]] method of A is called with property P and value V, the
    1.20 +   following steps are taken:
    1.21 +
    1.22 +   1.  Call the [[CanPut]] method of A with name P.
    1.23 +   2.  If Result(1) is false, return.
    1.24 +   3.  If A doesn't have a property with name P, go to step 7.
    1.25 +   4.  If P is "length", go to step 12.
    1.26 +   5.  Set the value of property P of A to V.
    1.27 +   6.  Go to step 8.
    1.28 +   7.  Create a property with name P, set its value to V and give it empty
    1.29 +   attributes.
    1.30 +   8.  If P is not an array index, return.
    1.31 +   9.  If A itself has a property (not an inherited property) named "length",
    1.32 +   andToUint32(P) is less than the value of the length property of A, then
    1.33 +   return.
    1.34 +   10. Change (or set) the value of the length property of A to ToUint32(P)+1.
    1.35 +   11. Return.
    1.36 +   12. Compute ToUint32(V).
    1.37 +   13. For every integer k that is less than the value of the length property
    1.38 +   of A but not less than Result(12), if A itself has a property (not an
    1.39 +   inherited property) named ToString(k), then delete that property.
    1.40 +   14. Set the value of property P of A to Result(12).
    1.41 +   15. Return.
    1.42 +   Author:             christine@netscape.com
    1.43 +   Date:               12 november 1997
    1.44 +*/
    1.45 +
    1.46 +var SECTION = "15.4.5.1-1";
    1.47 +var VERSION = "ECMA_1";
    1.48 +startTest();
    1.49 +var TITLE   = "Array [[Put]] (P, V)";
    1.50 +
    1.51 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.52 +
    1.53 +
    1.54 +// P is "length"
    1.55 +
    1.56 +new TestCase(   SECTION,
    1.57 +		"var A = new Array(); A.length = 1000; A.length",
    1.58 +		1000,
    1.59 +		eval("var A = new Array(); A.length = 1000; A.length") );
    1.60 +
    1.61 +// A has Property P, and P is not length or an array index
    1.62 +new TestCase(   SECTION,
    1.63 +		"var A = new Array(1000); A.name = 'name of this array'; A.name",
    1.64 +		'name of this array',
    1.65 +		eval("var A = new Array(1000); A.name = 'name of this array'; A.name") );
    1.66 +
    1.67 +new TestCase(   SECTION,
    1.68 +		"var A = new Array(1000); A.name = 'name of this array'; A.length",
    1.69 +		1000,
    1.70 +		eval("var A = new Array(1000); A.name = 'name of this array'; A.length") );
    1.71 +
    1.72 +
    1.73 +// A has Property P, P is not length, P is an array index, and ToUint32(p) is less than the
    1.74 +// value of length
    1.75 +
    1.76 +new TestCase(   SECTION,
    1.77 +		"var A = new Array(1000); A[123] = 'hola'; A[123]",
    1.78 +		'hola',
    1.79 +		eval("var A = new Array(1000); A[123] = 'hola'; A[123]") );
    1.80 +
    1.81 +new TestCase(   SECTION,
    1.82 +		"var A = new Array(1000); A[123] = 'hola'; A.length",
    1.83 +		1000,
    1.84 +		eval("var A = new Array(1000); A[123] = 'hola'; A.length") );
    1.85 +
    1.86 +
    1.87 +for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) {
    1.88 +  if (i === "u".charCodeAt(0) || i === "x".charCodeAt(0))
    1.89 +    continue;
    1.90 +  TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'";
    1.91 +  if ( i < 0x00FF - 1   ) {
    1.92 +    TEST_STRING += ",";
    1.93 +  } else {
    1.94 +    TEST_STRING += ");"
    1.95 +      }
    1.96 +}
    1.97 +
    1.98 +var LENGTH = 0x00ff - 0x0020 - 2 /* "u"/"x" exclusions above */;
    1.99 +
   1.100 +new TestCase(   SECTION,
   1.101 +		TEST_STRING +" A[150] = 'hello'; A[150]",
   1.102 +		'hello',
   1.103 +		eval( TEST_STRING + " A[150] = 'hello'; A[150]" ) );
   1.104 +
   1.105 +new TestCase(   SECTION,
   1.106 +		TEST_STRING +" A[150] = 'hello'; A[150]",
   1.107 +		LENGTH,
   1.108 +		eval( TEST_STRING + " A[150] = 'hello'; A.length" ) );
   1.109 +
   1.110 +// A has Property P, P is not length, P is an array index, and ToUint32(p) is not less than the
   1.111 +// value of length
   1.112 +
   1.113 +new TestCase(   SECTION,
   1.114 +		"var A = new Array(); A[123] = true; A.length",
   1.115 +		124,
   1.116 +		eval("var A = new Array(); A[123] = true; A.length") );
   1.117 +
   1.118 +new TestCase(   SECTION,
   1.119 +		"var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length",
   1.120 +		16,
   1.121 +		eval("var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A.length") );
   1.122 +
   1.123 +for ( var i = 0; i < A.length; i++ ) {
   1.124 +  new TestCase( SECTION,
   1.125 +		"var A = new Array(0,1,2,3,4,5,6,7,8,9,10); A[15] ='15'; A[" +i +"]",
   1.126 +		(i <= 10) ? i : ( i == 15 ? '15' : void 0 ),
   1.127 +		A[i] );
   1.128 +}
   1.129 +// P is not an array index, and P is not "length"
   1.130 +
   1.131 +new TestCase(   SECTION,
   1.132 +		"var A = new Array(); A.join.length = 4; A.join.length",
   1.133 +		1,
   1.134 +		eval("var A = new Array(); A.join.length = 4; A.join.length") );
   1.135 +
   1.136 +new TestCase(   SECTION,
   1.137 +		"var A = new Array(); A.join.length = 4; A.length",
   1.138 +		0,
   1.139 +		eval("var A = new Array(); A.join.length = 4; A.length") );
   1.140 +
   1.141 +test();

mercurial