]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Expressions/shell.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS IS"
8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 07 February 2001
22 * Functionality common to Array testing -
24 //-------------------------------------------------------------------------------------------------
25 var CHAR_LBRACKET
= '[';
26 var CHAR_RBRACKET
= ']';
27 var CHAR_QT_DBL
= '"';
32 var TYPE_STRING
= typeof 'abc';
36 * If available, arr.toSource() gives more detail than arr.toString()
38 * var arr = Array(1,2,'3');
46 * But toSource() doesn't exist in Rhino, so use our own imitation, below -
49 function formatArray(arr
)
53 return arr
.toSource();
64 * Imitate SpiderMonkey's arr.toSource() method:
66 * a) Double-quote each array element that is of string type
67 * b) Represent |undefined| and |null| by empty strings
68 * c) Delimit elements by a comma + single space
69 * d) Do not add delimiter at the end UNLESS the last element is |undefined|
70 * e) Add square brackets to the beginning and end of the string
72 function toSource(arr
)
74 var delim
= CHAR_COMMA
+ CHAR_SPACE
;
85 case (typeof elt
=== TYPE_STRING
) :
86 ret
+= doubleQuote(elt
);
89 case (elt
=== undefined || elt
=== null) :
90 break; // add nothing but the delimiter, below -
93 ret
+= elt
.toString();
96 if ((i
< len
-1) || (elt
=== undefined))
100 return CHAR_LBRACKET
+ ret
+ CHAR_RBRACKET
;
104 function doubleQuote(text
)
106 return CHAR_QT_DBL
+ text
+ CHAR_QT_DBL
;
110 function singleQuote(text
)
112 return CHAR_QT
+ text
+ CHAR_QT
;