]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/Objects/toString-001.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: toString_1.js
24 ECMA Section: Object.toString()
27 This checks the ToString value of Object objects under JavaScript 1.2.
29 In JavaScript 1.2, Object.toString()
31 Author: christine@netscape.com
32 Date: 12 november 1997
35 var SECTION
= "JS1_2";
36 var VERSION
= "JS1_2";
38 var TITLE
= "Object.toString()";
40 writeHeaderToLog( SECTION
+ " "+ TITLE
);
42 var testcases
= new Array();
46 testcases
[testcases
.length
] = new TestCase( SECTION
,
47 "var o = new Object(); o.toString()",
53 testcases
[testcases
.length
] = new TestCase( SECTION
,
54 "o = {}; o.toString()",
58 o
= { name:"object", length:0, value:"hello" }
60 testcases
[testcases
.length
] = new TestCase( SECTION
,
61 "o = { name:\"object\", length:0, value:\"hello\" }; o.toString()",
63 checkObjectToString(o
.toString(), ['name:"object"', 'length:0',
66 o
= { name:"object", length:0, value:"hello",
67 toString:new Function( "return this.value+''" ) }
69 testcases
[testcases
.length
] = new TestCase( SECTION
,
70 "o = { name:\"object\", length:0, value:\"hello\", "+
71 "toString:new Function( \"return this.value+''\" ) }; o.toString()",
80 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
81 testcases
[tc
].passed
= writeTestCaseResult(
84 testcases
[tc
].description
+" = "+
85 testcases
[tc
].actual
);
87 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
96 * In JS1.2, Object.prototype.toString returns a representation of the
97 * object's properties as a string. However, the order of the properties
98 * in the resulting string is not specified. This function compares the
99 * resulting string with an array of strings to make sure that the
100 * resulting string is some permutation of the strings in the array.
102 function checkObjectToString(s
, a
) {
103 var m
= /^\{(.*)\}$/(s
);
105 return false; // should begin and end with curly brackets
106 var a2
= m
[1].split(", ");
107 if (a
.length
!= a2
.length
)
108 return false; // should be same length
111 for (var i
=0; i
< a
.length
; i
++) {
113 return false; // should have identical elements