]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.2.1-1.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma / Expressions / 11.2.1-1.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 File Name: 11.2.1-1.js
24 ECMA Section: 11.2.1 Property Accessors
25 Description:
26
27 Properties are accessed by name, using either the dot notation:
28 MemberExpression . Identifier
29 CallExpression . Identifier
30
31 or the bracket notation: MemberExpression [ Expression ]
32 CallExpression [ Expression ]
33
34 The dot notation is explained by the following syntactic conversion:
35 MemberExpression . Identifier
36 is identical in its behavior to
37 MemberExpression [ <identifier-string> ]
38 and similarly
39 CallExpression . Identifier
40 is identical in its behavior to
41 CallExpression [ <identifier-string> ]
42 where <identifier-string> is a string literal containing the same sequence
43 of characters as the Identifier.
44
45 The production MemberExpression : MemberExpression [ Expression ] is
46 evaluated as follows:
47
48 1. Evaluate MemberExpression.
49 2. Call GetValue(Result(1)).
50 3. Evaluate Expression.
51 4. Call GetValue(Result(3)).
52 5. Call ToObject(Result(2)).
53 6. Call ToString(Result(4)).
54 7. Return a value of type Reference whose base object is Result(5) and
55 whose property name is Result(6).
56
57 The production CallExpression : CallExpression [ Expression ] is evaluated
58 in exactly the same manner, except that the contained CallExpression is
59 evaluated in step 1.
60
61 Author: christine@netscape.com
62 Date: 12 november 1997
63 */
64 var SECTION = "11.2.1-1";
65 var VERSION = "ECMA_1";
66 startTest();
67 var TITLE = "Property Accessors";
68 writeHeaderToLog( SECTION + " "+TITLE );
69
70 var testcases = new Array();
71
72 // go through all Native Function objects, methods, and properties and get their typeof.
73
74 var PROPERTY = new Array();
75 var p = 0;
76
77 // properties and functions of the global object
78
79 PROPERTY[p++] = new Property( "this", "NaN", "number" );
80 PROPERTY[p++] = new Property( "this", "Infinity", "number" );
81 PROPERTY[p++] = new Property( "this", "eval", "function" );
82 PROPERTY[p++] = new Property( "this", "parseInt", "function" );
83 PROPERTY[p++] = new Property( "this", "parseFloat", "function" );
84 PROPERTY[p++] = new Property( "this", "escape", "function" );
85 PROPERTY[p++] = new Property( "this", "unescape", "function" );
86 PROPERTY[p++] = new Property( "this", "isNaN", "function" );
87 PROPERTY[p++] = new Property( "this", "isFinite", "function" );
88 PROPERTY[p++] = new Property( "this", "Object", "function" );
89 PROPERTY[p++] = new Property( "this", "Number", "function" );
90 PROPERTY[p++] = new Property( "this", "Function", "function" );
91 PROPERTY[p++] = new Property( "this", "Array", "function" );
92 PROPERTY[p++] = new Property( "this", "String", "function" );
93 PROPERTY[p++] = new Property( "this", "Boolean", "function" );
94 PROPERTY[p++] = new Property( "this", "Date", "function" );
95 PROPERTY[p++] = new Property( "this", "Math", "object" );
96
97 // properties and methods of Object objects
98
99 PROPERTY[p++] = new Property( "Object", "prototype", "object" );
100 PROPERTY[p++] = new Property( "Object", "toString", "function" );
101 PROPERTY[p++] = new Property( "Object", "valueOf", "function" );
102 PROPERTY[p++] = new Property( "Object", "constructor", "function" );
103
104 // properties of the Function object
105
106 PROPERTY[p++] = new Property( "Function", "prototype", "function" );
107 PROPERTY[p++] = new Property( "Function.prototype", "toString", "function" );
108 PROPERTY[p++] = new Property( "Function.prototype", "length", "number" );
109 PROPERTY[p++] = new Property( "Function.prototype", "valueOf", "function" );
110
111 Function.prototype.myProperty = "hi";
112
113 PROPERTY[p++] = new Property( "Function.prototype", "myProperty", "string" );
114
115 // properties of the Array object
116 PROPERTY[p++] = new Property( "Array", "prototype", "object" );
117 PROPERTY[p++] = new Property( "Array", "length", "number" );
118 PROPERTY[p++] = new Property( "Array.prototype", "constructor", "function" );
119 PROPERTY[p++] = new Property( "Array.prototype", "toString", "function" );
120 PROPERTY[p++] = new Property( "Array.prototype", "join", "function" );
121 PROPERTY[p++] = new Property( "Array.prototype", "reverse", "function" );
122 PROPERTY[p++] = new Property( "Array.prototype", "sort", "function" );
123
124 // properties of the String object
125 PROPERTY[p++] = new Property( "String", "prototype", "object" );
126 PROPERTY[p++] = new Property( "String", "fromCharCode", "function" );
127 PROPERTY[p++] = new Property( "String.prototype", "toString", "function" );
128 PROPERTY[p++] = new Property( "String.prototype", "constructor", "function" );
129 PROPERTY[p++] = new Property( "String.prototype", "valueOf", "function" );
130 PROPERTY[p++] = new Property( "String.prototype", "charAt", "function" );
131 PROPERTY[p++] = new Property( "String.prototype", "charCodeAt", "function" );
132 PROPERTY[p++] = new Property( "String.prototype", "indexOf", "function" );
133 PROPERTY[p++] = new Property( "String.prototype", "lastIndexOf", "function" );
134 PROPERTY[p++] = new Property( "String.prototype", "split", "function" );
135 PROPERTY[p++] = new Property( "String.prototype", "substring", "function" );
136 PROPERTY[p++] = new Property( "String.prototype", "toLowerCase", "function" );
137 PROPERTY[p++] = new Property( "String.prototype", "toUpperCase", "function" );
138 PROPERTY[p++] = new Property( "String.prototype", "length", "number" );
139
140 // properties of the Boolean object
141 PROPERTY[p++] = new Property( "Boolean", "prototype", "object" );
142 PROPERTY[p++] = new Property( "Boolean", "constructor", "function" );
143 PROPERTY[p++] = new Property( "Boolean.prototype", "valueOf", "function" );
144 PROPERTY[p++] = new Property( "Boolean.prototype", "toString", "function" );
145
146 // properties of the Number object
147
148 PROPERTY[p++] = new Property( "Number", "MAX_VALUE", "number" );
149 PROPERTY[p++] = new Property( "Number", "MIN_VALUE", "number" );
150 PROPERTY[p++] = new Property( "Number", "NaN", "number" );
151 PROPERTY[p++] = new Property( "Number", "NEGATIVE_INFINITY", "number" );
152 PROPERTY[p++] = new Property( "Number", "POSITIVE_INFINITY", "number" );
153 PROPERTY[p++] = new Property( "Number.prototype", "toString", "function" );
154 PROPERTY[p++] = new Property( "Number.prototype", "constructor", "function" );
155 PROPERTY[p++] = new Property( "Number.prototype", "valueOf", "function" );
156
157 // properties of the Math Object.
158 PROPERTY[p++] = new Property( "Math", "E", "number" );
159 PROPERTY[p++] = new Property( "Math", "LN10", "number" );
160 PROPERTY[p++] = new Property( "Math", "LN2", "number" );
161 PROPERTY[p++] = new Property( "Math", "LOG2E", "number" );
162 PROPERTY[p++] = new Property( "Math", "LOG10E", "number" );
163 PROPERTY[p++] = new Property( "Math", "PI", "number" );
164 PROPERTY[p++] = new Property( "Math", "SQRT1_2", "number" );
165 PROPERTY[p++] = new Property( "Math", "SQRT2", "number" );
166 PROPERTY[p++] = new Property( "Math", "abs", "function" );
167 PROPERTY[p++] = new Property( "Math", "acos", "function" );
168 PROPERTY[p++] = new Property( "Math", "asin", "function" );
169 PROPERTY[p++] = new Property( "Math", "atan", "function" );
170 PROPERTY[p++] = new Property( "Math", "atan2", "function" );
171 PROPERTY[p++] = new Property( "Math", "ceil", "function" );
172 PROPERTY[p++] = new Property( "Math", "cos", "function" );
173 PROPERTY[p++] = new Property( "Math", "exp", "function" );
174 PROPERTY[p++] = new Property( "Math", "floor", "function" );
175 PROPERTY[p++] = new Property( "Math", "log", "function" );
176 PROPERTY[p++] = new Property( "Math", "max", "function" );
177 PROPERTY[p++] = new Property( "Math", "min", "function" );
178 PROPERTY[p++] = new Property( "Math", "pow", "function" );
179 PROPERTY[p++] = new Property( "Math", "random", "function" );
180 PROPERTY[p++] = new Property( "Math", "round", "function" );
181 PROPERTY[p++] = new Property( "Math", "sin", "function" );
182 PROPERTY[p++] = new Property( "Math", "sqrt", "function" );
183 PROPERTY[p++] = new Property( "Math", "tan", "function" );
184
185 // properties of the Date object
186 PROPERTY[p++] = new Property( "Date", "parse", "function" );
187 PROPERTY[p++] = new Property( "Date", "prototype", "object" );
188 PROPERTY[p++] = new Property( "Date", "UTC", "function" );
189 PROPERTY[p++] = new Property( "Date.prototype", "constructor", "function" );
190 PROPERTY[p++] = new Property( "Date.prototype", "toString", "function" );
191 PROPERTY[p++] = new Property( "Date.prototype", "valueOf", "function" );
192 PROPERTY[p++] = new Property( "Date.prototype", "getTime", "function" );
193 PROPERTY[p++] = new Property( "Date.prototype", "getYear", "function" );
194 PROPERTY[p++] = new Property( "Date.prototype", "getFullYear", "function" );
195 PROPERTY[p++] = new Property( "Date.prototype", "getUTCFullYear", "function" );
196 PROPERTY[p++] = new Property( "Date.prototype", "getMonth", "function" );
197 PROPERTY[p++] = new Property( "Date.prototype", "getUTCMonth", "function" );
198 PROPERTY[p++] = new Property( "Date.prototype", "getDate", "function" );
199 PROPERTY[p++] = new Property( "Date.prototype", "getUTCDate", "function" );
200 PROPERTY[p++] = new Property( "Date.prototype", "getDay", "function" );
201 PROPERTY[p++] = new Property( "Date.prototype", "getUTCDay", "function" );
202 PROPERTY[p++] = new Property( "Date.prototype", "getHours", "function" );
203 PROPERTY[p++] = new Property( "Date.prototype", "getUTCHours", "function" );
204 PROPERTY[p++] = new Property( "Date.prototype", "getMinutes", "function" );
205 PROPERTY[p++] = new Property( "Date.prototype", "getUTCMinutes", "function" );
206 PROPERTY[p++] = new Property( "Date.prototype", "getSeconds", "function" );
207 PROPERTY[p++] = new Property( "Date.prototype", "getUTCSeconds", "function" );
208 PROPERTY[p++] = new Property( "Date.prototype", "getMilliseconds","function" );
209 PROPERTY[p++] = new Property( "Date.prototype", "getUTCMilliseconds", "function" );
210 PROPERTY[p++] = new Property( "Date.prototype", "setTime", "function" );
211 PROPERTY[p++] = new Property( "Date.prototype", "setMilliseconds","function" );
212 PROPERTY[p++] = new Property( "Date.prototype", "setUTCMilliseconds", "function" );
213 PROPERTY[p++] = new Property( "Date.prototype", "setSeconds", "function" );
214 PROPERTY[p++] = new Property( "Date.prototype", "setUTCSeconds", "function" );
215 PROPERTY[p++] = new Property( "Date.prototype", "setMinutes", "function" );
216 PROPERTY[p++] = new Property( "Date.prototype", "setUTCMinutes", "function" );
217 PROPERTY[p++] = new Property( "Date.prototype", "setHours", "function" );
218 PROPERTY[p++] = new Property( "Date.prototype", "setUTCHours", "function" );
219 PROPERTY[p++] = new Property( "Date.prototype", "setDate", "function" );
220 PROPERTY[p++] = new Property( "Date.prototype", "setUTCDate", "function" );
221 PROPERTY[p++] = new Property( "Date.prototype", "setMonth", "function" );
222 PROPERTY[p++] = new Property( "Date.prototype", "setUTCMonth", "function" );
223 PROPERTY[p++] = new Property( "Date.prototype", "setFullYear", "function" );
224 PROPERTY[p++] = new Property( "Date.prototype", "setUTCFullYear", "function" );
225 PROPERTY[p++] = new Property( "Date.prototype", "setYear", "function" );
226 PROPERTY[p++] = new Property( "Date.prototype", "toLocaleString", "function" );
227 PROPERTY[p++] = new Property( "Date.prototype", "toUTCString", "function" );
228 PROPERTY[p++] = new Property( "Date.prototype", "toGMTString", "function" );
229
230 for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
231 RESULT = eval("typeof " + PROPERTY[i].object + "." + PROPERTY[i].name );
232
233 testcases[tc++] = new TestCase( SECTION,
234 "typeof " + PROPERTY[i].object + "." + PROPERTY[i].name,
235 PROPERTY[i].type,
236 RESULT );
237
238 RESULT = eval("typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']");
239
240 testcases[tc++] = new TestCase( SECTION,
241 "typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']",
242 PROPERTY[i].type,
243 RESULT );
244 }
245
246 test();
247
248 function test() {
249 for ( tc=0; tc < testcases.length; tc++ ) {
250 testcases[tc].passed = writeTestCaseResult(
251 testcases[tc].expect,
252 testcases[tc].actual,
253 testcases[tc].description +" = "+
254 testcases[tc].actual );
255
256 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
257 }
258 stopTest();
259 return ( testcases );
260 }
261 function MyObject( arg0, arg1, arg2, arg3, arg4 ) {
262 this.name = arg0;
263 }
264 function Property( object, name, type ) {
265 this.object = object;
266 this.name = name;
267 this.type = type;
268 }