Debian Codegraph @

rhino/testsrc/tests/ecma/Number/15.7.2.js

raw symbols SCIP
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 gTestfile = '15.7.2.js';
7
8 /**
9 File Name: 15.7.2.js
10 ECMA Section: 15.7.2 The Number Constructor
11 15.7.2.1
12 15.7.2.2
13
14 Description: 15.7.2 When Number is called as part of a new
15 expression, it is a constructor: it initializes
16 the newly created object.
17
18 15.7.2.1 The [[Prototype]] property of the newly
19 constructed object is set to othe original Number
20 prototype object, the one that is the initial value
21 of Number.prototype(0). The [[Class]] property is
22 set to "Number". The [[Value]] property of the
23 newly constructed object is set to ToNumber(value)
24
25 15.7.2.2 new Number(). same as in 15.7.2.1, except
26 the [[Value]] property is set to +0.
27
28 need to add more test cases. see the gTestcases for
29 TypeConversion ToNumber.
30
31 Author: [email protected]
32 Date: 29 september 1997
33 */
34
35 var SECTION = "15.7.2";
36 var VERSION = "ECMA_1";
37 startTest();
38 var TITLE = "The Number Constructor";
39
40 writeHeaderToLog( SECTION + " "+ TITLE);
41
42 // To verify that the object's prototype is the Number.prototype, check to see if the object's
43 // constructor property is the same as Number.prototype.constructor.
44
45 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
46
47 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
48 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
49 new TestCase(SECTION,
50 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
51 "[object Number]",
52 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
53
54 new TestCase(SECTION, "(new Number(0)).constructor", Number.prototype.constructor, (new Number(0)).constructor );
55 new TestCase(SECTION, "typeof (new Number(0))", "object", typeof (new Number(0)) );
56 new TestCase(SECTION, "(new Number(0)).valueOf()", 0, (new Number(0)).valueOf() );
57 new TestCase(SECTION,
58 "NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()",
59 "[object Number]",
60 eval("NUMB = new Number(0);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
61
62 new TestCase(SECTION, "(new Number(1)).constructor", Number.prototype.constructor, (new Number(1)).constructor );
63 new TestCase(SECTION, "typeof (new Number(1))", "object", typeof (new Number(1)) );
64 new TestCase(SECTION, "(new Number(1)).valueOf()", 1, (new Number(1)).valueOf() );
65 new TestCase(SECTION,
66 "NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
67 "[object Number]",
68 eval("NUMB = new Number(1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
69
70 new TestCase(SECTION, "(new Number(-1)).constructor", Number.prototype.constructor, (new Number(-1)).constructor );
71 new TestCase(SECTION, "typeof (new Number(-1))", "object", typeof (new Number(-1)) );
72 new TestCase(SECTION, "(new Number(-1)).valueOf()", -1, (new Number(-1)).valueOf() );
73 new TestCase(SECTION,
74 "NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()",
75 "[object Number]",
76 eval("NUMB = new Number(-1);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
77
78 new TestCase(SECTION, "(new Number(Number.NaN)).constructor", Number.prototype.constructor, (new Number(Number.NaN)).constructor );
79 new TestCase(SECTION, "typeof (new Number(Number.NaN))", "object", typeof (new Number(Number.NaN)) );
80 new TestCase(SECTION, "(new Number(Number.NaN)).valueOf()", Number.NaN, (new Number(Number.NaN)).valueOf() );
81 new TestCase(SECTION,
82 "NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()",
83 "[object Number]",
84 eval("NUMB = new Number(Number.NaN);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
85
86 new TestCase(SECTION, "(new Number('string')).constructor", Number.prototype.constructor, (new Number('string')).constructor );
87 new TestCase(SECTION, "typeof (new Number('string'))", "object", typeof (new Number('string')) );
88 new TestCase(SECTION, "(new Number('string')).valueOf()", Number.NaN, (new Number('string')).valueOf() );
89 new TestCase(SECTION,
90 "NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()",
91 "[object Number]",
92 eval("NUMB = new Number('string');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
93
94 new TestCase(SECTION, "(new Number(new String())).constructor", Number.prototype.constructor, (new Number(new String())).constructor );
95 new TestCase(SECTION, "typeof (new Number(new String()))", "object", typeof (new Number(new String())) );
96 new TestCase(SECTION, "(new Number(new String())).valueOf()", 0, (new Number(new String())).valueOf() );
97 new TestCase(SECTION,
98 "NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()",
99 "[object Number]",
100 eval("NUMB = new Number(new String());NUMB.toString=Object.prototype.toString;NUMB.toString()") );
101
102 new TestCase(SECTION, "(new Number('')).constructor", Number.prototype.constructor, (new Number('')).constructor );
103 new TestCase(SECTION, "typeof (new Number(''))", "object", typeof (new Number('')) );
104 new TestCase(SECTION, "(new Number('')).valueOf()", 0, (new Number('')).valueOf() );
105 new TestCase(SECTION,
106 "NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()",
107 "[object Number]",
108 eval("NUMB = new Number('');NUMB.toString=Object.prototype.toString;NUMB.toString()") );
109
110 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.POSITIVE_INFINITY)).constructor );
111 new TestCase(SECTION, "typeof (new Number(Number.POSITIVE_INFINITY))", "object", typeof (new Number(Number.POSITIVE_INFINITY)) );
112 new TestCase(SECTION, "(new Number(Number.POSITIVE_INFINITY)).valueOf()", Number.POSITIVE_INFINITY, (new Number(Number.POSITIVE_INFINITY)).valueOf() );
113 new TestCase(SECTION,
114 "NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
115 "[object Number]",
116 eval("NUMB = new Number(Number.POSITIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
117
118 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).constructor", Number.prototype.constructor, (new Number(Number.NEGATIVE_INFINITY)).constructor );
119 new TestCase(SECTION, "typeof (new Number(Number.NEGATIVE_INFINITY))", "object", typeof (new Number(Number.NEGATIVE_INFINITY)) );
120 new TestCase(SECTION, "(new Number(Number.NEGATIVE_INFINITY)).valueOf()", Number.NEGATIVE_INFINITY, (new Number(Number.NEGATIVE_INFINITY)).valueOf() );
121 new TestCase(SECTION,
122 "NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()",
123 "[object Number]",
124 eval("NUMB = new Number(Number.NEGATIVE_INFINITY);NUMB.toString=Object.prototype.toString;NUMB.toString()") );
125
126
127 new TestCase(SECTION, "(new Number()).constructor", Number.prototype.constructor, (new Number()).constructor );
128 new TestCase(SECTION, "typeof (new Number())", "object", typeof (new Number()) );
129 new TestCase(SECTION, "(new Number()).valueOf()", 0, (new Number()).valueOf() );
130 new TestCase(SECTION,
131 "NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()",
132 "[object Number]",
133 eval("NUMB = new Number();NUMB.toString=Object.prototype.toString;NUMB.toString()") );
134
135 test();