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: 15.2.4.2.js michael@0: ECMA Section: 15.2.4.2 Object.prototype.toString() michael@0: michael@0: Description: When the toString method is called, the following michael@0: steps are taken: michael@0: 1. Get the [[Class]] property of this object michael@0: 2. Call ToString( Result(1) ) michael@0: 3. Compute a string value by concatenating the three michael@0: strings "[object " + Result(2) + "]" michael@0: 4. Return Result(3). michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 28 october 1997 michael@0: michael@0: */ michael@0: var SECTION = "15.2.4.2"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Object.prototype.toString()"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, "(new Object()).toString()", "[object Object]", (new Object()).toString() ); michael@0: michael@0: new TestCase( SECTION, "myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''), michael@0: eval("myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()") michael@0: ); michael@0: michael@0: new TestCase( SECTION, "myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Function]", michael@0: eval("myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: '[object Object]', michael@0: eval("myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Number]", michael@0: eval("myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object String]", michael@0: eval("myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Math]", michael@0: eval("myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Function]", michael@0: eval("myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Array]", michael@0: eval("myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Boolean]", michael@0: eval("myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()", michael@0: "[object Date]", michael@0: eval("myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()") ); michael@0: michael@0: new TestCase( SECTION, "var MYVAR = new Object( this ); MYVAR.toString()", michael@0: GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''), michael@0: eval("var MYVAR = new Object( this ); MYVAR.toString()") michael@0: ); michael@0: michael@0: new TestCase( SECTION, "var MYVAR = new Object(); MYVAR.toString()", michael@0: "[object Object]", michael@0: eval("var MYVAR = new Object(); MYVAR.toString()") ); michael@0: michael@0: new TestCase( SECTION, "var MYVAR = new Object(void 0); MYVAR.toString()", michael@0: "[object Object]", michael@0: eval("var MYVAR = new Object(void 0); MYVAR.toString()") ); michael@0: michael@0: new TestCase( SECTION, "var MYVAR = new Object(null); MYVAR.toString()", michael@0: "[object Object]", michael@0: eval("var MYVAR = new Object(null); MYVAR.toString()") ); michael@0: michael@0: michael@0: function MyObject( value ) { michael@0: this.value = new Function( "return this.value" ); michael@0: this.toString = new Function ( "return this.value+''"); michael@0: } michael@0: michael@0: test();