]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/function/String.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 String(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: String';
35 writeHeaderToLog('Executing script: String.js');
36 writeHeaderToLog( SECTION
+ " "+ TITLE
);
39 var testcases
= new Array();
42 testcases
[count
++] = new TestCase( SECTION
, "String(true) ",
43 'true', (String(true)));
44 testcases
[count
++] = new TestCase( SECTION
, "String(false) ",
45 'false', (String(false)));
46 testcases
[count
++] = new TestCase( SECTION
, "String(-124) ",
47 '-124', (String(-124)));
48 testcases
[count
++] = new TestCase( SECTION
, "String(1.23) ",
49 '1.23', (String(1.23)));
51 http://bugs.webkit.org/show_bug.cgi?id=11545#c5
52 According to ECMA 9.8, when input type of String object argument was Object, we
53 should applied ToPrimitive(input arg, hint String) first, and later ToString().
54 And just like previous one, ToPrimitive() will use [[DefaultValue]](hint)
55 with hint String to convert the input (toString() below uses the rule in ECMA 15.2.4.2):
57 valueOf(toString({p:1}) => valueOf('[object Object]') => '[object Object]'
59 And ToString() called after ToPrimitive(), so the correct result would be:
63 //testcases[count++] = new TestCase( SECTION, "String({p:1}) ",
64 // '{p:1}', (String({p:1})));
65 testcases
[count
++] = new TestCase( SECTION
, "String(null) ",
66 'null', (String(null)));
68 http://bugs.webkit.org/show_bug.cgi?id=11545#c5
69 According to ECMA 9.8, when input type of String object argument was Object, we
70 should applied ToPrimitive(input arg, hint String) first, and later ToString().
71 And just like previous one, ToPrimitive() will use [[DefaultValue]](hint)
72 with hint String to convert the input (toString() below uses the rule in ECMA 15.2.4.2):
74 valueOf(toString([1,2,3])) => valueOf('1,2,3') => '1,2,3'
76 And ToString() called after ToPrimitive(), so the correct result would be:
80 //testcases[count++] = new TestCase( SECTION, "String([1,2,3]) ",
81 // '[1, 2, 3]', (String([1,2,3])));
86 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
87 testcases
[tc
].passed
= writeTestCaseResult(
90 testcases
[tc
].description
+" = "+
91 testcases
[tc
].actual
);
92 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";