Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Expressions / 11.2.1-1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          11.2.1-1.js
42    ECMA Section:       11.2.1 Property Accessors
43    Description:
44
45    Properties are accessed by name, using either the dot notation:
46    MemberExpression . Identifier
47    CallExpression . Identifier
48
49    or the bracket notation:    MemberExpression [ Expression ]
50    CallExpression [ Expression ]
51
52    The dot notation is explained by the following syntactic conversion:
53    MemberExpression . Identifier
54    is identical in its behavior to
55    MemberExpression [ <identifier-string> ]
56    and similarly
57    CallExpression . Identifier
58    is identical in its behavior to
59    CallExpression [ <identifier-string> ]
60    where <identifier-string> is a string literal containing the same sequence
61    of characters as the Identifier.
62
63    The production MemberExpression : MemberExpression [ Expression ] is
64    evaluated as follows:
65
66    1.  Evaluate MemberExpression.
67    2.  Call GetValue(Result(1)).
68    3.  Evaluate Expression.
69    4.  Call GetValue(Result(3)).
70    5.  Call ToObject(Result(2)).
71    6.  Call ToString(Result(4)).
72    7.  Return a value of type Reference whose base object is Result(5) and
73    whose property name is Result(6).
74
75    The production CallExpression : CallExpression [ Expression ] is evaluated
76    in exactly the same manner, except that the contained CallExpression is
77    evaluated in step 1.
78
79    Author:             christine@netscape.com
80    Date:               12 november 1997
81 */
82 var SECTION = "11.2.1-1";
83 var VERSION = "ECMA_1";
84 startTest();
85 var TITLE   = "Property Accessors";
86 writeHeaderToLog( SECTION + " "+TITLE );
87
88 // go through all Native Function objects, methods, and properties and get their typeof.
89
90 var PROPERTY = new Array();
91 var p = 0;
92
93 // properties and functions of the global object
94
95 PROPERTY[p++] = new Property( "this",   "NaN",          "number" );
96 PROPERTY[p++] = new Property( "this",   "Infinity",     "number" );
97 PROPERTY[p++] = new Property( "this",   "eval",         "function" );
98 PROPERTY[p++] = new Property( "this",   "parseInt",     "function" );
99 PROPERTY[p++] = new Property( "this",   "parseFloat",   "function" );
100 PROPERTY[p++] = new Property( "this",   "escape",       "function" );
101 PROPERTY[p++] = new Property( "this",   "unescape",     "function" );
102 PROPERTY[p++] = new Property( "this",   "isNaN",        "function" );
103 PROPERTY[p++] = new Property( "this",   "isFinite",     "function" );
104 PROPERTY[p++] = new Property( "this",   "Object",       "function" );
105 PROPERTY[p++] = new Property( "this",   "Number",       "function" );
106 PROPERTY[p++] = new Property( "this",   "Function",     "function" );
107 PROPERTY[p++] = new Property( "this",   "Array",        "function" );
108 PROPERTY[p++] = new Property( "this",   "String",       "function" );
109 PROPERTY[p++] = new Property( "this",   "Boolean",      "function" );
110 PROPERTY[p++] = new Property( "this",   "Date",         "function" );
111 PROPERTY[p++] = new Property( "this",   "Math",         "object" );
112
113 // properties and  methods of Object objects
114
115 PROPERTY[p++] = new Property( "Object", "prototype",    "object" );
116 PROPERTY[p++] = new Property( "Object", "toString",     "function" );
117 PROPERTY[p++] = new Property( "Object", "valueOf",      "function" );
118 PROPERTY[p++] = new Property( "Object", "constructor",  "function" );
119
120 // properties of the Function object
121
122 PROPERTY[p++] = new Property( "Function",   "prototype",    "function" );
123 PROPERTY[p++] = new Property( "Function.prototype",   "toString",     "function" );
124 PROPERTY[p++] = new Property( "Function.prototype",   "length",       "number" );
125 PROPERTY[p++] = new Property( "Function.prototype",   "valueOf",      "function" );
126
127 Function.prototype.myProperty = "hi";
128
129 PROPERTY[p++] = new Property( "Function.prototype",   "myProperty",   "string" );
130
131 // properties of the Array object
132 PROPERTY[p++] = new Property( "Array",      "prototype",    "object" );
133 PROPERTY[p++] = new Property( "Array",      "length",       "number" );
134 PROPERTY[p++] = new Property( "Array.prototype",      "constructor",  "function" );
135 PROPERTY[p++] = new Property( "Array.prototype",      "toString",     "function" );
136 PROPERTY[p++] = new Property( "Array.prototype",      "join",         "function" );
137 PROPERTY[p++] = new Property( "Array.prototype",      "reverse",      "function" );
138 PROPERTY[p++] = new Property( "Array.prototype",      "sort",         "function" );
139
140 // properties of the String object
141 PROPERTY[p++] = new Property( "String",     "prototype",    "object" );
142 PROPERTY[p++] = new Property( "String",     "fromCharCode", "function" );
143 PROPERTY[p++] = new Property( "String.prototype",     "toString",     "function" );
144 PROPERTY[p++] = new Property( "String.prototype",     "constructor",  "function" );
145 PROPERTY[p++] = new Property( "String.prototype",     "valueOf",      "function" );
146 PROPERTY[p++] = new Property( "String.prototype",     "charAt",       "function" );
147 PROPERTY[p++] = new Property( "String.prototype",     "charCodeAt",   "function" );
148 PROPERTY[p++] = new Property( "String.prototype",     "indexOf",      "function" );
149 PROPERTY[p++] = new Property( "String.prototype",     "lastIndexOf",  "function" );
150 PROPERTY[p++] = new Property( "String.prototype",     "split",        "function" );
151 PROPERTY[p++] = new Property( "String.prototype",     "substring",    "function" );
152 PROPERTY[p++] = new Property( "String.prototype",     "toLowerCase",  "function" );
153 PROPERTY[p++] = new Property( "String.prototype",     "toUpperCase",  "function" );
154 PROPERTY[p++] = new Property( "String.prototype",     "length",       "number" );
155
156 // properties of the Boolean object
157 PROPERTY[p++] = new Property( "Boolean",    "prototype",    "object" );
158 PROPERTY[p++] = new Property( "Boolean",    "constructor",  "function" );
159 PROPERTY[p++] = new Property( "Boolean.prototype",    "valueOf",      "function" );
160 PROPERTY[p++] = new Property( "Boolean.prototype",    "toString",     "function" );
161
162 // properties of the Number object
163
164 PROPERTY[p++] = new Property( "Number",     "MAX_VALUE",    "number" );
165 PROPERTY[p++] = new Property( "Number",     "MIN_VALUE",    "number" );
166 PROPERTY[p++] = new Property( "Number",     "NaN",          "number" );
167 PROPERTY[p++] = new Property( "Number",     "NEGATIVE_INFINITY",    "number" );
168 PROPERTY[p++] = new Property( "Number",     "POSITIVE_INFINITY",    "number" );
169 PROPERTY[p++] = new Property( "Number.prototype",     "toString",     "function" );
170 PROPERTY[p++] = new Property( "Number.prototype",     "constructor",  "function" );
171 PROPERTY[p++] = new Property( "Number.prototype",     "valueOf",        "function" );
172
173 // properties of the Math Object.
174 PROPERTY[p++] = new Property( "Math",   "E",        "number" );
175 PROPERTY[p++] = new Property( "Math",   "LN10",     "number" );
176 PROPERTY[p++] = new Property( "Math",   "LN2",      "number" );
177 PROPERTY[p++] = new Property( "Math",   "LOG2E",    "number" );
178 PROPERTY[p++] = new Property( "Math",   "LOG10E",   "number" );
179 PROPERTY[p++] = new Property( "Math",   "PI",       "number" );
180 PROPERTY[p++] = new Property( "Math",   "SQRT1_2",  "number" );
181 PROPERTY[p++] = new Property( "Math",   "SQRT2",    "number" );
182 PROPERTY[p++] = new Property( "Math",   "abs",      "function" );
183 PROPERTY[p++] = new Property( "Math",   "acos",     "function" );
184 PROPERTY[p++] = new Property( "Math",   "asin",     "function" );
185 PROPERTY[p++] = new Property( "Math",   "atan",     "function" );
186 PROPERTY[p++] = new Property( "Math",   "atan2",    "function" );
187 PROPERTY[p++] = new Property( "Math",   "ceil",     "function" );
188 PROPERTY[p++] = new Property( "Math",   "cos",      "function" );
189 PROPERTY[p++] = new Property( "Math",   "exp",      "function" );
190 PROPERTY[p++] = new Property( "Math",   "floor",    "function" );
191 PROPERTY[p++] = new Property( "Math",   "log",      "function" );
192 PROPERTY[p++] = new Property( "Math",   "max",      "function" );
193 PROPERTY[p++] = new Property( "Math",   "min",      "function" );
194 PROPERTY[p++] = new Property( "Math",   "pow",      "function" );
195 PROPERTY[p++] = new Property( "Math",   "random",   "function" );
196 PROPERTY[p++] = new Property( "Math",   "round",    "function" );
197 PROPERTY[p++] = new Property( "Math",   "sin",      "function" );
198 PROPERTY[p++] = new Property( "Math",   "sqrt",     "function" );
199 PROPERTY[p++] = new Property( "Math",   "tan",      "function" );
200
201 // properties of the Date object
202 PROPERTY[p++] = new Property( "Date",   "parse",        "function" );
203 PROPERTY[p++] = new Property( "Date",   "prototype",    "object" );
204 PROPERTY[p++] = new Property( "Date",   "UTC",          "function" );
205 PROPERTY[p++] = new Property( "Date.prototype",   "constructor",    "function" );
206 PROPERTY[p++] = new Property( "Date.prototype",   "toString",       "function" );
207 PROPERTY[p++] = new Property( "Date.prototype",   "valueOf",        "function" );
208 PROPERTY[p++] = new Property( "Date.prototype",   "getTime",        "function" );
209 PROPERTY[p++] = new Property( "Date.prototype",   "getYear",        "function" );
210 PROPERTY[p++] = new Property( "Date.prototype",   "getFullYear",    "function" );
211 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCFullYear", "function" );
212 PROPERTY[p++] = new Property( "Date.prototype",   "getMonth",       "function" );
213 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMonth",    "function" );
214 PROPERTY[p++] = new Property( "Date.prototype",   "getDate",        "function" );
215 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCDate",     "function" );
216 PROPERTY[p++] = new Property( "Date.prototype",   "getDay",         "function" );
217 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCDay",      "function" );
218 PROPERTY[p++] = new Property( "Date.prototype",   "getHours",       "function" );
219 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCHours",    "function" );
220 PROPERTY[p++] = new Property( "Date.prototype",   "getMinutes",     "function" );
221 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMinutes",  "function" );
222 PROPERTY[p++] = new Property( "Date.prototype",   "getSeconds",     "function" );
223 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCSeconds",  "function" );
224 PROPERTY[p++] = new Property( "Date.prototype",   "getMilliseconds","function" );
225 PROPERTY[p++] = new Property( "Date.prototype",   "getUTCMilliseconds", "function" );
226 PROPERTY[p++] = new Property( "Date.prototype",   "setTime",        "function" );
227 PROPERTY[p++] = new Property( "Date.prototype",   "setMilliseconds","function" );
228 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMilliseconds", "function" );
229 PROPERTY[p++] = new Property( "Date.prototype",   "setSeconds",     "function" );
230 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCSeconds",  "function" );
231 PROPERTY[p++] = new Property( "Date.prototype",   "setMinutes",     "function" );
232 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMinutes",  "function" );
233 PROPERTY[p++] = new Property( "Date.prototype",   "setHours",       "function" );
234 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCHours",    "function" );
235 PROPERTY[p++] = new Property( "Date.prototype",   "setDate",        "function" );
236 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCDate",     "function" );
237 PROPERTY[p++] = new Property( "Date.prototype",   "setMonth",       "function" );
238 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCMonth",    "function" );
239 PROPERTY[p++] = new Property( "Date.prototype",   "setFullYear",    "function" );
240 PROPERTY[p++] = new Property( "Date.prototype",   "setUTCFullYear", "function" );
241 PROPERTY[p++] = new Property( "Date.prototype",   "setYear",        "function" );
242 PROPERTY[p++] = new Property( "Date.prototype",   "toLocaleString", "function" );
243 PROPERTY[p++] = new Property( "Date.prototype",   "toUTCString",    "function" );
244 PROPERTY[p++] = new Property( "Date.prototype",   "toGMTString",    "function" );
245
246 for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
247   RESULT = eval("typeof " + PROPERTY[i].object + "." + PROPERTY[i].name );
248
249   new TestCase( SECTION,
250                 "typeof " + PROPERTY[i].object + "." + PROPERTY[i].name,
251                 PROPERTY[i].type,
252                 RESULT );
253
254   RESULT = eval("typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']");
255
256   new TestCase( SECTION,
257                 "typeof " + PROPERTY[i].object + "['" + PROPERTY[i].name +"']",
258                 PROPERTY[i].type,
259                 RESULT );
260 }
261
262 test();
263
264 function MyObject( arg0, arg1, arg2, arg3, arg4 ) {
265   this.name   = arg0;
266 }
267 function Property( object, name, type ) {
268   this.object = object;
269   this.name = name;
270   this.type = type;
271 }