js/src/tests/ecma/Array/15.4.4.3-1.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.join()
michael@0 10 Description: The elements of this object are converted to strings and
michael@0 11 these strings are then concatenated, separated by comma
michael@0 12 characters. The result is the same as if the built-in join
michael@0 13 method were invoiked for this object with no argument.
michael@0 14 Author: christine@netscape.com, pschwartau@netscape.com
michael@0 15 Date: 07 October 1997
michael@0 16 Modified: 14 July 2002
michael@0 17 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155285
michael@0 18 ECMA-262 Ed.3 Section 15.4.4.5 Array.prototype.join()
michael@0 19 Step 3: If |separator| is |undefined|, let |separator|
michael@0 20 be the single-character string ","
michael@0 21 *
michael@0 22 */
michael@0 23
michael@0 24 var SECTION = "15.4.4.3-1";
michael@0 25 var VERSION = "ECMA_1";
michael@0 26 startTest();
michael@0 27
michael@0 28 writeHeaderToLog( SECTION + " Array.prototype.join()");
michael@0 29
michael@0 30 var ARR_PROTOTYPE = Array.prototype;
michael@0 31
michael@0 32 new TestCase( SECTION, "Array.prototype.join.length", 1, Array.prototype.join.length );
michael@0 33 new TestCase( SECTION, "delete Array.prototype.join.length", false, delete Array.prototype.join.length );
michael@0 34 new TestCase( SECTION, "delete Array.prototype.join.length; Array.prototype.join.length", 1, eval("delete Array.prototype.join.length; Array.prototype.join.length") );
michael@0 35
michael@0 36 // case where array length is 0
michael@0 37
michael@0 38 new TestCase( SECTION,
michael@0 39 "var TEST_ARRAY = new Array(); TEST_ARRAY.join()",
michael@0 40 "",
michael@0 41 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") );
michael@0 42
michael@0 43 // array length is 0, but spearator is specified
michael@0 44
michael@0 45 new TestCase( SECTION,
michael@0 46 "var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')",
michael@0 47 "",
michael@0 48 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") );
michael@0 49
michael@0 50 // length is greater than 0, separator is supplied
michael@0 51 new TestCase( SECTION,
michael@0 52 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')",
michael@0 53 "&&true&false&123&[object Object]&true",
michael@0 54 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") );
michael@0 55
michael@0 56 // length is greater than 0, separator is empty string
michael@0 57 new TestCase( SECTION,
michael@0 58 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')",
michael@0 59 "truefalse123[object Object]true",
michael@0 60 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") );
michael@0 61
michael@0 62 // length is greater than 0, separator is undefined
michael@0 63 new TestCase( SECTION,
michael@0 64 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)",
michael@0 65 ",,true,false,123,[object Object],true",
michael@0 66 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") );
michael@0 67
michael@0 68 // length is greater than 0, separator is not supplied
michael@0 69 new TestCase( SECTION,
michael@0 70 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()",
michael@0 71 ",,true,false,123,[object Object],true",
michael@0 72 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") );
michael@0 73
michael@0 74 // separator is a control character
michael@0 75 new TestCase( SECTION,
michael@0 76 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')",
michael@0 77 decodeURIComponent("%0B%0Btrue%0Bfalse%0B123%0B[object Object]%0Btrue"),
michael@0 78 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") );
michael@0 79
michael@0 80 // length of array is 1
michael@0 81 new TestCase( SECTION,
michael@0 82 "var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')",
michael@0 83 "true",
michael@0 84 eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
michael@0 85
michael@0 86
michael@0 87 SEPARATOR = "\t"
michael@0 88 TEST_LENGTH = 100;
michael@0 89 TEST_STRING = "";
michael@0 90 ARGUMENTS = "";
michael@0 91 TEST_RESULT = "";
michael@0 92
michael@0 93 for ( var index = 0; index < TEST_LENGTH; index++ ) {
michael@0 94 ARGUMENTS += index;
michael@0 95 ARGUMENTS += ( index == TEST_LENGTH -1 ) ? "" : ",";
michael@0 96
michael@0 97 TEST_RESULT += index;
michael@0 98 TEST_RESULT += ( index == TEST_LENGTH -1 ) ? "" : SEPARATOR;
michael@0 99 }
michael@0 100
michael@0 101 TEST_ARRAY = eval( "new Array( "+ARGUMENTS +")" );
michael@0 102
michael@0 103 new TestCase( SECTION,
michael@0 104 "TEST_ARRAY.join("+SEPARATOR+")",
michael@0 105 TEST_RESULT,
michael@0 106 TEST_ARRAY.join( SEPARATOR ) );
michael@0 107
michael@0 108 new TestCase( SECTION,
michael@0 109 "(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join()",
michael@0 110 "true,false,,,1e+21,1e-7",
michael@0 111 (new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join() );
michael@0 112
michael@0 113 // this is not an Array object
michael@0 114 new TestCase( SECTION,
michael@0 115 "var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')",
michael@0 116 "true:false:111:0.5:1230000:NaN::",
michael@0 117 eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") );
michael@0 118
michael@0 119 test();
michael@0 120
michael@0 121 function Object_1( value ) {
michael@0 122 this.array = value.split(",");
michael@0 123 this.length = this.array.length;
michael@0 124 for ( var i = 0; i < this.length; i++ ) {
michael@0 125 this[i] = eval(this.array[i]);
michael@0 126 }
michael@0 127 this.join = Array.prototype.join;
michael@0 128 this.getClass = Object.prototype.toString;
michael@0 129 }

mercurial