|
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/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 11.2.1-4-n.js |
|
9 ECMA Section: 11.2.1 Property Accessors |
|
10 Description: |
|
11 |
|
12 Properties are accessed by name, using either the dot notation: |
|
13 MemberExpression . Identifier |
|
14 CallExpression . Identifier |
|
15 |
|
16 or the bracket notation: MemberExpression [ Expression ] |
|
17 CallExpression [ Expression ] |
|
18 |
|
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> ] |
|
23 and similarly |
|
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. |
|
29 |
|
30 The production MemberExpression : MemberExpression [ Expression ] is |
|
31 evaluated as follows: |
|
32 |
|
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). |
|
41 |
|
42 The production CallExpression : CallExpression [ Expression ] is evaluated |
|
43 in exactly the same manner, except that the contained CallExpression is |
|
44 evaluated in step 1. |
|
45 |
|
46 Author: christine@netscape.com |
|
47 Date: 12 november 1997 |
|
48 */ |
|
49 var SECTION = "11.2.1-4-n"; |
|
50 var VERSION = "ECMA_1"; |
|
51 startTest(); |
|
52 var TITLE = "Property Accessors"; |
|
53 writeHeaderToLog( SECTION + " "+TITLE ); |
|
54 |
|
55 // go through all Native Function objects, methods, and properties and get their typeof. |
|
56 |
|
57 var PROPERTY = new Array(); |
|
58 var p = 0; |
|
59 |
|
60 // try to access properties of primitive types |
|
61 |
|
62 PROPERTY[p++] = new Property( "null", null, "null", 0 ); |
|
63 |
|
64 for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) { |
|
65 |
|
66 DESCRIPTION = PROPERTY[i].object + ".valueOf()"; |
|
67 EXPECTED = "error"; |
|
68 |
|
69 new TestCase( SECTION, |
|
70 PROPERTY[i].object + ".valueOf()", |
|
71 PROPERTY[i].value, |
|
72 eval( PROPERTY[i].object+ ".valueOf()" ) ); |
|
73 |
|
74 new TestCase( SECTION, |
|
75 PROPERTY[i].object + ".toString()", |
|
76 PROPERTY[i].string, |
|
77 eval(PROPERTY[i].object+ ".toString()") ); |
|
78 |
|
79 } |
|
80 |
|
81 test(); |
|
82 |
|
83 function MyObject( value ) { |
|
84 this.value = value; |
|
85 this.stringValue = value +""; |
|
86 this.numberValue = Number(value); |
|
87 return this; |
|
88 } |
|
89 function Property( object, value, string, number ) { |
|
90 this.object = object; |
|
91 this.string = String(value); |
|
92 this.number = Number(value); |
|
93 this.value = value; |
|
94 } |