]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Number/15.7.1.js
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.1 The Number Constructor Called as a Function
28 Description: When Number is called as a function rather than as a
29 constructor, it performs a type conversion.
30 15.7.1.1 Return a number value (not a Number object)
31 computed by ToNumber( value )
32 15.7.1.2 Number() returns 0.
34 need to add more test cases. see the testcases for
35 TypeConversion ToNumber.
37 Author: christine@netscape.com
38 Date: 29 september 1997
41 var SECTION
= "15.7.1";
42 var VERSION
= "ECMA_1";
44 var TITLE
= "The Number Constructor Called as a Function";
46 writeHeaderToLog( SECTION
+ " "+ TITLE
);
48 var testcases
= getTestCases();
52 function getTestCases() {
53 var array
= new Array();
56 array
[item
++] = new TestCase(SECTION
, "Number()", 0, Number() );
57 array
[item
++] = new TestCase(SECTION
, "Number(void 0)", Number
.NaN
, Number(void 0) );
58 array
[item
++] = new TestCase(SECTION
, "Number(null)", 0, Number(null) );
59 array
[item
++] = new TestCase(SECTION
, "Number()", 0, Number() );
60 array
[item
++] = new TestCase(SECTION
, "Number(new Number())", 0, Number( new Number() ) );
61 array
[item
++] = new TestCase(SECTION
, "Number(0)", 0, Number(0) );
62 array
[item
++] = new TestCase(SECTION
, "Number(1)", 1, Number(1) );
63 array
[item
++] = new TestCase(SECTION
, "Number(-1)", -1, Number(-1) );
64 array
[item
++] = new TestCase(SECTION
, "Number(NaN)", Number
.NaN
, Number( Number
.NaN
) );
65 array
[item
++] = new TestCase(SECTION
, "Number('string')", Number
.NaN
, Number( "string") );
66 array
[item
++] = new TestCase(SECTION
, "Number(new String())", 0, Number( new String() ) );
67 array
[item
++] = new TestCase(SECTION
, "Number('')", 0, Number( "" ) );
68 array
[item
++] = new TestCase(SECTION
, "Number(Infinity)", Number
.POSITIVE_INFINITY
, Number("Infinity") );
70 array
[item
++] = new TestCase(SECTION
, "Number(new MyObject(100))", 100, Number(new MyObject(100)) );
75 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
76 testcases
[tc
].passed
= writeTestCaseResult(
79 testcases
[tc
].description
+" = "+
80 testcases
[tc
].actual
);
82 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
87 function MyObject( value
) {
89 this.valueOf
= new Function( "return this.value" );