1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 ECMA Section: 15.7.2 The Number Constructor
46 Description: 15.7.2 When Number is called as part of a new
47 expression, it is a constructor: it initializes
48 the newly created object.
50 15.7.2.1 The [[Prototype]] property of the newly
51 constructed object is set to othe original Number
52 prototype object, the one that is the initial value
53 of Number.prototype(0). The [[Class]] property is
54 set to "Number". The [[Value]] property of the
55 newly constructed object is set to ToNumber(value)
57 15.7.2.2 new Number(). same as in 15.7.2.1, except
58 the [[Value]] property is set to +0.
60 need to add more test cases. see the testcases for
61 TypeConversion ToNumber.
63 Author: christine@netscape.com
64 Date: 29 september 1997
67 var SECTION = "15.7.2";
68 var VERSION = "ECMA_1";
70 var TITLE = "The Number Constructor";
72 writeHeaderToLog( SECTION + " "+ TITLE);
74 // To verify that the object's prototype is the Number.prototype, check to see if the object's
75 // constructor property is the same as Number.prototype.constructor.
77 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
79 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
80 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
82 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
84 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
86 new TestCase(SECTION, "(new Number(0)).constructor", Number.prototype.constructor, (new Number(0)).constructor );
87 new TestCase(SECTION, "typeof (new Number(0))", "object", typeof (new Number(0)) );
88 new TestCase(SECTION, "(new Number(0)).valueOf()", 0, (new Number(0)).valueOf() );
90 "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
92 eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
94 new TestCase(SECTION, "(new Number(1)).constructor", Number.prototype.constructor, (new Number(1)).constructor );
95 new TestCase(SECTION, "typeof (new Number(1))", "object", typeof (new Number(1)) );
96 new TestCase(SECTION, "(new Number(1)).valueOf()", 1, (new Number(1)).valueOf() );
98 "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
100 eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
102 new TestCase(SECTION, "(new Number(-1)).constructor", Number.prototype.constructor, (new Number(-1)).constructor );
103 new TestCase(SECTION, "typeof (new Number(-1))", "object", typeof (new Number(-1)) );
104 new TestCase(SECTION, "(new Number(-1)).valueOf()", -1, (new Number(-1)).valueOf() );
105 new TestCase(SECTION,
106 "NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
108 eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
110 new TestCase(SECTION, "(new Number(Number.NaN)).constructor", Number.prototype.constructor, (new Number(Number.NaN)).constructor );
111 new TestCase(SECTION, "typeof (new Number(Number.NaN))", "object", typeof (new Number(Number.NaN)) );
112 new TestCase(SECTION, "(new Number(Number.NaN)).valueOf()", Number.NaN, (new Number(Number.NaN)).valueOf() );
113 new TestCase(SECTION,
114 "NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()",
116 eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
118 new TestCase(SECTION, "(new Number('string')).constructor", Number.prototype.constructor, (new Number('string')).constructor );
119 new TestCase(SECTION, "typeof (new Number('string'))", "object", typeof (new Number('string')) );
120 new TestCase(SECTION, "(new Number('string')).valueOf()", Number.NaN, (new Number('string')).valueOf() );
121 new TestCase(SECTION,
122 "NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()",
124 eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
126 new TestCase(SECTION, "(new Number(new String())).constructor", Number.prototype.constructor, (new Number(new String())).constructor );
127 new TestCase(SECTION, "typeof (new Number(new String()))", "object", typeof (new Number(new String())) );
128 new TestCase(SECTION, "(new Number(new String())).valueOf()", 0, (new Number(new String())).valueOf() );
129 new TestCase(SECTION,
130 "NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()",
132 eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
134 new TestCase(SECTION, "(new Number('')).constructor", Number.prototype.constructor, (new Number('')).constructor );
135 new TestCase(SECTION, "typeof (new Number(''))", "object", typeof (new Number('')) );
136 new TestCase(SECTION, "(new Number('')).valueOf()", 0, (new Number('')).valueOf() );
137 new TestCase(SECTION,
138 "NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()",
140 eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
142 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.POSITIVE_INFINITY)).constructor );
143 new TestCase(SECTION, "typeof (new Number(Number.POSITIVE_INFINITY))", "object", typeof (new Number(Number.POSITIVE_INFINITY)) );
144 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).valueOf()", Number.POSITIVE_INFINITY, (new Number(Number.POSITIVE_INFINITY)).valueOf() );
145 new TestCase(SECTION,
146 "NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
148 eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
150 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.NEGATIVE_INFINITY)).constructor );
151 new TestCase(SECTION, "typeof (new Number(Number.NEGATIVE_INFINITY))", "object", typeof (new Number(Number.NEGATIVE_INFINITY)) );
152 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).valueOf()", Number.NEGATIVE_INFINITY, (new Number(Number.NEGATIVE_INFINITY)).valueOf() );
153 new TestCase(SECTION,
154 "NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
156 eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
159 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
160 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
161 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
162 new TestCase(SECTION,
163 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
165 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );