]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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 Description: 'This tests the function Number(Object)'
27 Date: Fri Feb 13 09:58:28 PST 1998
30 var SECTION
= 'As described in Netscape doc "Whats new in JavaScript 1.2"';
31 var VERSION
= 'no version';
33 var TITLE
= 'functions: Number';
34 var BUGNUMBER
="123435";
36 writeHeaderToLog('Executing script: Number.js');
37 writeHeaderToLog( SECTION
+ " "+ TITLE
);
40 var testcases
= new Array();
43 date
= new Date(2200);
45 testcases
[count
++] = new TestCase( SECTION
, "Number(new Date(2200)) ",
46 2200, (Number(date
)));
47 testcases
[count
++] = new TestCase( SECTION
, "Number(true) ",
49 testcases
[count
++] = new TestCase( SECTION
, "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) ",
59 testcases
[count
++] = new TestCase( SECTION
, "Number(-45) ",
62 // http://scopus.mcom.com/bugsplat/show_bug.cgi?id=123435
63 // under js1.2, Number([1,2,3]) should return 3.
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:
73 toString(valuOf([1,2,3])) => toString(1,2,3) => '1,2,3'
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
80 //testcases[count++] = new TestCase( SECTION, "Number([1,2,3]) ",
81 // 3, (Number([1,2,3])));
85 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
86 testcases
[tc
].passed
= writeTestCaseResult(
89 testcases
[tc
].description
+" = "+
90 testcases
[tc
].actual
);
91 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";