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-2.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-2";
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    // try to access properties of primitive types
78
79    PROPERTY[p++] = new Property(  "undefined",    void 0,   "undefined",   NaN );
80
81    for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
82        testcases[tc++] = new TestCase( SECTION,
83                                        PROPERTY[i].object + ".valueOf()",
84                                        PROPERTY[i].value,
85                                        eval( PROPERTY[i].object+ ".valueOf()" ) );
86
87        testcases[tc++] = new TestCase( SECTION,
88                                        PROPERTY[i].object + ".toString()",
89                                        PROPERTY[i].string,
90                                        eval( PROPERTY[i].object+ ".toString()" ) );
91
92    }
93
94    test();
95
96function test() {
97    for ( tc=0; tc < testcases.length; tc++ ) {
98        testcases[tc].passed = writeTestCaseResult(
99                            testcases[tc].expect,
100                            testcases[tc].actual,
101                            testcases[tc].description +" = "+
102                            testcases[tc].actual );
103
104        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
105    }
106    stopTest();
107    return ( testcases );
108}
109function MyObject( value ) {
110    this.value = value;
111    this.stringValue = value +"";
112    this.numberValue = Number(value);
113    return this;
114}
115function Property( object, value, string, number ) {
116    this.object = object;
117    this.string = String(value);
118    this.number = Number(value);
119    this.value = value;
120}