]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.1.1.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 11.1.1 The this keyword
27 The this keyword evaluates to the this value of the execution context.
29 Author: christine@netscape.com
30 Date: 12 november 1997
32 var SECTION
= "11.1.1";
33 var VERSION
= "ECMA_1";
36 writeHeaderToLog( SECTION
+ " The this keyword");
38 var testcases
= new Array();
41 var GLOBAL_OBJECT
= this.toString();
43 // this in global code and eval(this) in global code should return the global object.
45 testcases
[item
++] = new TestCase( SECTION
,
46 "Global Code: this.toString()",
50 testcases
[item
++] = new TestCase( SECTION
,
51 "Global Code: eval('this.toString()')",
53 eval('this.toString()') );
55 // this in anonymous code called as a function should return the global object.
57 testcases
[item
++] = new TestCase( SECTION
,
58 "Anonymous Code: var MYFUNC = new Function('return this.toString()'); MYFUNC()",
60 eval("var MYFUNC = new Function('return this.toString()'); MYFUNC()") );
62 // eval( this ) in anonymous code called as a function should return that function's activation object
64 testcases
[item
++] = new TestCase( SECTION
,
65 "Anonymous Code: var MYFUNC = new Function('return (eval(\"this.toString()\")'); (MYFUNC()).toString()",
67 eval("var MYFUNC = new Function('return eval(\"this.toString()\")'); (MYFUNC()).toString()") );
69 // this and eval( this ) in anonymous code called as a constructor should return the object
71 testcases
[item
++] = new TestCase( SECTION
,
72 "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()",
74 eval("var MYFUNC = new Function('this.THIS = this'); ((new MYFUNC()).THIS).toString()") );
76 testcases
[item
++] = new TestCase( SECTION
,
77 "Anonymous Code: var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
79 eval("var MYFUNC = new Function('this.THIS = this'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
81 testcases
[item
++] = new TestCase( SECTION
,
82 "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC().THIS).toString()",
84 eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); ((new MYFUNC()).THIS).toString()") );
86 testcases
[item
++] = new TestCase( SECTION
,
87 "Anonymous Code: var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1",
89 eval("var MYFUNC = new Function('this.THIS = eval(\"this\")'); var FUN1 = new MYFUNC(); FUN1.THIS == FUN1") );
91 // this and eval(this) in function code called as a function should return the global object.
92 testcases
[item
++] = new TestCase( SECTION
,
93 "Function Code: ReturnThis()",
97 testcases
[item
++] = new TestCase( SECTION
,
98 "Function Code: ReturnEvalThis()",
102 // this and eval(this) in function code called as a contructor should return the object.
103 testcases
[item
++] = new TestCase( SECTION
,
104 "var MYOBJECT = new ReturnThis(); MYOBJECT.toString()",
106 eval("var MYOBJECT = new ReturnThis(); MYOBJECT.toString()") );
108 testcases
[item
++] = new TestCase( SECTION
,
109 "var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()",
111 eval("var MYOBJECT = new ReturnEvalThis(); MYOBJECT.toString()") );
118 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
119 testcases
[tc
].passed
= writeTestCaseResult(
120 testcases
[tc
].expect
,
121 testcases
[tc
].actual
,
122 testcases
[tc
].description
+" = "+
123 testcases
[tc
].actual
);
125 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
128 return ( testcases
);
130 function ReturnThis() {
131 return this.toString();
133 function ReturnEvalThis() {
134 return( eval("this.toString()") );