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/. */
9
ECMA Section: 11.2.1 Property Accessors
12
Properties are accessed by name, using either the dot notation:
13
MemberExpression . Identifier
14
CallExpression . Identifier
16
or the bracket notation: MemberExpression [ Expression ]
17
CallExpression [ Expression ]
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> ]
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.
30
The production MemberExpression : MemberExpression [ Expression ] is
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).
42
The production CallExpression : CallExpression [ Expression ] is evaluated
43
in exactly the same manner, except that the contained CallExpression is
46
Author: christine@netscape.com
47
Date: 12 november 1997
49
var SECTION = "11.2.1-2";
50
var VERSION = "ECMA_1";
52
var TITLE = "Property Accessors";
53
writeHeaderToLog( SECTION + " "+TITLE );
55
// go through all Native Function objects, methods, and properties and get their typeof.
57
var PROPERTY = new Array();
60
// try to access properties of primitive types
62
PROPERTY[p++] = new Property( "undefined", void 0, "undefined", NaN );
64
for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
66
DESCRIPTION = PROPERTY[i].object + ".valueOf()";
69
new TestCase( SECTION,
70
PROPERTY[i].object + ".valueOf()",
72
eval( PROPERTY[i].object+ ".valueOf()" ) );
74
new TestCase( SECTION,
75
PROPERTY[i].object + ".toString()",
77
eval(PROPERTY[i].object+ ".toString()") );
82
function MyObject( value ) {
84
this.stringValue = value +"";
85
this.numberValue = Number(value);
89
function Property( object, value, string, number ) {
91
this.string = String(value);
92
this.number = Number(value);