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: 15.2.4.2.js
24 ECMA Section: 15.2.4.2 Object.prototype.toString()
26 Description: When the toString method is called, the following
28 1. Get the [[Class]] property of this object
29 2. Call ToString( Result(1) )
30 3. Compute a string value by concatenating the three
31 strings "[object " + Result(2) + "]"
34 Author: christine@netscape.com
38 var SECTION = "15.2.4.2";
39 var VERSION = "ECMA_1";
41 var TITLE = "Object.prototype.toString()";
43 writeHeaderToLog( SECTION + " "+ TITLE);
45 var testcases = getTestCases();
48 function getTestCases() {
49 var array = new Array();
52 array[item++] = new TestCase( SECTION, "(new Object()).toString()", "[object Object]", (new Object()).toString() );
54 array[item++] = new TestCase( SECTION, "myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()",
56 eval("myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()") );
58 array[item++] = new TestCase( SECTION, "myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()",
60 eval("myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()") );
62 array[item++] = new TestCase( SECTION, "myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()",
64 eval("myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()") );
66 array[item++] = new TestCase( SECTION, "myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()",
68 eval("myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()") );
70 array[item++] = new TestCase( SECTION, "myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()",
72 eval("myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()") );
74 array[item++] = new TestCase( SECTION, "myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()",
76 eval("myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()") );
78 array[item++] = new TestCase( SECTION, "myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()",
80 eval("myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()") );
82 array[item++] = new TestCase( SECTION, "myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()",
84 eval("myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()") );
86 array[item++] = new TestCase( SECTION, "myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()",
88 eval("myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()") );
90 array[item++] = new TestCase( SECTION, "myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()",
92 eval("myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()") );
94 array[item++] = new TestCase( SECTION, "var MYVAR = new Object( this ); MYVAR.toString()",
96 eval("var MYVAR = new Object( this ); MYVAR.toString()") );
98 array[item++] = new TestCase( SECTION, "var MYVAR = new Object(); MYVAR.toString()",
100 eval("var MYVAR = new Object(); MYVAR.toString()") );
102 array[item++] = new TestCase( SECTION, "var MYVAR = new Object(void 0); MYVAR.toString()",
104 eval("var MYVAR = new Object(void 0); MYVAR.toString()") );
106 array[item++] = new TestCase( SECTION, "var MYVAR = new Object(null); MYVAR.toString()",
108 eval("var MYVAR = new Object(null); MYVAR.toString()") );
112 function test( array ) {
113 for ( tc=0 ; tc < testcases.length; tc++ ) {
114 testcases[tc].passed = writeTestCaseResult(
115 testcases[tc].expect,
116 testcases[tc].actual,
117 testcases[tc].description +" = "+ testcases[tc].actual );
119 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
122 return ( testcases );
125 function MyObject( value ) {
126 this.value = new Function( "return this.value" );
127 this.toString = new Function ( "return this.value+''");