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