]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/function/Number.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_2 / function / Number.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/
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 Filename: Number.js
24 Description: 'This tests the function Number(Object)'
25
26 Author: Nick Lerissa
27 Date: Fri Feb 13 09:58:28 PST 1998
28 */
29
30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION = 'no version';
32 startTest();
33 var TITLE = 'functions: Number';
34 var BUGNUMBER="123435";
35
36 writeHeaderToLog('Executing script: Number.js');
37 writeHeaderToLog( SECTION + " "+ TITLE);
38
39 var count = 0;
40 var testcases = new Array();
41
42
43 date = new Date(2200);
44
45 testcases[count++] = new TestCase( SECTION, "Number(new Date(2200)) ",
46 2200, (Number(date)));
47 testcases[count++] = new TestCase( SECTION, "Number(true) ",
48 1, (Number(true)));
49 testcases[count++] = new TestCase( SECTION, "Number(false) ",
50 0, (Number(false)));
51 testcases[count++] = new TestCase( SECTION, "Number('124') ",
52 124, (Number('124')));
53 testcases[count++] = new TestCase( SECTION, "Number('1.23') ",
54 1.23, (Number('1.23')));
55 testcases[count++] = new TestCase( SECTION, "Number({p:1}) ",
56 NaN, (Number({p:1})));
57 testcases[count++] = new TestCase( SECTION, "Number(null) ",
58 0, (Number(null)));
59 testcases[count++] = new TestCase( SECTION, "Number(-45) ",
60 -45, (Number(-45)));
61
62 // http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123435
63 // under js1.2, Number([1,2,3]) should return 3.
64
65 /*
66 http://bugs.webkit.org/show_bug.cgi?id=11545#c4
67 According to ECMA 9.3, when input type was Object, should call
68 ToPrimitive(input arg, hint Number) first, and than ToNumber() later. However,
69 ToPrimitive() will use [[DefaultValue]](hint) rule when input Type was Object
70 (ECMA 8.6.2.6). So the input [1,2,3] will applied [[DefaultValue]](hint) rule
71 with hint Number, and it looks like this:
72
73 toString(valuOf([1,2,3])) => toString(1,2,3) => '1,2,3'
74
75 Than ToNumber('1,2,3') results NaN based on ECMA 9.3.1: If the grammar cannot
76 interpret the string as an expansion of StringNumericLiteral, then the result
77 of ToNumber is NaN.
78 */
79
80 //testcases[count++] = new TestCase( SECTION, "Number([1,2,3]) ",
81 // 3, (Number([1,2,3])));
82
83 function test()
84 {
85 for ( tc=0; tc < testcases.length; tc++ ) {
86 testcases[tc].passed = writeTestCaseResult(
87 testcases[tc].expect,
88 testcases[tc].actual,
89 testcases[tc].description +" = "+
90 testcases[tc].actual );
91 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
92 }
93 stopTest();
94 return ( testcases );
95 }
96
97 test();
98