Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Expressions / 11.2.1-5.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-5.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-5";
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 // try to access properties of primitive types
94
95 PROPERTY[p++] = new Property(  new String("hi"),    "hi",   "hi",   NaN );
96 PROPERTY[p++] = new Property(  new Number(NaN),         NaN,    "NaN",    NaN );
97 PROPERTY[p++] = new Property(  new Number(3),           3,      "3",    3  );
98 PROPERTY[p++] = new Property(  new Boolean(true),        true,      "true",    1 );
99 PROPERTY[p++] = new Property(  new Boolean(false),       false,      "false",    0 );
100
101 for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
102   new TestCase( SECTION,
103                 PROPERTY[i].object + ".valueOf()",
104                 PROPERTY[i].value,
105                 eval( "PROPERTY[i].object.valueOf()" ) );
106
107   new TestCase( SECTION,
108                 PROPERTY[i].object + ".toString()",
109                 PROPERTY[i].string,
110                 eval( "PROPERTY[i].object.toString()" ) );
111
112 }
113
114 test();
115
116 function MyObject( value ) {
117   this.value = value;
118   this.stringValue = value +"";
119   this.numberValue = Number(value);
120   return this;
121 }
122 function Property( object, value, string, number ) {
123   this.object = object;
124   this.string = String(value);
125   this.number = Number(value);
126   this.value = value;
127 }