michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 11.2.1-2.js michael@0: ECMA Section: 11.2.1 Property Accessors michael@0: Description: michael@0: michael@0: Properties are accessed by name, using either the dot notation: michael@0: MemberExpression . Identifier michael@0: CallExpression . Identifier michael@0: michael@0: or the bracket notation: MemberExpression [ Expression ] michael@0: CallExpression [ Expression ] michael@0: michael@0: The dot notation is explained by the following syntactic conversion: michael@0: MemberExpression . Identifier michael@0: is identical in its behavior to michael@0: MemberExpression [ ] michael@0: and similarly michael@0: CallExpression . Identifier michael@0: is identical in its behavior to michael@0: CallExpression [ ] michael@0: where is a string literal containing the same sequence michael@0: of characters as the Identifier. michael@0: michael@0: The production MemberExpression : MemberExpression [ Expression ] is michael@0: evaluated as follows: michael@0: michael@0: 1. Evaluate MemberExpression. michael@0: 2. Call GetValue(Result(1)). michael@0: 3. Evaluate Expression. michael@0: 4. Call GetValue(Result(3)). michael@0: 5. Call ToObject(Result(2)). michael@0: 6. Call ToString(Result(4)). michael@0: 7. Return a value of type Reference whose base object is Result(5) and michael@0: whose property name is Result(6). michael@0: michael@0: The production CallExpression : CallExpression [ Expression ] is evaluated michael@0: in exactly the same manner, except that the contained CallExpression is michael@0: evaluated in step 1. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "11.2.1-2"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Property Accessors"; michael@0: writeHeaderToLog( SECTION + " "+TITLE ); michael@0: michael@0: // go through all Native Function objects, methods, and properties and get their typeof. michael@0: michael@0: var PROPERTY = new Array(); michael@0: var p = 0; michael@0: michael@0: // try to access properties of primitive types michael@0: michael@0: PROPERTY[p++] = new Property( "\"hi\"", "hi", "hi", NaN ); michael@0: PROPERTY[p++] = new Property( NaN, NaN, "NaN", NaN ); michael@0: // PROPERTY[p++] = new Property( 3, 3, "3", 3 ); michael@0: PROPERTY[p++] = new Property( true, true, "true", 1 ); michael@0: PROPERTY[p++] = new Property( false, false, "false", 0 ); michael@0: michael@0: for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) { michael@0: new TestCase( SECTION, michael@0: PROPERTY[i].object + ".valueOf()", michael@0: PROPERTY[i].value, michael@0: eval( PROPERTY[i].object+ ".valueOf()" ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: PROPERTY[i].object + ".toString()", michael@0: PROPERTY[i].string, michael@0: eval( PROPERTY[i].object+ ".toString()" ) ); michael@0: michael@0: } michael@0: michael@0: test(); michael@0: michael@0: function MyObject( value ) { michael@0: this.value = value; michael@0: this.stringValue = value +""; michael@0: this.numberValue = Number(value); michael@0: return this; michael@0: } michael@0: function Property( object, value, string, number ) { michael@0: this.object = object; michael@0: this.string = String(value); michael@0: this.number = Number(value); michael@0: this.value = value; michael@0: }