Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 11.1.1.js |
michael@0 | 9 | ECMA Section: 11.1.1 The this keyword |
michael@0 | 10 | Description: |
michael@0 | 11 | |
michael@0 | 12 | The this keyword evaluates to the this value of the execution context. |
michael@0 | 13 | |
michael@0 | 14 | Author: christine@netscape.com |
michael@0 | 15 | Date: 12 november 1997 |
michael@0 | 16 | */ |
michael@0 | 17 | var SECTION = "11.1.1"; |
michael@0 | 18 | var VERSION = "ECMA_1"; |
michael@0 | 19 | startTest(); |
michael@0 | 20 | |
michael@0 | 21 | writeHeaderToLog( SECTION + " The this keyword"); |
michael@0 | 22 | |
michael@0 | 23 | var GLOBAL_OBJECT = this.toString(); |
michael@0 | 24 | |
michael@0 | 25 | // this in global code and eval(this) in global code should return the global object. |
michael@0 | 26 | |
michael@0 | 27 | new TestCase( SECTION, |
michael@0 | 28 | "Global Code: this.toString()", |
michael@0 | 29 | GLOBAL_OBJECT, |
michael@0 | 30 | this.toString() ); |
michael@0 | 31 | |
michael@0 | 32 | new TestCase( SECTION, |
michael@0 | 33 | "Global Code: eval('this.toString()')", |
michael@0 | 34 | GLOBAL_OBJECT, |
michael@0 | 35 | eval('this.toString()') ); |
michael@0 | 36 | |
michael@0 | 37 | // this in anonymous code called as a function should return the global object. |
michael@0 | 38 | |
michael@0 | 39 | new TestCase( SECTION, |
michael@0 | 40 | "Anonymous Code: var MYFUNC = new Function('return this.toString()'); MYFUNC()", |
michael@0 | 41 | GLOBAL_OBJECT, |
michael@0 | 42 | eval("var MYFUNC = new Function('return this.toString()'); MYFUNC()") ); |
michael@0 | 43 | |
michael@0 | 44 | // eval( this ) in anonymous code called as a function should return that function's activation object |
michael@0 | 45 | |
michael@0 | 46 | new TestCase( SECTION, |
michael@0 | 47 | "Anonymous Code: var MYFUNC = new Function('return (eval(\"this.toString()\")'); (MYFUNC()).toString()", |
michael@0 | 48 | GLOBAL_OBJECT, |
michael@0 | 49 | eval("var MYFUNC = new Function('return eval(\"this.toString()\")'); (MYFUNC()).toString()") ); |
michael@0 | 50 | |
michael@0 | 51 | // this and eval( this ) in anonymous code called as a constructor should return the object |
michael@0 | 52 | |
michael@0 | 53 | new TestCase( SECTION, |
michael@0 | 54 | "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()", |
michael@0 | 55 | "[object Object]", |
michael@0 | 56 | eval("var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()") ); |
michael@0 | 57 | |
michael@0 | 58 | new TestCase( SECTION, |
michael@0 | 59 | "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1", |
michael@0 | 60 | true, |
michael@0 | 61 | eval("var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") ); |
michael@0 | 62 | |
michael@0 | 63 | new TestCase( SECTION, |
michael@0 | 64 | "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC().THIS).toString()", |
michael@0 | 65 | "[object Object]", |
michael@0 | 66 | eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC()).THIS).toString()") ); |
michael@0 | 67 | |
michael@0 | 68 | new TestCase( SECTION, |
michael@0 | 69 | "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1", |
michael@0 | 70 | true, |
michael@0 | 71 | eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") ); |
michael@0 | 72 | |
michael@0 | 73 | // this and eval(this) in function code called as a function should return the global object. |
michael@0 | 74 | new TestCase( SECTION, |
michael@0 | 75 | "Function Code: ReturnThis()", |
michael@0 | 76 | GLOBAL_OBJECT, |
michael@0 | 77 | ReturnThis() ); |
michael@0 | 78 | |
michael@0 | 79 | new TestCase( SECTION, |
michael@0 | 80 | "Function Code: ReturnEvalThis()", |
michael@0 | 81 | GLOBAL_OBJECT, |
michael@0 | 82 | ReturnEvalThis() ); |
michael@0 | 83 | |
michael@0 | 84 | // this and eval(this) in function code called as a contructor should return the object. |
michael@0 | 85 | new TestCase( SECTION, |
michael@0 | 86 | "var MYOBJECT = new ReturnThis(); MYOBJECT.toString()", |
michael@0 | 87 | "[object Object]", |
michael@0 | 88 | eval("var MYOBJECT = new ReturnThis(); MYOBJECT.toString()") ); |
michael@0 | 89 | |
michael@0 | 90 | new TestCase( SECTION, |
michael@0 | 91 | "var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()", |
michael@0 | 92 | "[object Object]", |
michael@0 | 93 | eval("var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()") ); |
michael@0 | 94 | |
michael@0 | 95 | test(); |
michael@0 | 96 | |
michael@0 | 97 | function ReturnThis() { |
michael@0 | 98 | return this.toString(); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function ReturnEvalThis() { |
michael@0 | 102 | return( eval("this.toString()") ); |
michael@0 | 103 | } |