1 /* ***** BEGIN LICENSE BLOCK *****
\r
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
\r
4 * The contents of this file are subject to the Mozilla Public License Version
\r
5 * 1.1 (the "License"); you may not use this file except in compliance with
\r
6 * the License. You may obtain a copy of the License at
\r
7 * http://www.mozilla.org/MPL/
\r
9 * Software distributed under the License is distributed on an "AS IS" basis,
\r
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
\r
11 * for the specific language governing rights and limitations under the
\r
14 * The Original Code is mozilla.org code.
\r
16 * The Initial Developer of the Original Code is
\r
17 * Netscape Communications Corporation.
\r
18 * Portions created by the Initial Developer are Copyright (C) 1998
\r
19 * the Initial Developer. All Rights Reserved.
\r
22 * pschwartau@netscape.com
\r
24 * Alternatively, the contents of this file may be used under the terms of
\r
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
\r
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
\r
27 * in which case the provisions of the GPL or the LGPL are applicable instead
\r
28 * of those above. If you wish to allow use of your version of this file only
\r
29 * under the terms of either the GPL or the LGPL, and not to allow others to
\r
30 * use your version of this file under the terms of the MPL, indicate your
\r
31 * decision by deleting the provisions above and replace them with the notice
\r
32 * and other provisions required by the GPL or the LGPL. If you do not delete
\r
33 * the provisions above, a recipient may use your version of this file under
\r
34 * the terms of any one of the MPL, the GPL or the LGPL.
\r
36 * ***** END LICENSE BLOCK *****
\r
40 * SUMMARY: Applying Function.prototype.call to the Function object itself
\r
43 * ECMA-262 15.3.4.4 Function.prototype.call (thisArg [,arg1 [,arg2,
\85] ] )
\r
45 * When applied to the Function object itself, thisArg should be ignored.
\r
46 * As explained by Waldemar (waldemar@netscape.com):
\r
48 * Function.call(obj, "print(this)") is equivalent to invoking
\r
49 * Function("print(this)") with this set to obj. Now, Function("print(this)")
\r
50 * is equivalent to new Function("print(this)") (see 15.3.1.1), and the latter
\r
51 * ignores the this value that you passed it and constructs a function
\r
52 * (which we'll call F) which will print the value of the this that will be
\r
53 * passed in when F will be invoked.
\r
55 * With the last set of () you're invoking F(), which means you're calling it
\r
56 * with no this value. When you don't provide a this value, it defaults to the
\r
61 //-----------------------------------------------------------------------------
\r
64 var summary = 'Applying Function.prototype.call to the Function object itself';
\r
66 var statusitems = [];
\r
68 var actualvalues = [];
\r
70 var expectedvalues = [];
\r
71 var self = this; // capture a reference to the global object
\r
72 var cnOBJECT_GLOBAL = self.toString();
\r
73 var cnOBJECT_OBJECT = (new Object).toString();
\r
74 var cnHello = 'Hello';
\r
76 var objTEST = {color:cnRed};
\r
77 var f = new Function();
\r
78 var g = new Function();
\r
81 f = Function.call(self, 'return cnHello');
\r
82 g = Function.call(objTEST, 'return cnHello');
\r
84 status = 'Section A of test';
\r
89 status = 'Section B of test';
\r
95 f = Function.call(self, 'return this.toString()');
\r
96 g = Function.call(objTEST, 'return this.toString()');
\r
98 status = 'Section C of test';
\r
100 expect = cnOBJECT_GLOBAL;
\r
103 status = 'Section D of test';
\r
105 expect = cnOBJECT_GLOBAL;
\r
109 f = Function.call(self, 'return this.color');
\r
110 g = Function.call(objTEST, 'return this.color');
\r
112 status = 'Section E of test';
\r
114 expect = undefined;
\r
117 status = 'Section F of test';
\r
119 expect = undefined;
\r
124 //-----------------------------------------------------------------------------
\r
126 //-----------------------------------------------------------------------------
\r
129 function captureThis()
\r
131 statusitems[UBound] = status;
\r
132 actualvalues[UBound] = actual;
\r
133 expectedvalues[UBound] = expect;
\r
140 enterFunc ('test');
\r
141 printBugNumber (bug);
\r
142 printStatus (summary);
\r
144 for (var i = 0; i < UBound; i++)
\r
146 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
\r