1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Expressions/11.2.1-5.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 11.2.1-5.js 1.12 + ECMA Section: 11.2.1 Property Accessors 1.13 + Description: 1.14 + 1.15 + Properties are accessed by name, using either the dot notation: 1.16 + MemberExpression . Identifier 1.17 + CallExpression . Identifier 1.18 + 1.19 + or the bracket notation: MemberExpression [ Expression ] 1.20 + CallExpression [ Expression ] 1.21 + 1.22 + The dot notation is explained by the following syntactic conversion: 1.23 + MemberExpression . Identifier 1.24 + is identical in its behavior to 1.25 + MemberExpression [ <identifier-string> ] 1.26 + and similarly 1.27 + CallExpression . Identifier 1.28 + is identical in its behavior to 1.29 + CallExpression [ <identifier-string> ] 1.30 + where <identifier-string> is a string literal containing the same sequence 1.31 + of characters as the Identifier. 1.32 + 1.33 + The production MemberExpression : MemberExpression [ Expression ] is 1.34 + evaluated as follows: 1.35 + 1.36 + 1. Evaluate MemberExpression. 1.37 + 2. Call GetValue(Result(1)). 1.38 + 3. Evaluate Expression. 1.39 + 4. Call GetValue(Result(3)). 1.40 + 5. Call ToObject(Result(2)). 1.41 + 6. Call ToString(Result(4)). 1.42 + 7. Return a value of type Reference whose base object is Result(5) and 1.43 + whose property name is Result(6). 1.44 + 1.45 + The production CallExpression : CallExpression [ Expression ] is evaluated 1.46 + in exactly the same manner, except that the contained CallExpression is 1.47 + evaluated in step 1. 1.48 + 1.49 + Author: christine@netscape.com 1.50 + Date: 12 november 1997 1.51 +*/ 1.52 +var SECTION = "11.2.1-5"; 1.53 +var VERSION = "ECMA_1"; 1.54 +startTest(); 1.55 +var TITLE = "Property Accessors"; 1.56 +writeHeaderToLog( SECTION + " "+TITLE ); 1.57 + 1.58 +// go through all Native Function objects, methods, and properties and get their typeof. 1.59 + 1.60 +var PROPERTY = new Array(); 1.61 +var p = 0; 1.62 + 1.63 +// try to access properties of primitive types 1.64 + 1.65 +PROPERTY[p++] = new Property( new String("hi"), "hi", "hi", NaN ); 1.66 +PROPERTY[p++] = new Property( new Number(NaN), NaN, "NaN", NaN ); 1.67 +PROPERTY[p++] = new Property( new Number(3), 3, "3", 3 ); 1.68 +PROPERTY[p++] = new Property( new Boolean(true), true, "true", 1 ); 1.69 +PROPERTY[p++] = new Property( new Boolean(false), false, "false", 0 ); 1.70 + 1.71 +for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) { 1.72 + new TestCase( SECTION, 1.73 + PROPERTY[i].object + ".valueOf()", 1.74 + PROPERTY[i].value, 1.75 + eval( "PROPERTY[i].object.valueOf()" ) ); 1.76 + 1.77 + new TestCase( SECTION, 1.78 + PROPERTY[i].object + ".toString()", 1.79 + PROPERTY[i].string, 1.80 + eval( "PROPERTY[i].object.toString()" ) ); 1.81 + 1.82 +} 1.83 + 1.84 +test(); 1.85 + 1.86 +function MyObject( value ) { 1.87 + this.value = value; 1.88 + this.stringValue = value +""; 1.89 + this.numberValue = Number(value); 1.90 + return this; 1.91 +} 1.92 +function Property( object, value, string, number ) { 1.93 + this.object = object; 1.94 + this.string = String(value); 1.95 + this.number = Number(value); 1.96 + this.value = value; 1.97 +}