michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 10.1.4-1.js michael@0: ECMA Section: 10.1.4 Scope Chain and Identifier Resolution michael@0: Description: michael@0: Every execution context has associated with it a scope chain. This is michael@0: logically a list of objects that are searched when binding an Identifier. michael@0: When control enters an execution context, the scope chain is created and michael@0: is populated with an initial set of objects, depending on the type of michael@0: code. When control leaves the execution context, the scope chain is michael@0: destroyed. michael@0: michael@0: During execution, the scope chain of the execution context is affected michael@0: only by WithStatement. When execution enters a with block, the object michael@0: specified in the with statement is added to the front of the scope chain. michael@0: When execution leaves a with block, whether normally or via a break or michael@0: continue statement, the object is removed from the scope chain. The object michael@0: being removed will always be the first object in the scope chain. michael@0: michael@0: During execution, the syntactic production PrimaryExpression : Identifier michael@0: is evaluated using the following algorithm: michael@0: michael@0: 1. Get the next object in the scope chain. If there isn't one, go to step 5. michael@0: 2. Call the [[HasProperty]] method of Result(l), passing the Identifier as michael@0: the property. michael@0: 3. If Result(2) is true, return a value of type Reference whose base object michael@0: is Result(l) and whose property name is the Identifier. michael@0: 4. Go to step 1. michael@0: 5. Return a value of type Reference whose base object is null and whose michael@0: property name is the Identifier. michael@0: The result of binding an identifier is always a value of type Reference with michael@0: its member name component equal to the identifier string. michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "10.1.4-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " Scope Chain and Identifier Resolution"); michael@0: michael@0: new TestCase( "SECTION", michael@0: "with MyObject, eval should be [object Global].eval " ); michael@0: test(); michael@0: michael@0: function test() { michael@0: for ( gTc=0; gTc < gTestcases.length; gTc++ ) { michael@0: michael@0: var MYOBJECT = new MyObject(); michael@0: var INPUT = 2; michael@0: gTestcases[gTc].description += ( INPUT +"" ); michael@0: michael@0: with ( MYOBJECT ) { michael@0: eval( INPUT ); michael@0: } michael@0: michael@0: gTestcases[gTc].actual = eval( INPUT ); michael@0: gTestcases[gTc].expect = INPUT; michael@0: michael@0: gTestcases[gTc].passed = writeTestCaseResult( michael@0: gTestcases[gTc].expect, michael@0: gTestcases[gTc].actual, michael@0: gTestcases[gTc].description +" = "+ michael@0: gTestcases[gTc].actual ); michael@0: michael@0: gTestcases[gTc].reason += ( gTestcases[gTc].passed ) ? "" : "wrong value "; michael@0: } michael@0: stopTest(); michael@0: return ( gTestcases ); michael@0: } michael@0: michael@0: function MyObject() { michael@0: this.eval = new Function( "x", "return(Math.pow(Number(x),2))" ); michael@0: }