initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / ObjectObjects / 15.2.4.2.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/
5  *
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.
10  *
11  * The Original Code is Mozilla Communicator client code, released March
12  * 31, 1998.
13  *
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
17  * Rights Reserved.
18  *
19  * Contributor(s): 
20  * 
21  */
22 /**
23     File Name:          15.2.4.2.js
24     ECMA Section:       15.2.4.2 Object.prototype.toString()
25
26     Description:        When the toString method is called, the following
27                         steps are taken:
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) + "]"
32                         4.  Return Result(3).
33
34     Author:             christine@netscape.com
35     Date:               28 october 1997
36
37 */
38     var SECTION = "15.2.4.2";
39     var VERSION = "ECMA_1";
40     startTest();
41     var TITLE   = "Object.prototype.toString()";
42
43     writeHeaderToLog( SECTION + " "+ TITLE);
44
45     var testcases = getTestCases();
46     test();
47
48 function getTestCases() {
49     var array = new Array();
50     var item = 0;
51
52     array[item++] = new TestCase( SECTION,  "(new Object()).toString()",    "[object Object]",  (new Object()).toString() );
53
54     array[item++] = new TestCase( SECTION,  "myvar = this;  myvar.toString = Object.prototype.toString; myvar.toString()",
55                                             GLOBAL,
56                                             eval("myvar = this;  myvar.toString = Object.prototype.toString; myvar.toString()") );
57
58     array[item++] = new TestCase( SECTION,  "myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()",
59                                             "[object Function]",
60                                             eval("myvar = MyObject; myvar.toString = Object.prototype.toString; myvar.toString()") );
61
62     array[item++] = new TestCase( SECTION,  "myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()",
63                                             '[object Object]',
64                                             eval("myvar = new MyObject( true ); myvar.toString = Object.prototype.toString; myvar.toString()") );
65
66     array[item++] = new TestCase( SECTION,  "myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()",
67                                             "[object Number]",
68                                             eval("myvar = new Number(0); myvar.toString = Object.prototype.toString; myvar.toString()") );
69
70     array[item++] = new TestCase( SECTION,  "myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()",
71                                             "[object String]",
72                                             eval("myvar = new String(''); myvar.toString = Object.prototype.toString; myvar.toString()") );
73
74     array[item++] = new TestCase( SECTION,  "myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()",
75                                             "[object Math]",
76                                             eval("myvar = Math; myvar.toString = Object.prototype.toString; myvar.toString()") );
77
78     array[item++] = new TestCase( SECTION,  "myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()",
79                                             "[object Function]",
80                                             eval("myvar = new Function(); myvar.toString = Object.prototype.toString; myvar.toString()") );
81
82     array[item++] = new TestCase( SECTION,  "myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()",
83                                             "[object Array]",
84                                             eval("myvar = new Array(); myvar.toString = Object.prototype.toString; myvar.toString()") );
85
86     array[item++] = new TestCase( SECTION,  "myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()",
87                                             "[object Boolean]",
88                                             eval("myvar = new Boolean(); myvar.toString = Object.prototype.toString; myvar.toString()") );
89
90     array[item++] = new TestCase( SECTION,  "myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()",
91                                             "[object Date]",
92                                             eval("myvar = new Date(); myvar.toString = Object.prototype.toString; myvar.toString()") );
93
94     array[item++] = new TestCase( SECTION,  "var MYVAR = new Object( this ); MYVAR.toString()",
95                                             GLOBAL,
96                                             eval("var MYVAR = new Object( this ); MYVAR.toString()") );
97
98     array[item++] = new TestCase( SECTION,  "var MYVAR = new Object(); MYVAR.toString()",
99                                             "[object Object]",
100                                             eval("var MYVAR = new Object(); MYVAR.toString()") );
101
102     array[item++] = new TestCase( SECTION,  "var MYVAR = new Object(void 0); MYVAR.toString()",
103                                             "[object Object]",
104                                             eval("var MYVAR = new Object(void 0); MYVAR.toString()") );
105
106     array[item++] = new TestCase( SECTION,  "var MYVAR = new Object(null); MYVAR.toString()",
107                                             "[object Object]",
108                                             eval("var MYVAR = new Object(null); MYVAR.toString()") );
109
110     return ( array );
111 }
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 );
118
119         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
120     }
121     stopTest();
122     return ( testcases );
123 }
124
125 function MyObject( value ) {
126     this.value = new Function( "return this.value" );
127     this.toString = new Function ( "return this.value+''");
128 }