Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / Function / call-001.js
1 /* ***** BEGIN LICENSE BLOCK *****\r
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
3  *\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
8  *\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
12  * License.\r
13  *\r
14  * The Original Code is mozilla.org code.\r
15  *\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
20  *\r
21  * Contributor(s):\r
22  *   pschwartau@netscape.com\r
23  *\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
35  *\r
36  * ***** END LICENSE BLOCK *****\r
37  *\r
38  * Date: 2001-07-13\r
39  *\r
40  * SUMMARY: Applying Function.prototype.call to the Function object itself\r
41  *\r
42  *\r
43  * ECMA-262 15.3.4.4 Function.prototype.call (thisArg [,arg1 [,arg2,\85] ] )\r
44  *\r
45  * When applied to the Function object itself, thisArg should be ignored.\r
46  * As explained by Waldemar (waldemar@netscape.com):\r
47  *\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
54  *\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
57  * global object.\r
58  *\r
59  */\r
60 \r
61 //-----------------------------------------------------------------------------\r
62 var UBound = 0;\r
63 var bug = '(none)';\r
64 var summary = 'Applying Function.prototype.call to the Function object itself';\r
65 var status = '';\r
66 var statusitems = [];\r
67 var actual = '';\r
68 var actualvalues = [];\r
69 var expect= '';\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
75 var cnRed = 'red';\r
76 var objTEST = {color:cnRed};\r
77 var f = new Function();\r
78 var g = new Function();\r
79 \r
80 \r
81 f = Function.call(self, 'return cnHello');\r
82 g = Function.call(objTEST, 'return cnHello');\r
83 \r
84 status = 'Section A of test';\r
85 actual = f();\r
86 expect = cnHello;\r
87 captureThis();\r
88 \r
89 status = 'Section B of test';\r
90 actual = g();\r
91 expect = cnHello;\r
92 captureThis();\r
93 \r
94 \r
95 f = Function.call(self, 'return this.toString()');\r
96 g = Function.call(objTEST, 'return this.toString()');\r
97 \r
98 status = 'Section C of test';\r
99 actual = f();\r
100 expect = cnOBJECT_GLOBAL;\r
101 captureThis();\r
102 \r
103 status = 'Section D of test';\r
104 actual = g();\r
105 expect = cnOBJECT_GLOBAL;\r
106 captureThis();\r
107 \r
108 \r
109 f = Function.call(self, 'return this.color');\r
110 g = Function.call(objTEST, 'return this.color');\r
111 \r
112 status = 'Section E of test';\r
113 actual = f();\r
114 expect = undefined;\r
115 captureThis();\r
116 \r
117 status = 'Section F of test';\r
118 actual = g();\r
119 expect = undefined;\r
120 captureThis();\r
121 \r
122 \r
123 \r
124 //-----------------------------------------------------------------------------\r
125 test();\r
126 //-----------------------------------------------------------------------------\r
127 \r
128 \r
129 function captureThis()\r
130 {\r
131   statusitems[UBound] = status;\r
132   actualvalues[UBound] = actual;\r
133   expectedvalues[UBound] = expect;\r
134   UBound++;\r
135 }\r
136 \r
137 \r
138 function test()\r
139 {\r
140   enterFunc ('test');\r
141   printBugNumber (bug);\r
142   printStatus (summary);\r
143 \r
144   for (var i = 0; i < UBound; i++)\r
145   {\r
146     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);\r
147   }\r
148 \r
149   exitFunc ('test');\r
150 }\r