]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma/ExecutionContexts/10.2.2-2.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma / ExecutionContexts / 10.2.2-2.js
CommitLineData
b37bf2e1
A
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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23 File Name: 10.2.2-2.js
24 ECMA Section: 10.2.2 Eval Code
25 Description:
26
27 When control enters an execution context for eval code, the previous
28 active execution context, referred to as the calling context, is used to
29 determine the scope chain, the variable object, and the this value. If
30 there is no calling context, then initializing the scope chain, variable
31 instantiation, and determination of the this value are performed just as
32 for global code.
33
34 The scope chain is initialized to contain the same objects, in the same
35 order, as the calling context's scope chain. This includes objects added
36 to the calling context's scope chain by WithStatement.
37
38 Variable instantiation is performed using the calling context's variable
39 object and using empty property attributes.
40
41 The this value is the same as the this value of the calling context.
42
43 Author: christine@netscape.com
44 Date: 12 november 1997
45*/
46
47 var SECTION = "10.2.2-2";
48 var VERSION = "ECMA_1";
49 startTest();
50 var TITLE = "Eval Code";
51
52 writeHeaderToLog( SECTION + " "+ TITLE);
53
54 var testcases = new Array();
55
56 // Test Objects
57
58 var OBJECT = new MyObject( "hello" );
59 var GLOBAL_PROPERTIES = new Array();
60 var i = 0;
61
62 for ( p in this ) {
63 GLOBAL_PROPERTIES[i++] = p;
64 }
65
66 with ( OBJECT ) {
67 var THIS = this;
68 testcases[tc++] = new TestCase( SECTION, "eval( 'this == THIS' )", true, eval("this == THIS") );
69 testcases[tc++] = new TestCase( SECTION, "this in a with() block", GLOBAL, this+"" );
70 testcases[tc++] = new TestCase( SECTION, "new MyObject('hello').value", "hello", value );
71 testcases[tc++] = new TestCase( SECTION, "eval(new MyObject('hello').value)", "hello", eval("value") );
72 testcases[tc++] = new TestCase( SECTION, "new MyObject('hello').getClass()", "[object Object]", getClass() );
73 testcases[tc++] = new TestCase( SECTION, "eval(new MyObject('hello').getClass())", "[object Object]", eval("getClass()") );
74 testcases[tc++] = new TestCase( SECTION, "eval(new MyObject('hello').toString())", "hello", eval("toString()") );
75 testcases[tc++] = new TestCase( SECTION, "eval('getClass') == Object.prototype.toString", true, eval("getClass") == Object.prototype.toString );
76
77 for ( i = 0; i < GLOBAL_PROPERTIES.length; i++ ) {
78 testcases[tc++] = new TestCase( SECTION, GLOBAL_PROPERTIES[i] +
79 " == THIS["+GLOBAL_PROPERTIES[i]+"]", true,
80 eval(GLOBAL_PROPERTIES[i]) == eval( "THIS[GLOBAL_PROPERTIES[i]]") );
81 }
82
83 }
84
85 test();
86
87function test() {
88 for ( tc=0; tc < testcases.length; tc++ ) {
89 testcases[tc].passed = writeTestCaseResult(
90 testcases[tc].expect,
91 testcases[tc].actual,
92 testcases[tc].description +" = "+
93 testcases[tc].actual );
94
95 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
96 }
97 stopTest();
98 return ( testcases );
99}
100function MyObject( value ) {
101 this.value = value;
102 this.getClass = Object.prototype.toString;
103 this.toString = new Function( "return this.value+''" );
104 return this;
105}