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 ***** */
39
gTestfile = '15.4.4.3-1.js';
42
File Name: 15.4.4.3-1.js
43
ECMA Section: 15.4.4.3-1 Array.prototype.join()
44
Description: The elements of this object are converted to strings and
45
these strings are then concatenated, separated by comma
46
characters. The result is the same as if the built-in join
47
method were invoiked for this object with no argument.
48
Author: christine@netscape.com, pschwartau@netscape.com
50
Modified: 14 July 2002
51
Reason: See http://bugzilla.mozilla.org/show_bug.cgi?id=155285
52
ECMA-262 Ed.3 Section 15.4.4.5 Array.prototype.join()
53
Step 3: If |separator| is |undefined|, let |separator|
54
be the single-character string ","
58
var SECTION = "15.4.4.3-1";
59
var VERSION = "ECMA_1";
62
writeHeaderToLog( SECTION + " Array.prototype.join()");
64
var ARR_PROTOTYPE = Array.prototype;
66
new TestCase( SECTION, "Array.prototype.join.length", 1, Array.prototype.join.length );
67
new TestCase( SECTION, "delete Array.prototype.join.length", false, delete Array.prototype.join.length );
68
new TestCase( SECTION, "delete Array.prototype.join.length; Array.prototype.join.length", 1, eval("delete Array.prototype.join.length; Array.prototype.join.length") );
70
// case where array length is 0
72
new TestCase( SECTION,
73
"var TEST_ARRAY = new Array(); TEST_ARRAY.join()",
75
eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") );
77
// array length is 0, but spearator is specified
79
new TestCase( SECTION,
80
"var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')",
82
eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") );
84
// length is greater than 0, separator is supplied
85
new TestCase( SECTION,
86
"var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')",
87
"&&true&false&123&[object Object]&true",
88
eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") );
90
// length is greater than 0, separator is empty string
91
new TestCase( SECTION,
92
"var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')",
93
"truefalse123[object Object]true",
94
eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") );
96
// length is greater than 0, separator is undefined
97
new TestCase( SECTION,
98
"var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)",
99
",,true,false,123,[object Object],true",
100
eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") );
102
// length is greater than 0, separator is not supplied
103
new TestCase( SECTION,
104
"var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()",
105
",,true,false,123,[object Object],true",
106
eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") );
108
// separator is a control character
109
new TestCase( SECTION,
110
"var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')",
111
decodeURIComponent("%0B%0Btrue%0Bfalse%0B123%0B[object Object]%0Btrue"),
112
eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") );
114
// length of array is 1
115
new TestCase( SECTION,
116
"var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')",
118
eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
127
for ( var index = 0; index < TEST_LENGTH; index++ ) {
129
ARGUMENTS += ( index == TEST_LENGTH -1 ) ? "" : ",";
131
TEST_RESULT += index;
132
TEST_RESULT += ( index == TEST_LENGTH -1 ) ? "" : SEPARATOR;
135
TEST_ARRAY = eval( "new Array( "+ARGUMENTS +")" );
137
new TestCase( SECTION,
138
"TEST_ARRAY.join("+SEPARATOR+")",
140
TEST_ARRAY.join( SEPARATOR ) );
142
new TestCase( SECTION,
143
"(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join()",
144
"true,false,,,1e+21,1e-7",
145
(new Array( Boolean(true), Boolean(false), null, void 0, Number(1e+21), Number(1e-7))).join() );
147
// this is not an Array object
148
new TestCase( SECTION,
149
"var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')",
150
"true:false:111:0.5:1230000:NaN::",
151
eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") );
155
function Object_1( value ) {
156
this.array = value.split(",");
157
this.length = this.array.length;
158
for ( var i = 0; i < this.length; i++ ) {
159
this[i] = eval(this.array[i]);
161
this.join = Array.prototype.join;
162
this.getClass = Object.prototype.toString;