js/src/tests/ecma/extensions/10.1.4-9.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial