michael@0: // |reftest| skip -- obsolete test michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: toString_1.js michael@0: ECMA Section: Object.toString() michael@0: Description: michael@0: michael@0: This checks the ToString value of Object objects under JavaScript 1.2. michael@0: michael@0: In JavaScript 1.2, Object.toString() michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "JS1_2"; michael@0: var VERSION = "JS1_2"; michael@0: startTest(); michael@0: var TITLE = "Object.toString()"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var o = new Object(); michael@0: michael@0: new TestCase( SECTION, michael@0: "var o = new Object(); o.toString()", michael@0: "{}", michael@0: o.toString() ); michael@0: michael@0: o = {}; michael@0: michael@0: new TestCase( SECTION, michael@0: "o = {}; o.toString()", michael@0: "{}", michael@0: o.toString() ); michael@0: michael@0: o = { name:"object", length:0, value:"hello" } michael@0: michael@0: new TestCase( SECTION, michael@0: "o = { name:\"object\", length:0, value:\"hello\" }; o.toString()", michael@0: true, michael@0: checkObjectToString(o.toString(), ['name:"object"', 'length:0', michael@0: 'value:"hello"'])); michael@0: michael@0: o = { name:"object", length:0, value:"hello", michael@0: toString:new Function( "return this.value+''" ) } michael@0: michael@0: new TestCase( SECTION, michael@0: "o = { name:\"object\", length:0, value:\"hello\", "+ michael@0: "toString:new Function( \"return this.value+''\" ) }; o.toString()", michael@0: "hello", michael@0: o.toString() ); michael@0: michael@0: michael@0: michael@0: test(); michael@0: michael@0: /** michael@0: * checkObjectToString michael@0: * michael@0: * In JS1.2, Object.prototype.toString returns a representation of the michael@0: * object's properties as a string. However, the order of the properties michael@0: * in the resulting string is not specified. This function compares the michael@0: * resulting string with an array of strings to make sure that the michael@0: * resulting string is some permutation of the strings in the array. michael@0: */ michael@0: function checkObjectToString(s, a) { michael@0: var m = /^\{(.*)\}$/(s); michael@0: if (!m) michael@0: return false; // should begin and end with curly brackets michael@0: var a2 = m[1].split(", "); michael@0: if (a.length != a2.length) michael@0: return false; // should be same length michael@0: a.sort(); michael@0: a2.sort(); michael@0: for (var i=0; i < a.length; i++) { michael@0: if (a[i] != a2[i]) michael@0: return false; // should have identical elements michael@0: } michael@0: return true; michael@0: } michael@0: