| 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/. */ |
| 5 | |
| 6 | gTestfile = '10.2.2-1.js'; |
| 7 | |
| 8 | /** |
| 9 | File Name: 10.2.2-1.js |
| 10 | ECMA Section: 10.2.2 Eval Code |
| 11 | Description: |
| 12 | |
| 13 | When control enters an execution context for eval code, the previous |
| 14 | active execution context, referred to as the calling context, is used to |
| 15 | determine the scope chain, the variable object, and the this value. If |
| 16 | there is no calling context, then initializing the scope chain, variable |
| 17 | instantiation, and determination of the this value are performed just as |
| 18 | for global code. |
| 19 | |
| 20 | The scope chain is initialized to contain the same objects, in the same |
| 21 | order, as the calling context's scope chain. This includes objects added |
| 22 | to the calling context's scope chain by WithStatement. |
| 23 | |
| 24 | Variable instantiation is performed using the calling context's variable |
| 25 | object and using empty property attributes. |
| 26 | |
| 27 | The this value is the same as the this value of the calling context. |
| 28 | |
| 29 | Author: [email protected] |
| 30 | Date: 12 november 1997 |
| 31 | */ |
| 32 | |
| 33 | var SECTION = "10.2.2-1"; |
| 34 | var VERSION = "ECMA_1"; |
| 35 | startTest(); |
| 36 | var TITLE = "Eval Code"; |
| 37 | |
| 38 | writeHeaderToLog( SECTION + " "+ TITLE); |
| 39 | |
| 40 | var THIS = eval("this"); |
| 41 | |
| 42 | new TestCase( SECTION, |
| 43 | "this +''", |
| 44 | GLOBAL, |
| 45 | THIS + "" ); |
| 46 | |
| 47 | var GLOBAL_PROPERTIES = new Array(); |
| 48 | var i = 0; |
| 49 | |
| 50 | for ( p in THIS ) { |
| 51 | GLOBAL_PROPERTIES[i++] = p; |
| 52 | } |
| 53 | |
| 54 | for ( i = 0; i < GLOBAL_PROPERTIES.length; i++ ) { |
| 55 | new TestCase( SECTION, |
| 56 | GLOBAL_PROPERTIES[i] +" == THIS["+GLOBAL_PROPERTIES[i]+"]", |
| 57 | true, |
| 58 | eval(GLOBAL_PROPERTIES[i]) == eval( "THIS[GLOBAL_PROPERTIES[i]]") ); |
| 59 | } |
| 60 | |
| 61 | // this in eval statements is the same as this value of the calling context |
| 62 | |
| 63 | var RESULT = THIS == this; |
| 64 | |
| 65 | new TestCase( SECTION, |
| 66 | "eval( 'this == THIS' )", |
| 67 | true, |
| 68 | RESULT ); |
| 69 | |
| 70 | var RESULT = THIS +''; |
| 71 | |
| 72 | new TestCase( SECTION, |
| 73 | "eval( 'this + \"\"' )", |
| 74 | GLOBAL, |
| 75 | RESULT ); |
| 76 | |
| 77 | |
| 78 | new TestCase( SECTION, |
| 79 | "eval( 'this == THIS' )", |
| 80 | true, |
| 81 | eval( "this == THIS" ) ); |
| 82 | |
| 83 | new TestCase( SECTION, |
| 84 | "eval( 'this + \"\"' )", |
| 85 | GLOBAL, |
| 86 | eval( "this +''") ); |
| 87 | |
| 88 | |
| 89 | test(); |