Home | History | Annotate | Download | only in Number
      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/
      5  *
      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.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     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
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          15.7.1.js
     24     ECMA Section:       15.7.1 The Number Constructor Called as a Function
     25                         15.7.1.1
     26                         15.7.1.2
     27 
     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.
     33 
     34                         need to add more test cases.  see the testcases for
     35                         TypeConversion ToNumber.
     36 
     37     Author:             christine (at) netscape.com
     38     Date:               29 september 1997
     39 */
     40 
     41     var SECTION = "15.7.1";
     42     var VERSION = "ECMA_1";
     43     startTest();
     44     var TITLE   = "The Number Constructor Called as a Function";
     45 
     46     writeHeaderToLog( SECTION + " "+ TITLE);
     47 
     48     var testcases = getTestCases();
     49     test();
     50 
     51 
     52 function getTestCases() {
     53     var array = new Array();
     54     var item = 0;
     55 
     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") );
     69 
     70     array[item++] = new TestCase(SECTION, "Number(new MyObject(100))",  100,        Number(new MyObject(100)) );
     71 
     72     return ( array );
     73 }
     74 function test() {
     75     for ( tc=0; tc < testcases.length; tc++ ) {
     76         testcases[tc].passed = writeTestCaseResult(
     77                             testcases[tc].expect,
     78                             testcases[tc].actual,
     79                             testcases[tc].description +" = "+
     80                             testcases[tc].actual );
     81 
     82         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     83     }
     84     stopTest();
     85     return ( testcases );
     86 }
     87 function MyObject( value ) {
     88     this.value = value;
     89     this.valueOf = new Function( "return this.value" );
     90 }