js/src/tests/ecma/ObjectObjects/15.2.4.2.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 File Name: 15.2.4.2.js
michael@0 9 ECMA Section: 15.2.4.2 Object.prototype.toString()
michael@0 10
michael@0 11 Description: When the toString method is called, the following
michael@0 12 steps are taken:
michael@0 13 1. Get the [[Class]] property of this object
michael@0 14 2. Call ToString( Result(1) )
michael@0 15 3. Compute a string value by concatenating the three
michael@0 16 strings "[object " + Result(2) + "]"
michael@0 17 4. Return Result(3).
michael@0 18
michael@0 19 Author: christine@netscape.com
michael@0 20 Date: 28 october 1997
michael@0 21
michael@0 22 */
michael@0 23 var SECTION = "15.2.4.2";
michael@0 24 var VERSION = "ECMA_1";
michael@0 25 startTest();
michael@0 26 var TITLE = "Object.prototype.toString()";
michael@0 27
michael@0 28 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 29
michael@0 30 new TestCase( SECTION, "(new Object()).toString()", "[object Object]", (new Object()).toString() );
michael@0 31
michael@0 32 new TestCase( SECTION, "myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 33 GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''),
michael@0 34 eval("myvar = this; myvar.toString = Object.prototype.toString; myvar.toString()")
michael@0 35 );
michael@0 36
michael@0 37 new TestCase( SECTION, "myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 38 "[object Function]",
michael@0 39 eval("myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 40
michael@0 41 new TestCase( SECTION, "myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 42 '[object Object]',
michael@0 43 eval("myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 44
michael@0 45 new TestCase( SECTION, "myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 46 "[object Number]",
michael@0 47 eval("myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 48
michael@0 49 new TestCase( SECTION, "myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 50 "[object String]",
michael@0 51 eval("myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 52
michael@0 53 new TestCase( SECTION, "myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 54 "[object Math]",
michael@0 55 eval("myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 56
michael@0 57 new TestCase( SECTION, "myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 58 "[object Function]",
michael@0 59 eval("myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 60
michael@0 61 new TestCase( SECTION, "myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 62 "[object Array]",
michael@0 63 eval("myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 64
michael@0 65 new TestCase( SECTION, "myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 66 "[object Boolean]",
michael@0 67 eval("myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 68
michael@0 69 new TestCase( SECTION, "myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()",
michael@0 70 "[object Date]",
michael@0 71 eval("myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()") );
michael@0 72
michael@0 73 new TestCase( SECTION, "var MYVAR = new Object( this ); MYVAR.toString()",
michael@0 74 GLOBAL.replace(/ @ 0x[0-9a-fA-F]+ \(native @ 0x[0-9a-fA-F]+\)/, ''),
michael@0 75 eval("var MYVAR = new Object( this ); MYVAR.toString()")
michael@0 76 );
michael@0 77
michael@0 78 new TestCase( SECTION, "var MYVAR = new Object(); MYVAR.toString()",
michael@0 79 "[object Object]",
michael@0 80 eval("var MYVAR = new Object(); MYVAR.toString()") );
michael@0 81
michael@0 82 new TestCase( SECTION, "var MYVAR = new Object(void 0); MYVAR.toString()",
michael@0 83 "[object Object]",
michael@0 84 eval("var MYVAR = new Object(void 0); MYVAR.toString()") );
michael@0 85
michael@0 86 new TestCase( SECTION, "var MYVAR = new Object(null); MYVAR.toString()",
michael@0 87 "[object Object]",
michael@0 88 eval("var MYVAR = new Object(null); MYVAR.toString()") );
michael@0 89
michael@0 90
michael@0 91 function MyObject( value ) {
michael@0 92 this.value = new Function( "return this.value" );
michael@0 93 this.toString = new Function ( "return this.value+''");
michael@0 94 }
michael@0 95
michael@0 96 test();

mercurial