js/src/tests/ecma/ExecutionContexts/10.1.4-7.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/ExecutionContexts/10.1.4-7.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   File Name:          10.1.4-7.js
    1.12 +   ECMA Section:       10.1.4 Scope Chain and Identifier Resolution
    1.13 +   Description:
    1.14 +   Every execution context has associated with it a scope chain. This is
    1.15 +   logically a list of objects that are searched when binding an Identifier.
    1.16 +   When control enters an execution context, the scope chain is created and
    1.17 +   is populated with an initial set of objects, depending on the type of
    1.18 +   code. When control leaves the execution context, the scope chain is
    1.19 +   destroyed.
    1.20 +
    1.21 +   During execution, the scope chain of the execution context is affected
    1.22 +   only by WithStatement. When execution enters a with block, the object
    1.23 +   specified in the with statement is added to the front of the scope chain.
    1.24 +   When execution leaves a with block, whether normally or via a break or
    1.25 +   continue statement, the object is removed from the scope chain. The object
    1.26 +   being removed will always be the first object in the scope chain.
    1.27 +
    1.28 +   During execution, the syntactic production PrimaryExpression : Identifier
    1.29 +   is evaluated using the following algorithm:
    1.30 +
    1.31 +   1.  Get the next object in the scope chain. If there isn't one, go to step 5.
    1.32 +   2.  Call the [[HasProperty]] method of Result(l), passing the Identifier as
    1.33 +   the property.
    1.34 +   3.  If Result(2) is true, return a value of type Reference whose base object
    1.35 +   is Result(l) and whose property name is the Identifier.
    1.36 +   4.  Go to step 1.
    1.37 +   5.  Return a value of type Reference whose base object is null and whose
    1.38 +   property name is the Identifier.
    1.39 +   The result of binding an identifier is always a value of type Reference with
    1.40 +   its member name component equal to the identifier string.
    1.41 +   Author:             christine@netscape.com
    1.42 +   Date:               12 november 1997
    1.43 +*/
    1.44 +var SECTION = "10.1.4-7";
    1.45 +var VERSION = "ECMA_1";
    1.46 +startTest();
    1.47 +
    1.48 +writeHeaderToLog( SECTION + " Scope Chain and Identifier Resolution");
    1.49 +
    1.50 +new TestCase( "SECTION",
    1.51 +	      "with MyObject, eval should be [object Global].eval " );
    1.52 +test();
    1.53 +
    1.54 +function test() {
    1.55 +  for ( gTc=0; gTc < gTestcases.length; gTc++ ) {
    1.56 +
    1.57 +    var MYOBJECT = new MyObject();
    1.58 +    var INPUT = 2;
    1.59 +    gTestcases[gTc].description += ( INPUT +"" );
    1.60 +
    1.61 +    with ( MYOBJECT ) {
    1.62 +      delete( eval );
    1.63 +      gTestcases[gTc].actual = eval( INPUT );
    1.64 +      gTestcases[gTc].expect = INPUT;
    1.65 +    }
    1.66 +
    1.67 +    gTestcases[gTc].passed = writeTestCaseResult(
    1.68 +      gTestcases[gTc].expect,
    1.69 +      gTestcases[gTc].actual,
    1.70 +      gTestcases[gTc].description +" = "+
    1.71 +      gTestcases[gTc].actual );
    1.72 +
    1.73 +    gTestcases[gTc].reason += ( gTestcases[gTc].passed ) ? "" : "wrong value ";
    1.74 +  }
    1.75 +  stopTest();
    1.76 +  return ( gTestcases );
    1.77 +}
    1.78 +
    1.79 +function MyObject() {
    1.80 +  this.eval = new Function( "x", "return(Math.pow(Number(x),2))" );
    1.81 +}

mercurial