Home | History | Annotate | Download | only in Array
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          15.4.5.1-2.js
     24     ECMA Section:       [[ Put]] (P, V)
     25     Description:
     26     Array objects use a variation of the [[Put]] method used for other native
     27     ECMAScript objects (section 8.6.2.2).
     28 
     29     Assume A is an Array object and P is a string.
     30 
     31     When the [[Put]] method of A is called with property P and value V, the
     32     following steps are taken:
     33 
     34     1.  Call the [[CanPut]] method of A with name P.
     35     2.  If Result(1) is false, return.
     36     3.  If A doesn't have a property with name P, go to step 7.
     37     4.  If P is "length", go to step 12.
     38     5.  Set the value of property P of A to V.
     39     6.  Go to step 8.
     40     7.  Create a property with name P, set its value to V and give it empty
     41         attributes.
     42     8.  If P is not an array index, return.
     43     9.  If A itself has a property (not an inherited property) named "length",
     44         andToUint32(P) is less than the value of the length property of A, then
     45         return.
     46     10. Change (or set) the value of the length property of A to ToUint32(P)+1.
     47     11. Return.
     48     12. Compute ToUint32(V).
     49     13. For every integer k that is less than the value of the length property
     50         of A but not less than Result(12), if A itself has a property (not an
     51         inherited property) named ToString(k), then delete that property.
     52     14. Set the value of property P of A to Result(12).
     53     15. Return.
     54 
     55 
     56     These are testcases from Waldemar, detailed in
     57     http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123552
     58 
     59     Author:             christine (at) netscape.com
     60     Date:               15 June 1998
     61 */
     62 
     63     var SECTION = "15.4.5.1-2";
     64     var VERSION = "ECMA_1";
     65     startTest();
     66     var TITLE   = "Array [[Put]] (P,V)";
     67 
     68     writeHeaderToLog( SECTION + " "+ TITLE);
     69 
     70     var testcases = new Array();
     71 
     72     var a = new Array();
     73 
     74     AddCase( "3.00", "three" );
     75     AddCase( "00010", "eight" );
     76     AddCase( "37xyz", "thirty-five" );
     77     AddCase("5000000000", 5)
     78     AddCase( "-2", -3 );
     79 
     80     testcases[tc++] = new TestCase( SECTION,
     81         "a[10]",
     82         void 0,
     83         a[10] );
     84 
     85     testcases[tc++] = new TestCase( SECTION,
     86         "a[3]",
     87         void 0,
     88         a[3] );
     89 
     90     a[4] = "four";
     91 
     92     testcases[tc++] = new TestCase( SECTION,
     93         "a[4] = \"four\"; a[4]",
     94         "four",
     95         a[4] );
     96 
     97     testcases[tc++] = new TestCase( SECTION,
     98         "a[\"4\"]",
     99         "four",
    100         a["4"] );
    101 
    102     testcases[tc++] = new TestCase( SECTION,
    103         "a[\"4.00\"]",
    104         void 0,
    105         a["4.00"] );
    106 
    107     testcases[tc++] = new TestCase( SECTION,
    108         "a.length",
    109         5,
    110         a.length );
    111 
    112 
    113     a["5000000000"] = 5;
    114 
    115     testcases[tc++] = new TestCase( SECTION,
    116         "a[\"5000000000\"] = 5; a.length",
    117         5,
    118         a.length );
    119 
    120     testcases[tc++] = new TestCase( SECTION,
    121         "a[\"-2\"] = -3; a.length",
    122         5,
    123         a.length );
    124 
    125     test();
    126 
    127 function AddCase ( arg, value ) {
    128 
    129     a[arg] = value;
    130 
    131     testcases[tc++] = new TestCase( SECTION,
    132         "a[\"" + arg + "\"] =  "+ value +"; a.length",
    133         0,
    134         a.length );
    135 }
    136 
    137 
    138 function test() {
    139     for ( tc=0; tc < testcases.length; tc++ ) {
    140         testcases[tc].passed = writeTestCaseResult(
    141                             testcases[tc].expect,
    142                             testcases[tc].actual,
    143                             testcases[tc].description +" = "+
    144                             testcases[tc].actual );
    145 
    146         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    147     }
    148     stopTest();
    149     return ( testcases );
    150 }
    151