Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Number / 15.7.2.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
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.
22  *
23  * Contributor(s):
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          15.7.2.js
42    ECMA Section:       15.7.2 The Number Constructor
43    15.7.2.1
44    15.7.2.2
45
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.
49
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)
56
57    15.7.2.2 new Number().  same as in 15.7.2.1, except
58    the [[Value]] property is set to +0.
59
60    need to add more test cases.  see the testcases for
61    TypeConversion ToNumber.
62
63    Author:             christine@netscape.com
64    Date:               29 september 1997
65 */
66
67 var SECTION = "15.7.2";
68 var VERSION = "ECMA_1";
69 startTest();
70 var TITLE   = "The Number Constructor";
71
72 writeHeaderToLog( SECTION + " "+ TITLE);
73
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.
76
77 new TestCase(SECTION, "(new Number()).constructor",      Number.prototype.constructor,   (new Number()).constructor );
78
79 new TestCase(SECTION, "typeof (new Number())",         "object",           typeof (new Number()) );
80 new TestCase(SECTION,  "(new Number()).valueOf()",     0,                   (new Number()).valueOf() );
81 new TestCase(SECTION,
82              "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
83              "[object Number]",
84              eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
85
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() );
89 new TestCase(SECTION,
90              "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
91              "[object Number]",
92              eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
93
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() );
97 new TestCase(SECTION,
98              "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
99              "[object Number]",
100              eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
101
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()",
107              "[object Number]",
108              eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
109
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()",
115              "[object Number]",
116              eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
117
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()",
123              "[object Number]",
124              eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
125
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()",
131              "[object Number]",
132              eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
133
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()",
139              "[object Number]",
140              eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
141
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()",
147              "[object Number]",
148              eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
149
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()",
155              "[object Number]",
156              eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
157
158
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()",
164              "[object Number]",
165              eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
166
167 test();