1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/ExecutionContexts/10.2.2-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +/** 1.12 + File Name: 10.2.2-2.js 1.13 + ECMA Section: 10.2.2 Eval Code 1.14 + Description: 1.15 + 1.16 + When control enters an execution context for eval code, the previous 1.17 + active execution context, referred to as the calling context, is used to 1.18 + determine the scope chain, the variable object, and the this value. If 1.19 + there is no calling context, then initializing the scope chain, variable 1.20 + instantiation, and determination of the this value are performed just as 1.21 + for global code. 1.22 + 1.23 + The scope chain is initialized to contain the same objects, in the same 1.24 + order, as the calling context's scope chain. This includes objects added 1.25 + to the calling context's scope chain by WithStatement. 1.26 + 1.27 + Variable instantiation is performed using the calling context's variable 1.28 + object and using empty property attributes. 1.29 + 1.30 + The this value is the same as the this value of the calling context. 1.31 + 1.32 + Author: christine@netscape.com 1.33 + Date: 12 november 1997 1.34 +*/ 1.35 + 1.36 +var SECTION = "10.2.2-2"; 1.37 +var VERSION = "ECMA_1"; 1.38 +startTest(); 1.39 +var TITLE = "Eval Code"; 1.40 + 1.41 +writeHeaderToLog( SECTION + " "+ TITLE); 1.42 + 1.43 +// Test Objects 1.44 + 1.45 +var OBJECT = new MyObject( "hello" ); 1.46 +var GLOBAL_PROPERTIES = new Array(); 1.47 +var i = 0; 1.48 + 1.49 +for ( p in this ) { 1.50 + GLOBAL_PROPERTIES[i++] = p; 1.51 +} 1.52 + 1.53 +with ( OBJECT ) { 1.54 + var THIS = this; 1.55 + new TestCase( SECTION, 1.56 + "eval( 'this == THIS' )", 1.57 + true, 1.58 + eval("this == THIS") ); 1.59 + new TestCase( SECTION, 1.60 + "this in a with() block", 1.61 + GLOBAL, 1.62 + this+"" ); 1.63 + new TestCase( SECTION, 1.64 + "new MyObject('hello').value", 1.65 + "hello", 1.66 + value ); 1.67 + new TestCase( SECTION, 1.68 + "eval(new MyObject('hello').value)", 1.69 + "hello", 1.70 + eval("value") ); 1.71 + new TestCase( SECTION, 1.72 + "new MyObject('hello').getClass()", 1.73 + "[object Object]", 1.74 + getClass() ); 1.75 + new TestCase( SECTION, 1.76 + "eval(new MyObject('hello').getClass())", 1.77 + "[object Object]", 1.78 + eval("getClass()") ); 1.79 + new TestCase( SECTION, 1.80 + "eval(new MyObject('hello').toString())", 1.81 + "hello", 1.82 + eval("toString()") ); 1.83 + new TestCase( SECTION, 1.84 + "eval('getClass') == Object.prototype.toString", 1.85 + true, 1.86 + eval("getClass") == Object.prototype.toString ); 1.87 + 1.88 + for ( i = 0; i < GLOBAL_PROPERTIES.length; i++ ) { 1.89 + new TestCase( SECTION, GLOBAL_PROPERTIES[i] + 1.90 + " == THIS["+GLOBAL_PROPERTIES[i]+"]", true, 1.91 + eval(GLOBAL_PROPERTIES[i]) == eval( "THIS[GLOBAL_PROPERTIES[i]]") ); 1.92 + } 1.93 + 1.94 +} 1.95 + 1.96 +test(); 1.97 + 1.98 +function MyObject( value ) { 1.99 + this.value = value; 1.100 + this.getClass = Object.prototype.toString; 1.101 + this.toString = new Function( "return this.value+''" ); 1.102 + return this; 1.103 +}