js/src/tests/ecma/Number/15.7.2.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f077a3b12722
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 /**
8 File Name: 15.7.2.js
9 ECMA Section: 15.7.2 The Number Constructor
10 15.7.2.1
11 15.7.2.2
12
13 Description: 15.7.2 When Number is called as part of a new
14 expression, it is a constructor: it initializes
15 the newly created object.
16
17 15.7.2.1 The [[Prototype]] property of the newly
18 constructed object is set to othe original Number
19 prototype object, the one that is the initial value
20 of Number.prototype(0). The [[Class]] property is
21 set to "Number". The [[Value]] property of the
22 newly constructed object is set to ToNumber(value)
23
24 15.7.2.2 new Number(). same as in 15.7.2.1, except
25 the [[Value]] property is set to +0.
26
27 need to add more test cases. see the testcases for
28 TypeConversion ToNumber.
29
30 Author: christine@netscape.com
31 Date: 29 september 1997
32 */
33
34 var SECTION = "15.7.2";
35 var VERSION = "ECMA_1";
36 startTest();
37 var TITLE = "The Number Constructor";
38
39 writeHeaderToLog( SECTION + " "+ TITLE);
40
41 // To verify that the object's prototype is the Number.prototype, check to see if the object's
42 // constructor property is the same as Number.prototype.constructor.
43
44 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
45
46 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
47 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
48 new TestCase(SECTION,
49 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
50 "[object Number]",
51 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
52
53 new TestCase(SECTION, "(new Number(0)).constructor", Number.prototype.constructor, (new Number(0)).constructor );
54 new TestCase(SECTION, "typeof (new Number(0))", "object", typeof (new Number(0)) );
55 new TestCase(SECTION, "(new Number(0)).valueOf()", 0, (new Number(0)).valueOf() );
56 new TestCase(SECTION,
57 "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
58 "[object Number]",
59 eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
60
61 new TestCase(SECTION, "(new Number(1)).constructor", Number.prototype.constructor, (new Number(1)).constructor );
62 new TestCase(SECTION, "typeof (new Number(1))", "object", typeof (new Number(1)) );
63 new TestCase(SECTION, "(new Number(1)).valueOf()", 1, (new Number(1)).valueOf() );
64 new TestCase(SECTION,
65 "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
66 "[object Number]",
67 eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
68
69 new TestCase(SECTION, "(new Number(-1)).constructor", Number.prototype.constructor, (new Number(-1)).constructor );
70 new TestCase(SECTION, "typeof (new Number(-1))", "object", typeof (new Number(-1)) );
71 new TestCase(SECTION, "(new Number(-1)).valueOf()", -1, (new Number(-1)).valueOf() );
72 new TestCase(SECTION,
73 "NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
74 "[object Number]",
75 eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
76
77 new TestCase(SECTION, "(new Number(Number.NaN)).constructor", Number.prototype.constructor, (new Number(Number.NaN)).constructor );
78 new TestCase(SECTION, "typeof (new Number(Number.NaN))", "object", typeof (new Number(Number.NaN)) );
79 new TestCase(SECTION, "(new Number(Number.NaN)).valueOf()", Number.NaN, (new Number(Number.NaN)).valueOf() );
80 new TestCase(SECTION,
81 "NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()",
82 "[object Number]",
83 eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
84
85 new TestCase(SECTION, "(new Number('string')).constructor", Number.prototype.constructor, (new Number('string')).constructor );
86 new TestCase(SECTION, "typeof (new Number('string'))", "object", typeof (new Number('string')) );
87 new TestCase(SECTION, "(new Number('string')).valueOf()", Number.NaN, (new Number('string')).valueOf() );
88 new TestCase(SECTION,
89 "NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()",
90 "[object Number]",
91 eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
92
93 new TestCase(SECTION, "(new Number(new String())).constructor", Number.prototype.constructor, (new Number(new String())).constructor );
94 new TestCase(SECTION, "typeof (new Number(new String()))", "object", typeof (new Number(new String())) );
95 new TestCase(SECTION, "(new Number(new String())).valueOf()", 0, (new Number(new String())).valueOf() );
96 new TestCase(SECTION,
97 "NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()",
98 "[object Number]",
99 eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
100
101 new TestCase(SECTION, "(new Number('')).constructor", Number.prototype.constructor, (new Number('')).constructor );
102 new TestCase(SECTION, "typeof (new Number(''))", "object", typeof (new Number('')) );
103 new TestCase(SECTION, "(new Number('')).valueOf()", 0, (new Number('')).valueOf() );
104 new TestCase(SECTION,
105 "NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()",
106 "[object Number]",
107 eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
108
109 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.POSITIVE_INFINITY)).constructor );
110 new TestCase(SECTION, "typeof (new Number(Number.POSITIVE_INFINITY))", "object", typeof (new Number(Number.POSITIVE_INFINITY)) );
111 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).valueOf()", Number.POSITIVE_INFINITY, (new Number(Number.POSITIVE_INFINITY)).valueOf() );
112 new TestCase(SECTION,
113 "NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
114 "[object Number]",
115 eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
116
117 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.NEGATIVE_INFINITY)).constructor );
118 new TestCase(SECTION, "typeof (new Number(Number.NEGATIVE_INFINITY))", "object", typeof (new Number(Number.NEGATIVE_INFINITY)) );
119 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).valueOf()", Number.NEGATIVE_INFINITY, (new Number(Number.NEGATIVE_INFINITY)).valueOf() );
120 new TestCase(SECTION,
121 "NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
122 "[object Number]",
123 eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
124
125
126 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
127 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
128 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
129 new TestCase(SECTION,
130 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
131 "[object Number]",
132 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
133
134 test();

mercurial