Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 10.1.4-9.js |
michael@0 | 9 | ECMA Section: 10.1.4 Scope Chain and Identifier Resolution |
michael@0 | 10 | Description: |
michael@0 | 11 | Every execution context has associated with it a scope chain. This is |
michael@0 | 12 | logically a list of objects that are searched when binding an Identifier. |
michael@0 | 13 | When control enters an execution context, the scope chain is created and |
michael@0 | 14 | is populated with an initial set of objects, depending on the type of |
michael@0 | 15 | code. When control leaves the execution context, the scope chain is |
michael@0 | 16 | destroyed. |
michael@0 | 17 | |
michael@0 | 18 | During execution, the scope chain of the execution context is affected |
michael@0 | 19 | only by WithStatement. When execution enters a with block, the object |
michael@0 | 20 | specified in the with statement is added to the front of the scope chain. |
michael@0 | 21 | When execution leaves a with block, whether normally or via a break or |
michael@0 | 22 | continue statement, the object is removed from the scope chain. The object |
michael@0 | 23 | being removed will always be the first object in the scope chain. |
michael@0 | 24 | |
michael@0 | 25 | During execution, the syntactic production PrimaryExpression : Identifier |
michael@0 | 26 | is evaluated using the following algorithm: |
michael@0 | 27 | |
michael@0 | 28 | 1. Get the next object in the scope chain. If there isn't one, go to step 5. |
michael@0 | 29 | 2. Call the [[HasProperty]] method of Result(l), passing the Identifier as |
michael@0 | 30 | the property. |
michael@0 | 31 | 3. If Result(2) is true, return a value of type Reference whose base object |
michael@0 | 32 | is Result(l) and whose property name is the Identifier. |
michael@0 | 33 | 4. Go to step 1. |
michael@0 | 34 | 5. Return a value of type Reference whose base object is null and whose |
michael@0 | 35 | property name is the Identifier. |
michael@0 | 36 | The result of binding an identifier is always a value of type Reference with |
michael@0 | 37 | its member name component equal to the identifier string. |
michael@0 | 38 | Author: christine@netscape.com |
michael@0 | 39 | Date: 12 november 1997 |
michael@0 | 40 | */ |
michael@0 | 41 | var SECTION = "10.1.4-9"; |
michael@0 | 42 | var VERSION = "ECMA_2"; |
michael@0 | 43 | startTest(); |
michael@0 | 44 | |
michael@0 | 45 | writeHeaderToLog( SECTION + " Scope Chain and Identifier Resolution"); |
michael@0 | 46 | |
michael@0 | 47 | new TestCase( SECTION, "NEW_PROPERTY = " ); |
michael@0 | 48 | |
michael@0 | 49 | test(); |
michael@0 | 50 | |
michael@0 | 51 | function test() { |
michael@0 | 52 | for ( gTc=0; gTc < gTestcases.length; gTc++ ) { |
michael@0 | 53 | |
michael@0 | 54 | var MYOBJECT = new MyObject(); |
michael@0 | 55 | var RESULT = "hello"; |
michael@0 | 56 | |
michael@0 | 57 | with ( MYOBJECT ) { |
michael@0 | 58 | NEW_PROPERTY = RESULT; |
michael@0 | 59 | } |
michael@0 | 60 | gTestcases[gTc].actual = NEW_PROPERTY; |
michael@0 | 61 | gTestcases[gTc].expect = RESULT; |
michael@0 | 62 | |
michael@0 | 63 | gTestcases[gTc].passed = writeTestCaseResult( |
michael@0 | 64 | gTestcases[gTc].expect, |
michael@0 | 65 | gTestcases[gTc].actual, |
michael@0 | 66 | gTestcases[gTc].description +" = "+ |
michael@0 | 67 | gTestcases[gTc].actual ); |
michael@0 | 68 | |
michael@0 | 69 | gTestcases[gTc].reason += ( gTestcases[gTc].passed ) ? "" : "wrong value "; |
michael@0 | 70 | } |
michael@0 | 71 | stopTest(); |
michael@0 | 72 | return ( gTestcases ); |
michael@0 | 73 | } |
michael@0 | 74 | function MyObject( n ) { |
michael@0 | 75 | this.__proto__ = Number.prototype; |
michael@0 | 76 | } |