1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 File Name: 15.4.4.3-1.js
42 ECMA Section: 15.4.4.3-1 Array.prototype.join()
43 Description: The elements of this object are converted to strings and
44 these strings are then concatenated, separated by comma
45 characters. The result is the same as if the built-in join
46 method were invoiked for this object with no argument.
47 Author: christine@netscape.com, pschwartau@netscape.com
49 Modified: 14 July 2002
50 Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155285
51 ECMA-262 Ed.3 Section 15.4.4.5 Array.prototype.join()
52 Step 3: If |separator| is |undefined|, let |separator|
53 be the single-character string ","
57 var SECTION = "15.4.4.3-1";
58 var VERSION = "ECMA_1";
61 writeHeaderToLog( SECTION + " Array.prototype.join()");
63 var ARR_PROTOTYPE = Array.prototype;
65 new TestCase( SECTION, "Array.prototype.join.length", 1, Array.prototype.join.length );
66 new TestCase( SECTION, "delete Array.prototype.join.length", false, delete Array.prototype.join.length );
67 new TestCase( SECTION, "delete Array.prototype.join.length; Array.prototype.join.length", 1, eval("delete Array.prototype.join.length; Array.prototype.join.length") );
69 // case where array length is 0
71 new TestCase( SECTION,
72 "var TEST_ARRAY = new Array(); TEST_ARRAY.join()",
74 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") );
76 // array length is 0, but spearator is specified
78 new TestCase( SECTION,
79 "var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')",
81 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") );
83 // length is greater than 0, separator is supplied
84 new TestCase( SECTION,
85 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')",
86 "&&true&false&123&[object Object]&true",
87 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") );
89 // length is greater than 0, separator is empty string
90 new TestCase( SECTION,
91 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')",
92 "truefalse123[object Object]true",
93 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") );
95 // length is greater than 0, separator is undefined
96 new TestCase( SECTION,
97 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)",
98 ",,true,false,123,[object Object],true",
99 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") );
101 // length is greater than 0, separator is not supplied
102 new TestCase( SECTION,
103 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()",
104 ",,true,false,123,[object Object],true",
105 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") );
107 // separator is a control character
108 new TestCase( SECTION,
109 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')",
110 decodeURIComponent("%0B%0Btrue%0Bfalse%0B123%0B[object Object]%0Btrue"),
111 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") );
113 // length of array is 1
114 new TestCase( SECTION,
115 "var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')",
117 eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
126 for ( var index = 0; index < TEST_LENGTH; index++ ) {
128 ARGUMENTS += ( index == TEST_LENGTH -1 ) ? "" : ",";
130 TEST_RESULT += index;
131 TEST_RESULT += ( index == TEST_LENGTH -1 ) ? "" : SEPARATOR;
134 TEST_ARRAY = eval( "new Array( "+ARGUMENTS +")" );
136 new TestCase( SECTION,
137 "TEST_ARRAY.join("+SEPARATOR+")",
139 TEST_ARRAY.join( SEPARATOR ) );
141 new TestCase( SECTION,
142 "(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join()",
143 "true,false,,,1e+21,1e-7",
144 (new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join() );
146 // this is not an Array object
147 new TestCase( SECTION,
148 "var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')",
149 "true:false:111:0.5:1230000:NaN::",
150 eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") );
154 function Object_1( value ) {
155 this.array = value.split(",");
156 this.length = this.array.length;
157 for ( var i = 0; i < this.length; i++ ) {
158 this[i] = eval(this.array[i]);
160 this.join = Array.prototype.join;
161 this.getClass = Object.prototype.toString;