Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.2.1-5.js

raw symbols SCIP
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 gTestfile = '11.2.1-5.js';
7
8 /**
9 File Name: 11.2.1-5.js
10 ECMA Section: 11.2.1 Property Accessors
11 Description:
12
13 Properties are accessed by name, using either the dot notation:
14 MemberExpression . Identifier
15 CallExpression . Identifier
16
17 or the bracket notation: MemberExpression [ Expression ]
18 CallExpression [ Expression ]
19
20 The dot notation is explained by the following syntactic conversion:
21 MemberExpression . Identifier
22 is identical in its behavior to
23 MemberExpression [ <identifier-string> ]
24 and similarly
25 CallExpression . Identifier
26 is identical in its behavior to
27 CallExpression [ <identifier-string> ]
28 where <identifier-string> is a string literal containing the same sequence
29 of characters as the Identifier.
30
31 The production MemberExpression : MemberExpression [ Expression ] is
32 evaluated as follows:
33
34 1. Evaluate MemberExpression.
35 2. Call GetValue(Result(1)).
36 3. Evaluate Expression.
37 4. Call GetValue(Result(3)).
38 5. Call ToObject(Result(2)).
39 6. Call ToString(Result(4)).
40 7. Return a value of type Reference whose base object is Result(5) and
41 whose property name is Result(6).
42
43 The production CallExpression : CallExpression [ Expression ] is evaluated
44 in exactly the same manner, except that the contained CallExpression is
45 evaluated in step 1.
46
47 Author: [email protected]
48 Date: 12 november 1997
49 */
50 var SECTION = "11.2.1-5";
51 var VERSION = "ECMA_1";
52 startTest();
53 var TITLE = "Property Accessors";
54 writeHeaderToLog( SECTION + " "+TITLE );
55
56 // go through all Native Function objects, methods, and properties and get their typeof.
57
58 var PROPERTY = new Array();
59 var p = 0;
60
61 // try to access properties of primitive types
62
63 PROPERTY[p++] = new Property( new String("hi"), "hi", "hi", NaN );
64 PROPERTY[p++] = new Property( new Number(NaN), NaN, "NaN", NaN );
65 PROPERTY[p++] = new Property( new Number(3), 3, "3", 3 );
66 PROPERTY[p++] = new Property( new Boolean(true), true, "true", 1 );
67 PROPERTY[p++] = new Property( new Boolean(false), false, "false", 0 );
68
69 for ( var i = 0, RESULT; i < PROPERTY.length; i++ ) {
70 new TestCase( SECTION,
71 PROPERTY[i].object + ".valueOf()",
72 PROPERTY[i].value,
73 eval( "PROPERTY[i].object.valueOf()" ) );
74
75 new TestCase( SECTION,
76 PROPERTY[i].object + ".toString()",
77 PROPERTY[i].string,
78 eval( "PROPERTY[i].object.toString()" ) );
79
80 }
81
82 test();
83
84 function MyObject( value ) {
85 this.value = value;
86 this.stringValue = value +"";
87 this.numberValue = Number(value);
88 return this;
89 }
90 function Property( object, value, string, number ) {
91 this.object = object;
92 this.string = String(value);
93 this.number = Number(value);
94 this.value = value;
95 }