• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.3.js
24    ECMA Section:       15.2.4.3 Object.prototype.valueOf()
25
26    Description:        As a rule, the valueOf method for an object simply
27                        returns the object; but if the object is a "wrapper"
28                        for a host object, as may perhaps be created by the
29                        Object constructor, then the contained host object
30                        should be returned.
31
32                        This only covers native objects.
33
34    Author:             christine@netscape.com
35    Date:               28 october 1997
36
37*/
38    var SECTION = "15.2.4.3";
39    var VERSION = "ECMA_1";
40    startTest();
41    var TITLE   = "Object.prototype.valueOf()";
42
43    writeHeaderToLog( SECTION + " "+ TITLE);
44
45    var testcases = getTestCases();
46    test();
47
48function getTestCases() {
49    var array = new Array();
50    var item = 0;
51
52    var myarray = new Array();
53    myarray.valueOf = Object.prototype.valueOf;
54    var myboolean = new Boolean();
55    myboolean.valueOf = Object.prototype.valueOf;
56    var myfunction = new Function();
57    myfunction.valueOf = Object.prototype.valueOf;
58    var myobject = new Object();
59    myobject.valueOf = Object.prototype.valueOf;
60    var mymath = Math;
61    mymath.valueOf = Object.prototype.valueOf;
62    var mydate = new Date();
63    mydate.valueOf = Object.prototype.valueOf;
64    var mynumber = new Number();
65    mynumber.valueOf = Object.prototype.valueOf;
66    var mystring = new String();
67    mystring.valueOf = Object.prototype.valueOf;
68
69    array[item++] = new TestCase( SECTION,  "Object.prototype.valueOf.length",      0,      Object.prototype.valueOf.length );
70
71    array[item++] = new TestCase( SECTION,
72                                 "myarray = new Array(); myarray.valueOf = Object.prototype.valueOf; myarray.valueOf()",
73                                 myarray,
74                                 myarray.valueOf() );
75    array[item++] = new TestCase( SECTION,
76                                 "myboolean = new Boolean(); myboolean.valueOf = Object.prototype.valueOf; myboolean.valueOf()",
77                                 myboolean,
78                                 myboolean.valueOf() );
79    array[item++] = new TestCase( SECTION,
80                                 "myfunction = new Function(); myfunction.valueOf = Object.prototype.valueOf; myfunction.valueOf()",
81                                 myfunction,
82                                 myfunction.valueOf() );
83    array[item++] = new TestCase( SECTION,
84                                 "myobject = new Object(); myobject.valueOf = Object.prototype.valueOf; myobject.valueOf()",
85                                 myobject,
86                                 myobject.valueOf() );
87    array[item++] = new TestCase( SECTION,
88                                 "mymath = Math; mymath.valueOf = Object.prototype.valueOf; mymath.valueOf()",
89                                 mymath,
90                                 mymath.valueOf() );
91    array[item++] = new TestCase( SECTION,
92                                 "mynumber = new Number(); mynumber.valueOf = Object.prototype.valueOf; mynumber.valueOf()",
93                                 mynumber,
94                                 mynumber.valueOf() );
95    array[item++] = new TestCase( SECTION,
96                                 "mystring = new String(); mystring.valueOf = Object.prototype.valueOf; mystring.valueOf()",
97                                 mystring,
98                                 mystring.valueOf() );
99    array[item++] = new TestCase( SECTION,
100                                 "mydate = new Date(); mydate.valueOf = Object.prototype.valueOf; mydate.valueOf()",
101                                 mydate,
102                                 mydate.valueOf() );
103    return ( array );
104}
105function test() {
106    for ( tc=0; tc < testcases.length; tc++ ) {
107        testcases[tc].passed = writeTestCaseResult(
108                            testcases[tc].expect,
109                            testcases[tc].actual,
110                            testcases[tc].description +" = "+ testcases[tc].actual );
111        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
112    }
113    stopTest();
114    return ( testcases );
115}
116