js/src/tests/ecma/ExecutionContexts/10.2.2-2.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.

michael@0 1 // |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
michael@0 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7
michael@0 8 /**
michael@0 9 File Name: 10.2.2-2.js
michael@0 10 ECMA Section: 10.2.2 Eval Code
michael@0 11 Description:
michael@0 12
michael@0 13 When control enters an execution context for eval code, the previous
michael@0 14 active execution context, referred to as the calling context, is used to
michael@0 15 determine the scope chain, the variable object, and the this value. If
michael@0 16 there is no calling context, then initializing the scope chain, variable
michael@0 17 instantiation, and determination of the this value are performed just as
michael@0 18 for global code.
michael@0 19
michael@0 20 The scope chain is initialized to contain the same objects, in the same
michael@0 21 order, as the calling context's scope chain. This includes objects added
michael@0 22 to the calling context's scope chain by WithStatement.
michael@0 23
michael@0 24 Variable instantiation is performed using the calling context's variable
michael@0 25 object and using empty property attributes.
michael@0 26
michael@0 27 The this value is the same as the this value of the calling context.
michael@0 28
michael@0 29 Author: christine@netscape.com
michael@0 30 Date: 12 november 1997
michael@0 31 */
michael@0 32
michael@0 33 var SECTION = "10.2.2-2";
michael@0 34 var VERSION = "ECMA_1";
michael@0 35 startTest();
michael@0 36 var TITLE = "Eval Code";
michael@0 37
michael@0 38 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 39
michael@0 40 // Test Objects
michael@0 41
michael@0 42 var OBJECT = new MyObject( "hello" );
michael@0 43 var GLOBAL_PROPERTIES = new Array();
michael@0 44 var i = 0;
michael@0 45
michael@0 46 for ( p in this ) {
michael@0 47 GLOBAL_PROPERTIES[i++] = p;
michael@0 48 }
michael@0 49
michael@0 50 with ( OBJECT ) {
michael@0 51 var THIS = this;
michael@0 52 new TestCase( SECTION,
michael@0 53 "eval( 'this == THIS' )",
michael@0 54 true,
michael@0 55 eval("this == THIS") );
michael@0 56 new TestCase( SECTION,
michael@0 57 "this in a with() block",
michael@0 58 GLOBAL,
michael@0 59 this+"" );
michael@0 60 new TestCase( SECTION,
michael@0 61 "new MyObject('hello').value",
michael@0 62 "hello",
michael@0 63 value );
michael@0 64 new TestCase( SECTION,
michael@0 65 "eval(new MyObject('hello').value)",
michael@0 66 "hello",
michael@0 67 eval("value") );
michael@0 68 new TestCase( SECTION,
michael@0 69 "new MyObject('hello').getClass()",
michael@0 70 "[object Object]",
michael@0 71 getClass() );
michael@0 72 new TestCase( SECTION,
michael@0 73 "eval(new MyObject('hello').getClass())",
michael@0 74 "[object Object]",
michael@0 75 eval("getClass()") );
michael@0 76 new TestCase( SECTION,
michael@0 77 "eval(new MyObject('hello').toString())",
michael@0 78 "hello",
michael@0 79 eval("toString()") );
michael@0 80 new TestCase( SECTION,
michael@0 81 "eval('getClass') == Object.prototype.toString",
michael@0 82 true,
michael@0 83 eval("getClass") == Object.prototype.toString );
michael@0 84
michael@0 85 for ( i = 0; i < GLOBAL_PROPERTIES.length; i++ ) {
michael@0 86 new TestCase( SECTION, GLOBAL_PROPERTIES[i] +
michael@0 87 " == THIS["+GLOBAL_PROPERTIES[i]+"]", true,
michael@0 88 eval(GLOBAL_PROPERTIES[i]) == eval( "THIS[GLOBAL_PROPERTIES[i]]") );
michael@0 89 }
michael@0 90
michael@0 91 }
michael@0 92
michael@0 93 test();
michael@0 94
michael@0 95 function MyObject( value ) {
michael@0 96 this.value = value;
michael@0 97 this.getClass = Object.prototype.toString;
michael@0 98 this.toString = new Function( "return this.value+''" );
michael@0 99 return this;
michael@0 100 }

mercurial