Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / ExecutionContexts / 10.1.4-3.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          10.1.4-1.js
42    ECMA Section:       10.1.4 Scope Chain and Identifier Resolution
43    Description:
44    Every execution context has associated with it a scope chain. This is
45    logically a list of objects that are searched when binding an Identifier.
46    When control enters an execution context, the scope chain is created and
47    is populated with an initial set of objects, depending on the type of
48    code. When control leaves the execution context, the scope chain is
49    destroyed.
50
51    During execution, the scope chain of the execution context is affected
52    only by WithStatement. When execution enters a with block, the object
53    specified in the with statement is added to the front of the scope chain.
54    When execution leaves a with block, whether normally or via a break or
55    continue statement, the object is removed from the scope chain. The object
56    being removed will always be the first object in the scope chain.
57
58    During execution, the syntactic production PrimaryExpression : Identifier
59    is evaluated using the following algorithm:
60
61    1.  Get the next object in the scope chain. If there isn't one, go to step 5.
62    2.  Call the [[HasProperty]] method of Result(l), passing the Identifier as
63    the property.
64    3.  If Result(2) is true, return a value of type Reference whose base object
65    is Result(l) and whose property name is the Identifier.
66    4.  Go to step 1.
67    5.  Return a value of type Reference whose base object is null and whose
68    property name is the Identifier.
69    The result of binding an identifier is always a value of type Reference with
70    its member name component equal to the identifier string.
71    Author:             christine@netscape.com
72    Date:               12 november 1997
73 */
74 var SECTION = "10.1.4-3";
75 var VERSION = "ECMA_1";
76 startTest();
77
78 writeHeaderToLog( SECTION + " Scope Chain and Identifier Resolution");
79
80 new TestCase( "SECTION",
81               "with MyObject, eval should be [object Global].eval " );
82
83 test();
84
85 function test() {
86   for ( gTc=0; gTc < gTestcases.length; gTc++ ) {
87
88     var MYOBJECT = new MyObject();
89     var INPUT = 2;
90     gTestcases[gTc].description += ( INPUT +"" );
91
92     with ( MYOBJECT ) {
93       eval( INPUT );
94     }
95
96     gTestcases[gTc].passed = writeTestCaseResult(
97       gTestcases[gTc].expect,
98       gTestcases[gTc].actual,
99       gTestcases[gTc].description +" = "+
100       gTestcases[gTc].actual );
101
102     gTestcases[gTc].reason += ( gTestcases[gTc].passed ) ? "" : "wrong value ";
103   }
104   stopTest();
105   return ( gTestcases );
106 }
107
108 function MyObject() {
109   this.eval = new Function( "x", "return(Math.pow(Number(x),2))" );
110 }