]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.2.1-2.js
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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
23 File Name: 11.2.1-2.js
24 ECMA Section: 11.2.1 Property Accessors
27 Properties are accessed by name, using either the dot notation:
28 MemberExpression . Identifier
29 CallExpression . Identifier
31 or the bracket notation: MemberExpression [ Expression ]
32 CallExpression [ Expression ]
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> ]
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.
45 The production MemberExpression : MemberExpression [ Expression ] is
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).
57 The production CallExpression : CallExpression [ Expression ] is evaluated
58 in exactly the same manner, except that the contained CallExpression is
61 Author: christine@netscape.com
62 Date: 12 november 1997
64 var SECTION
= "11.2.1-2";
65 var VERSION
= "ECMA_1";
67 var TITLE
= "Property Accessors";
68 writeHeaderToLog( SECTION
+ " "+TITLE
);
70 var testcases
= new Array();
72 // go through all Native Function objects, methods, and properties and get their typeof.
74 var PROPERTY
= new Array();
77 // try to access properties of primitive types
79 PROPERTY
[p
++] = new Property( "\"hi\"", "hi", "hi", NaN
);
80 PROPERTY
[p
++] = new Property( NaN
, NaN
, "NaN", NaN
);
81 // PROPERTY[p++] = new Property( 3, 3, "3", 3 );
82 PROPERTY
[p
++] = new Property( true, true, "true", 1 );
83 PROPERTY
[p
++] = new Property( false, false, "false", 0 );
85 for ( var i
= 0, RESULT
; i
< PROPERTY
.length
; i
++ ) {
86 testcases
[tc
++] = new TestCase( SECTION
,
87 PROPERTY
[i
].object
+ ".valueOf()",
89 eval( PROPERTY
[i
].object
+ ".valueOf()" ) );
91 testcases
[tc
++] = new TestCase( SECTION
,
92 PROPERTY
[i
].object
+ ".toString()",
94 eval( PROPERTY
[i
].object
+ ".toString()" ) );
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
);
108 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
111 return ( testcases
);
113 function MyObject( value
) {
115 this.stringValue
= value
+"";
116 this.numberValue
= Number(value
);
119 function Property( object
, value
, string
, number
) {
120 this.object
= object
;
121 this.string
= String(value
);
122 this.number
= Number(value
);