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