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
24 ECMA Section: 15.7.2 The Number Constructor
28 Description: 15.7.2 When Number is called as part of a new
29 expression, it is a constructor: it initializes
30 the newly created object.
32 15.7.2.1 The [[Prototype]] property of the newly
33 constructed object is set to othe original Number
34 prototype object, the one that is the initial value
35 of Number.prototype(0). The [[Class]] property is
36 set to "Number". The [[Value]] property of the
37 newly constructed object is set to ToNumber(value)
39 15.7.2.2 new Number(). same as in 15.7.2.1, except
40 the [[Value]] property is set to +0.
42 need to add more test cases. see the testcases for
43 TypeConversion ToNumber.
45 Author: christine@netscape.com
46 Date: 29 september 1997
49 var SECTION = "15.7.2";
50 var VERSION = "ECMA_1";
52 var TITLE = "The Number Constructor";
54 writeHeaderToLog( SECTION + " "+ TITLE);
56 var testcases = getTestCases();
59 function getTestCases() {
60 var array = new Array();
63 // To verify that the object's prototype is the Number.prototype, check to see if the object's
64 // constructor property is the same as Number.prototype.constructor.
66 array[item++] = new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
68 array[item++] = new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
69 array[item++] = new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
70 array[item++] = new TestCase(SECTION,
71 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
73 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
75 array[item++] = new TestCase(SECTION, "(new Number(0)).constructor", Number.prototype.constructor, (new Number(0)).constructor );
76 array[item++] = new TestCase(SECTION, "typeof (new Number(0))", "object", typeof (new Number(0)) );
77 array[item++] = new TestCase(SECTION, "(new Number(0)).valueOf()", 0, (new Number(0)).valueOf() );
78 array[item++] = new TestCase(SECTION,
79 "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
81 eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
83 array[item++] = new TestCase(SECTION, "(new Number(1)).constructor", Number.prototype.constructor, (new Number(1)).constructor );
84 array[item++] = new TestCase(SECTION, "typeof (new Number(1))", "object", typeof (new Number(1)) );
85 array[item++] = new TestCase(SECTION, "(new Number(1)).valueOf()", 1, (new Number(1)).valueOf() );
86 array[item++] = new TestCase(SECTION,
87 "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
89 eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
91 array[item++] = new TestCase(SECTION, "(new Number(-1)).constructor", Number.prototype.constructor, (new Number(-1)).constructor );
92 array[item++] = new TestCase(SECTION, "typeof (new Number(-1))", "object", typeof (new Number(-1)) );
93 array[item++] = new TestCase(SECTION, "(new Number(-1)).valueOf()", -1, (new Number(-1)).valueOf() );
94 array[item++] = new TestCase(SECTION,
95 "NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
97 eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
99 array[item++] = new TestCase(SECTION, "(new Number(Number.NaN)).constructor", Number.prototype.constructor, (new Number(Number.NaN)).constructor );
100 array[item++] = new TestCase(SECTION, "typeof (new Number(Number.NaN))", "object", typeof (new Number(Number.NaN)) );
101 array[item++] = new TestCase(SECTION, "(new Number(Number.NaN)).valueOf()", Number.NaN, (new Number(Number.NaN)).valueOf() );
102 array[item++] = new TestCase(SECTION,
103 "NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()",
105 eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
107 array[item++] = new TestCase(SECTION, "(new Number('string')).constructor", Number.prototype.constructor, (new Number('string')).constructor );
108 array[item++] = new TestCase(SECTION, "typeof (new Number('string'))", "object", typeof (new Number('string')) );
109 array[item++] = new TestCase(SECTION, "(new Number('string')).valueOf()", Number.NaN, (new Number('string')).valueOf() );
110 array[item++] = new TestCase(SECTION,
111 "NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()",
113 eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
115 array[item++] = new TestCase(SECTION, "(new Number(new String())).constructor", Number.prototype.constructor, (new Number(new String())).constructor );
116 array[item++] = new TestCase(SECTION, "typeof (new Number(new String()))", "object", typeof (new Number(new String())) );
117 array[item++] = new TestCase(SECTION, "(new Number(new String())).valueOf()", 0, (new Number(new String())).valueOf() );
118 array[item++] = new TestCase(SECTION,
119 "NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()",
121 eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
123 array[item++] = new TestCase(SECTION, "(new Number('')).constructor", Number.prototype.constructor, (new Number('')).constructor );
124 array[item++] = new TestCase(SECTION, "typeof (new Number(''))", "object", typeof (new Number('')) );
125 array[item++] = new TestCase(SECTION, "(new Number('')).valueOf()", 0, (new Number('')).valueOf() );
126 array[item++] = new TestCase(SECTION,
127 "NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()",
129 eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
131 array[item++] = new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.POSITIVE_INFINITY)).constructor );
132 array[item++] = new TestCase(SECTION, "typeof (new Number(Number.POSITIVE_INFINITY))", "object", typeof (new Number(Number.POSITIVE_INFINITY)) );
133 array[item++] = new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).valueOf()", Number.POSITIVE_INFINITY, (new Number(Number.POSITIVE_INFINITY)).valueOf() );
134 array[item++] = new TestCase(SECTION,
135 "NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
137 eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
139 array[item++] = new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.NEGATIVE_INFINITY)).constructor );
140 array[item++] = new TestCase(SECTION, "typeof (new Number(Number.NEGATIVE_INFINITY))", "object", typeof (new Number(Number.NEGATIVE_INFINITY)) );
141 array[item++] = new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).valueOf()", Number.NEGATIVE_INFINITY, (new Number(Number.NEGATIVE_INFINITY)).valueOf() );
142 array[item++] = new TestCase(SECTION,
143 "NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
145 eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
148 array[item++] = new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
149 array[item++] = new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
150 array[item++] = new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
151 array[item++] = new TestCase(SECTION,
152 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
154 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
162 for ( tc=0; tc < testcases.length; tc++ ) {
163 testcases[tc].passed = writeTestCaseResult(
164 testcases[tc].expect,
165 testcases[tc].actual,
166 testcases[tc].description +" = "+
167 testcases[tc].actual );
169 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
172 return ( testcases );