]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
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: String.js | |
24 | Description: 'This tests the function String(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: String'; | |
34 | ||
35 | writeHeaderToLog('Executing script: String.js'); | |
36 | writeHeaderToLog( SECTION + " "+ TITLE); | |
37 | ||
38 | var count = 0; | |
39 | var testcases = new Array(); | |
40 | ||
41 | ||
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))); | |
50 | /* | |
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): | |
56 | ||
57 | valueOf(toString({p:1}) => valueOf('[object Object]') => '[object Object]' | |
58 | ||
59 | And ToString() called after ToPrimitive(), so the correct result would be: | |
60 | ||
61 | [object Object] | |
62 | */ | |
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))); | |
67 | /* | |
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): | |
73 | ||
74 | valueOf(toString([1,2,3])) => valueOf('1,2,3') => '1,2,3' | |
75 | ||
76 | And ToString() called after ToPrimitive(), so the correct result would be: | |
77 | ||
78 | 1,2,3 | |
79 | */ | |
80 | //testcases[count++] = new TestCase( SECTION, "String([1,2,3]) ", | |
81 | // '[1, 2, 3]', (String([1,2,3]))); | |
82 | ||
83 | ||
84 | function test() | |
85 | { | |
86 | for ( tc=0; tc < testcases.length; tc++ ) { | |
87 | testcases[tc].passed = writeTestCaseResult( | |
88 | testcases[tc].expect, | |
89 | testcases[tc].actual, | |
90 | testcases[tc].description +" = "+ | |
91 | testcases[tc].actual ); | |
92 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
93 | } | |
94 | stopTest(); | |
95 | return ( testcases ); | |
96 | } | |
97 | ||
98 | test(); | |
99 |