js/src/tests/ecma/Array/15.4.4.4-2.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8    File Name:          15.4.4.3-1.js
     9    ECMA Section:       15.4.4.3-1 Array.prototype.reverse()
    10    Description:
    12    The elements of the array are rearranged so as to reverse their order.
    13    This object is returned as the result of the call.
    15    1.   Call the [[Get]] method of this object with argument "length".
    16    2.   Call ToUint32(Result(1)).
    17    3.   Compute floor(Result(2)/2).
    18    4.   Let k be 0.
    19    5.   If k equals Result(3), return this object.
    20    6.   Compute Result(2)k1.
    21    7.   Call ToString(k).
    22    8.   ToString(Result(6)).
    23    9.   Call the [[Get]] method of this object with argument Result(7).
    24    10.   Call the [[Get]] method of this object with argument Result(8).
    25    11.   If this object has a property named by Result(8), go to step 12; but
    26    if this object has no property named by Result(8), then go to either
    27    step 12 or step 14, depending on the implementation.
    28    12.   Call the [[Put]] method of this object with arguments Result(7) and
    29    Result(10).
    30    13.   Go to step 15.
    31    14.   Call the [[Delete]] method on this object, providing Result(7) as the
    32    name of the property to delete.
    33    15.   If this object has a property named by Result(7), go to step 16; but if
    34    this object has no property named by Result(7), then go to either step 16
    35    or step 18, depending on the implementation.
    36    16.   Call the [[Put]] method of this object with arguments Result(8) and
    37    Result(9).
    38    17.   Go to step 19.
    39    18.   Call the [[Delete]] method on this object, providing Result(8) as the
    40    name of the property to delete.
    41    19.   Increase k by 1.
    42    20.   Go to step 5.
    44    Note that the reverse function is intentionally generic; it does not require
    45    that its this value be an Array object. Therefore it can be transferred to other
    46    kinds of objects for use as a method. Whether the reverse function can be applied
    47    successfully to a host object is implementation dependent.
    49    Note:   Array.prototype.reverse allows some flexibility in implementation
    50    regarding array indices that have not been populated. This test covers the
    51    cases in which unpopulated indices are not deleted, since the JavaScript
    52    implementation does not delete uninitialzed indices.
    54    Author:             christine@netscape.com
    55    Date:               7 october 1997
    56 */
    58 var SECTION = "15.4.4.4-1";
    59 var VERSION = "ECMA_1";
    60 startTest();
    62 writeHeaderToLog( SECTION + " Array.prototype.reverse()");
    64 var ARR_PROTOTYPE = Array.prototype;
    66 new TestCase( SECTION, "Array.prototype.reverse.length",           0,      Array.prototype.reverse.length );
    67 new TestCase( SECTION, "delete Array.prototype.reverse.length",    false,  delete Array.prototype.reverse.length );
    68 new TestCase( SECTION, "delete Array.prototype.reverse.length; Array.prototype.reverse.length",    0, eval("delete Array.prototype.reverse.length; Array.prototype.reverse.length") );
    70 // length of array is 0
    71 new TestCase(   SECTION,
    72 		"var A = new Array();   A.reverse(); A.length",
    73 		0,
    74 		eval("var A = new Array();   A.reverse(); A.length") );
    76 test();
    78 function CheckItems( R, A ) {
    79   for ( var i = 0; i < R.length; i++ ) {
    80     new TestCase(
    81       SECTION,
    82       "A["+i+ "]",
    83       R[i],
    84       A[i] );
    85   }
    86 }
    87 test();
    89 function Object_1( value ) {
    90   this.array = value.split(",");
    91   this.length = this.array.length;
    92   for ( var i = 0; i < this.length; i++ ) {
    93     this[i] = eval(this.array[i]);
    94   }
    95   this.join = Array.prototype.reverse;
    96   this.getClass = Object.prototype.toString;
    97 }
    98 function Reverse( array ) {
    99   var r2 = array.length;
   100   var k = 0;
   101   var r3 = Math.floor( r2/2 );
   102   if ( r3 == k ) {
   103     return array;
   104   }
   106   for ( k = 0;  k < r3; k++ ) {
   107     var r6 = r2 - k - 1;
   108 //        var r7 = String( k );
   109     var r7 = k;
   110     var r8 = String( r6 );
   112     var r9 = array[r7];
   113     var r10 = array[r8];
   115     array[r7] = r10;
   116     array[r8] = r9;
   117   }
   119   return array;
   120 }
   121 function Iterate( array ) {
   122   for ( var i = 0; i < array.length; i++ ) {
   123 //        print( i+": "+ array[String(i)] );
   124   }
   125 }
   127 function Object_1( value ) {
   128   this.array = value.split(",");
   129   this.length = this.array.length;
   130   for ( var i = 0; i < this.length; i++ ) {
   131     this[i] = this.array[i];
   132   }
   133   this.reverse = Array.prototype.reverse;
   134   this.getClass = Object.prototype.toString;
   135 }

mercurial