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.

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

mercurial