1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: Applying Function.prototype.call to the Function object itself
45 * ECMA-262 15.3.4.4 Function.prototype.call (thisArg [,arg1 [,arg2,
\85] ] )
47 * When applied to the Function object itself, thisArg should be ignored.
48 * As explained by Waldemar (waldemar@netscape.com):
50 * Function.call(obj, "print(this)") is equivalent to invoking
51 * Function("print(this)") with this set to obj. Now, Function("print(this)")
52 * is equivalent to new Function("print(this)") (see 15.3.1.1), and the latter
53 * ignores the this value that you passed it and constructs a function
54 * (which we'll call F) which will print the value of the this that will be
55 * passed in when F will be invoked.
57 * With the last set of () you're invoking F(), which means you're calling it
58 * with no this value. When you don't provide a this value, it defaults to the
63 //-----------------------------------------------------------------------------
65 var BUGNUMBER = '(none)';
66 var summary = 'Applying Function.prototype.call to the Function object itself';
70 var actualvalues = [];
72 var expectedvalues = [];
73 var self = this; // capture a reference to the global object
74 var cnOBJECT_GLOBAL = self.toString();
75 var cnOBJECT_OBJECT = (new Object).toString();
76 var cnHello = 'Hello';
78 var objTEST = {color:cnRed};
79 var f = new Function();
80 var g = new Function();
83 f = Function.call(self, 'return cnHello');
84 g = Function.call(objTEST, 'return cnHello');
86 status = 'Section A of test';
91 status = 'Section B of test';
97 f = Function.call(self, 'return this.toString()');
98 g = Function.call(objTEST, 'return this.toString()');
100 status = 'Section C of test';
102 expect = cnOBJECT_GLOBAL;
105 status = 'Section D of test';
107 expect = cnOBJECT_GLOBAL;
111 f = Function.call(self, 'return this.color');
112 g = Function.call(objTEST, 'return this.color');
114 status = 'Section E of test';
119 status = 'Section F of test';
126 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
131 function captureThis()
133 statusitems[UBound] = status;
134 actualvalues[UBound] = actual;
135 expectedvalues[UBound] = expect;
143 printBugNumber(BUGNUMBER);
144 printStatus (summary);
146 for (var i = 0; i < UBound; i++)
148 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);