Home | History | Annotate | Download | only in ExecutionContexts
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          10.2.2-1.js
     24     ECMA Section:       10.2.2 Eval Code
     25     Description:
     26 
     27     When control enters an execution context for eval code, the previous
     28     active execution context, referred to as the calling context, is used to
     29     determine the scope chain, the variable object, and the this value. If
     30     there is no calling context, then initializing the scope chain, variable
     31     instantiation, and determination of the this value are performed just as
     32     for global code.
     33 
     34     The scope chain is initialized to contain the same objects, in the same
     35     order, as the calling context's scope chain.  This includes objects added
     36     to the calling context's scope chain by WithStatement.
     37 
     38     Variable instantiation is performed using the calling context's variable
     39     object and using empty property attributes.
     40 
     41     The this value is the same as the this value of the calling context.
     42 
     43     Author:             christine (at) netscape.com
     44     Date:               12 november 1997
     45 */
     46 
     47     var SECTION = "10.2.2-1";
     48     var VERSION = "ECMA_1";
     49     startTest();
     50     var TITLE   = "Eval Code";
     51 
     52     writeHeaderToLog( SECTION + " "+ TITLE);
     53 
     54     var testcases = new Array();
     55 
     56     var THIS = eval("this");
     57 
     58     testcases[tc++] = new TestCase( SECTION,
     59                                     "this +''",
     60                                     GLOBAL,
     61                                     THIS + "" );
     62 
     63     var GLOBAL_PROPERTIES = new Array();
     64     var i = 0;
     65 
     66     for ( p in THIS ) {
     67         GLOBAL_PROPERTIES[i++] = p;
     68     }
     69 
     70     for ( i = 0; i < GLOBAL_PROPERTIES.length; i++ ) {
     71         testcases[tc++] = new TestCase( SECTION,
     72                                         GLOBAL_PROPERTIES[i] +" == THIS["+GLOBAL_PROPERTIES[i]+"]",
     73                                         true,
     74                                         eval(GLOBAL_PROPERTIES[i]) == eval( "THIS[GLOBAL_PROPERTIES[i]]") );
     75     }
     76 
     77     //  this in eval statements is the same as this value of the calling context
     78 
     79     var RESULT = THIS == this;
     80 
     81     testcases[tc++] = new TestCase( SECTION,
     82                                     "eval( 'this == THIS' )",
     83                                     true,
     84                                     RESULT );
     85 
     86     var RESULT = THIS +'';
     87 
     88     testcases[tc++] = new TestCase( SECTION,
     89                                     "eval( 'this + \"\"' )",
     90                                     GLOBAL,
     91                                     RESULT );
     92 
     93 
     94     testcases[tc++] = new TestCase( SECTION,
     95                                     "eval( 'this == THIS' )",
     96                                     true,
     97                                     eval( "this == THIS" ) );
     98 
     99     testcases[tc++] = new TestCase( SECTION,
    100                                     "eval( 'this + \"\"' )",
    101                                     GLOBAL,
    102                                     eval( "this +''") );
    103 
    104 
    105     test();
    106 
    107 function test() {
    108     for ( tc=0; tc < testcases.length; tc++ ) {
    109         testcases[tc].passed = writeTestCaseResult(
    110                             testcases[tc].expect,
    111                             testcases[tc].actual,
    112                             testcases[tc].description +" = "+
    113                             testcases[tc].actual );
    114 
    115         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    116     }
    117     stopTest();
    118     return ( testcases );
    119 }
    120