js/src/tests/ecma/Array/15.4.5.1-2.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-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     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-2.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 +
    1.43 +
    1.44 +   These are gTestcases from Waldemar, detailed in
    1.45 +   http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123552
    1.46 +
    1.47 +   Author:             christine@netscape.com
    1.48 +   Date:               15 June 1998
    1.49 +*/
    1.50 +
    1.51 +var SECTION = "15.4.5.1-2";
    1.52 +var VERSION = "ECMA_1";
    1.53 +startTest();
    1.54 +var TITLE   = "Array [[Put]] (P,V)";
    1.55 +
    1.56 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.57 +
    1.58 +var a = new Array();
    1.59 +
    1.60 +AddCase( "3.00", "three" );
    1.61 +AddCase( "00010", "eight" );
    1.62 +AddCase( "37xyz", "thirty-five" );
    1.63 +AddCase("5000000000", 5)
    1.64 +  AddCase( "-2", -3 );
    1.65 +
    1.66 +new TestCase( SECTION,
    1.67 +	      "a[10]",
    1.68 +	      void 0,
    1.69 +	      a[10] );
    1.70 +
    1.71 +new TestCase( SECTION,
    1.72 +	      "a[3]",
    1.73 +	      void 0,
    1.74 +	      a[3] );
    1.75 +
    1.76 +a[4] = "four";
    1.77 +
    1.78 +new TestCase( SECTION,
    1.79 +	      "a[4] = \"four\"; a[4]",
    1.80 +	      "four",
    1.81 +	      a[4] );
    1.82 +
    1.83 +new TestCase( SECTION,
    1.84 +	      "a[\"4\"]",
    1.85 +	      "four",
    1.86 +	      a["4"] );
    1.87 +
    1.88 +new TestCase( SECTION,
    1.89 +	      "a[\"4.00\"]",
    1.90 +	      void 0,
    1.91 +	      a["4.00"] );
    1.92 +
    1.93 +new TestCase( SECTION,
    1.94 +	      "a.length",
    1.95 +	      5,
    1.96 +	      a.length );
    1.97 +
    1.98 +
    1.99 +a["5000000000"] = 5;
   1.100 +
   1.101 +new TestCase( SECTION,
   1.102 +	      "a[\"5000000000\"] = 5; a.length",
   1.103 +	      5,
   1.104 +	      a.length );
   1.105 +
   1.106 +new TestCase( SECTION,
   1.107 +	      "a[\"-2\"] = -3; a.length",
   1.108 +	      5,
   1.109 +	      a.length );
   1.110 +
   1.111 +test();
   1.112 +
   1.113 +function AddCase ( arg, value ) {
   1.114 +
   1.115 +  a[arg] = value;
   1.116 +
   1.117 +  new TestCase( SECTION,
   1.118 +		"a[\"" + arg + "\"] =  "+ value +"; a.length",
   1.119 +		0,
   1.120 +		a.length );
   1.121 +}

mercurial