js/src/tests/ecma/Array/15.4.4.4-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.4.4-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     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.4.3-1.js
    1.12 +   ECMA Section:       15.4.4.3-1 Array.prototype.reverse()
    1.13 +   Description:
    1.14 +
    1.15 +   The elements of the array are rearranged so as to reverse their order.
    1.16 +   This object is returned as the result of the call.
    1.17 +
    1.18 +   1.   Call the [[Get]] method of this object with argument "length".
    1.19 +   2.   Call ToUint32(Result(1)).
    1.20 +   3.   Compute floor(Result(2)/2).
    1.21 +   4.   Let k be 0.
    1.22 +   5.   If k equals Result(3), return this object.
    1.23 +   6.   Compute Result(2)k1.
    1.24 +   7.   Call ToString(k).
    1.25 +   8.   ToString(Result(6)).
    1.26 +   9.   Call the [[Get]] method of this object with argument Result(7).
    1.27 +   10.   Call the [[Get]] method of this object with argument Result(8).
    1.28 +   11.   If this object has a property named by Result(8), go to step 12; but
    1.29 +   if this object has no property named by Result(8), then go to either
    1.30 +   step 12 or step 14, depending on the implementation.
    1.31 +   12.   Call the [[Put]] method of this object with arguments Result(7) and
    1.32 +   Result(10).
    1.33 +   13.   Go to step 15.
    1.34 +   14.   Call the [[Delete]] method on this object, providing Result(7) as the
    1.35 +   name of the property to delete.
    1.36 +   15.   If this object has a property named by Result(7), go to step 16; but if
    1.37 +   this object has no property named by Result(7), then go to either step 16
    1.38 +   or step 18, depending on the implementation.
    1.39 +   16.   Call the [[Put]] method of this object with arguments Result(8) and
    1.40 +   Result(9).
    1.41 +   17.   Go to step 19.
    1.42 +   18.   Call the [[Delete]] method on this object, providing Result(8) as the
    1.43 +   name of the property to delete.
    1.44 +   19.   Increase k by 1.
    1.45 +   20.   Go to step 5.
    1.46 +
    1.47 +   Note that the reverse function is intentionally generic; it does not require
    1.48 +   that its this value be an Array object. Therefore it can be transferred to other
    1.49 +   kinds of objects for use as a method. Whether the reverse function can be applied
    1.50 +   successfully to a host object is implementation dependent.
    1.51 +
    1.52 +   Note:   Array.prototype.reverse allows some flexibility in implementation
    1.53 +   regarding array indices that have not been populated. This test covers the
    1.54 +   cases in which unpopulated indices are not deleted, since the JavaScript
    1.55 +   implementation does not delete uninitialzed indices.
    1.56 +
    1.57 +   Author:             christine@netscape.com
    1.58 +   Date:               7 october 1997
    1.59 +*/
    1.60 +
    1.61 +var SECTION = "15.4.4.4-1";
    1.62 +var VERSION = "ECMA_1";
    1.63 +startTest();
    1.64 +
    1.65 +writeHeaderToLog( SECTION + " Array.prototype.reverse()");
    1.66 +
    1.67 +var ARR_PROTOTYPE = Array.prototype;
    1.68 +
    1.69 +new TestCase( SECTION, "Array.prototype.reverse.length",           0,      Array.prototype.reverse.length );
    1.70 +new TestCase( SECTION, "delete Array.prototype.reverse.length",    false,  delete Array.prototype.reverse.length );
    1.71 +new TestCase( SECTION, "delete Array.prototype.reverse.length; Array.prototype.reverse.length",    0, eval("delete Array.prototype.reverse.length; Array.prototype.reverse.length") );
    1.72 +
    1.73 +// length of array is 0
    1.74 +new TestCase(   SECTION,
    1.75 +		"var A = new Array();   A.reverse(); A.length",
    1.76 +		0,
    1.77 +		eval("var A = new Array();   A.reverse(); A.length") );
    1.78 +
    1.79 +test();
    1.80 +
    1.81 +function CheckItems( R, A ) {
    1.82 +  for ( var i = 0; i < R.length; i++ ) {
    1.83 +    new TestCase(
    1.84 +      SECTION,
    1.85 +      "A["+i+ "]",
    1.86 +      R[i],
    1.87 +      A[i] );
    1.88 +  }
    1.89 +}
    1.90 +test();
    1.91 +
    1.92 +function Object_1( value ) {
    1.93 +  this.array = value.split(",");
    1.94 +  this.length = this.array.length;
    1.95 +  for ( var i = 0; i < this.length; i++ ) {
    1.96 +    this[i] = eval(this.array[i]);
    1.97 +  }
    1.98 +  this.join = Array.prototype.reverse;
    1.99 +  this.getClass = Object.prototype.toString;
   1.100 +}
   1.101 +function Reverse( array ) {
   1.102 +  var r2 = array.length;
   1.103 +  var k = 0;
   1.104 +  var r3 = Math.floor( r2/2 );
   1.105 +  if ( r3 == k ) {
   1.106 +    return array;
   1.107 +  }
   1.108 +
   1.109 +  for ( k = 0;  k < r3; k++ ) {
   1.110 +    var r6 = r2 - k - 1;
   1.111 +//        var r7 = String( k );
   1.112 +    var r7 = k;
   1.113 +    var r8 = String( r6 );
   1.114 +
   1.115 +    var r9 = array[r7];
   1.116 +    var r10 = array[r8];
   1.117 +
   1.118 +    array[r7] = r10;
   1.119 +    array[r8] = r9;
   1.120 +  }
   1.121 +
   1.122 +  return array;
   1.123 +}
   1.124 +function Iterate( array ) {
   1.125 +  for ( var i = 0; i < array.length; i++ ) {
   1.126 +//        print( i+": "+ array[String(i)] );
   1.127 +  }
   1.128 +}
   1.129 +
   1.130 +function Object_1( value ) {
   1.131 +  this.array = value.split(",");
   1.132 +  this.length = this.array.length;
   1.133 +  for ( var i = 0; i < this.length; i++ ) {
   1.134 +    this[i] = this.array[i];
   1.135 +  }
   1.136 +  this.reverse = Array.prototype.reverse;
   1.137 +  this.getClass = Object.prototype.toString;
   1.138 +}

mercurial