]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/Function/call-001.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an
8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): pschwartau@netscape.com
22 * SUMMARY: Applying Function.prototype.call to the Function object itself
25 * ECMA-262 15.3.4.4 Function.prototype.call (thisArg [,arg1 [,arg2,\85] ] )
27 * When applied to the Function object itself, thisArg should be ignored.
28 * As explained by Waldemar (waldemar@netscape.com):
30 * Function.call(obj, "print(this)") is equivalent to invoking
31 * Function("print(this)") with this set to obj. Now, Function("print(this)")
32 * is equivalent to new Function("print(this)") (see 15.3.1.1), and the latter
33 * ignores the this value that you passed it and constructs a function
34 * (which we'll call F) which will print the value of the this that will be
35 * passed in when F will be invoked.
37 * With the last set of () you're invoking F(), which means you're calling it
38 * with no this value. When you don't provide a this value, it defaults to the
42 //-----------------------------------------------------------------------------
45 var summary
= 'Applying Function.prototype.call to the Function object itself';
49 var actualvalues
= [];
51 var expectedvalues
= [];
52 var self
= this; // capture a reference to the global object
53 var cnOBJECT_GLOBAL
= self
.toString();
54 var cnOBJECT_OBJECT
= (new Object
).toString();
55 var cnHello
= 'Hello';
57 var objTEST
= {color:cnRed
};
58 var f
= new Function();
59 var g
= new Function();
62 f
= Function
.call(self
, 'return cnHello');
63 g
= Function
.call(objTEST
, 'return cnHello');
65 status
= 'Section A of test';
70 status
= 'Section B of test';
76 f
= Function
.call(self
, 'return this.toString()');
77 g
= Function
.call(objTEST
, 'return this.toString()');
79 status
= 'Section C of test';
81 expect
= cnOBJECT_GLOBAL
;
84 status
= 'Section D of test';
86 expect
= cnOBJECT_GLOBAL
;
90 f
= Function
.call(self
, 'return this.color');
91 g
= Function
.call(objTEST
, 'return this.color');
93 status
= 'Section E of test';
98 status
= 'Section F of test';
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
110 function captureThis()
112 statusitems
[UBound
] = status
;
113 actualvalues
[UBound
] = actual
;
114 expectedvalues
[UBound
] = expect
;
122 printBugNumber (bug
);
123 printStatus (summary
);
125 for (var i
= 0; i
< UBound
; i
++)
127 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);