Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.1.1.js

raw symbols SCIP
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 = '11.1.1.js';
7
8 /**
9 File Name: 11.1.1.js
10 ECMA Section: 11.1.1 The this keyword
11 Description:
12
13 The this keyword evaluates to the this value of the execution context.
14
15 Author: [email protected]
16 Date: 12 november 1997
17 */
18 var SECTION = "11.1.1";
19 var VERSION = "ECMA_1";
20 startTest();
21
22 writeHeaderToLog( SECTION + " The this keyword");
23
24 var GLOBAL_OBJECT = this.toString();
25
26 // this in global code and eval(this) in global code should return the global object.
27
28 new TestCase( SECTION,
29 "Global Code: this.toString()",
30 GLOBAL_OBJECT,
31 this.toString() );
32
33 new TestCase( SECTION,
34 "Global Code: eval('this.toString()')",
35 GLOBAL_OBJECT,
36 eval('this.toString()') );
37
38 // this in anonymous code called as a function should return the global object.
39
40 new TestCase( SECTION,
41 "Anonymous Code: var MYFUNC = new Function('return this.toString()'); MYFUNC()",
42 GLOBAL_OBJECT,
43 eval("var MYFUNC = new Function('return this.toString()'); MYFUNC()") );
44
45 // eval( this ) in anonymous code called as a function should return that function's activation object
46
47 new TestCase( SECTION,
48 "Anonymous Code: var MYFUNC = new Function('return (eval(\"this.toString()\")'); (MYFUNC()).toString()",
49 GLOBAL_OBJECT,
50 eval("var MYFUNC = new Function('return eval(\"this.toString()\")'); (MYFUNC()).toString()") );
51
52 // this and eval( this ) in anonymous code called as a constructor should return the object
53
54 new TestCase( SECTION,
55 "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()",
56 "[object Object]",
57 eval("var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()") );
58
59 new TestCase( SECTION,
60 "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
61 true,
62 eval("var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
63
64 new TestCase( SECTION,
65 "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC().THIS).toString()",
66 "[object Object]",
67 eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC()).THIS).toString()") );
68
69 new TestCase( SECTION,
70 "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
71 true,
72 eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
73
74 // this and eval(this) in function code called as a function should return the global object.
75 new TestCase( SECTION,
76 "Function Code: ReturnThis()",
77 GLOBAL_OBJECT,
78 ReturnThis() );
79
80 new TestCase( SECTION,
81 "Function Code: ReturnEvalThis()",
82 GLOBAL_OBJECT,
83 ReturnEvalThis() );
84
85 // this and eval(this) in function code called as a contructor should return the object.
86 new TestCase( SECTION,
87 "var MYOBJECT = new ReturnThis(); MYOBJECT.toString()",
88 "[object Object]",
89 eval("var MYOBJECT = new ReturnThis(); MYOBJECT.toString()") );
90
91 new TestCase( SECTION,
92 "var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()",
93 "[object Object]",
94 eval("var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()") );
95
96 test();
97
98 function ReturnThis() {
99 return this.toString();
100 }
101
102 function ReturnEvalThis() {
103 return( eval("this.toString()") );
104 }