Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / js1_5 / Scope / scope-004.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-16\r
39  *\r
40  * SUMMARY:  Testing visiblity of variables from within a with block.\r
41  * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325\r
42  */\r
43 //-------------------------------------------------------------------------------------------------\r
44 var UBound = 0;\r
45 var bug = 90325;\r
46 var summary = 'Testing visiblity of variables from within a with block';\r
47 var status = '';\r
48 var statusitems = [];\r
49 var actual = '';\r
50 var actualvalues = [];\r
51 var expect= '';\r
52 var expectedvalues = [];\r
53 \r
54 // (compare local definitions which follow) -\r
55 var A = 'global A';\r
56 var B = 'global B';\r
57 var C = 'global C';\r
58 var D = 'global D';\r
59 \r
60 // an object with 'C' and 'D' properties -\r
61 var objTEST = new Object();\r
62 objTEST.C = C;\r
63 objTEST.D = D;\r
64 \r
65 \r
66 status = 'Section 1 of test';\r
67 with (new Object())\r
68 {\r
69   actual = A;\r
70   expect = 'global A';\r
71 }\r
72 addThis();\r
73 \r
74 \r
75 status = 'Section 2 of test';\r
76 with (Function)\r
77 {\r
78   actual = B;\r
79   expect = 'global B';\r
80 }\r
81 addThis();\r
82 \r
83 \r
84 status = 'Section 3 of test';\r
85 with (this)\r
86 {\r
87   actual = C;\r
88   expect = 'global C';\r
89 }\r
90 addThis();\r
91 \r
92 \r
93 status = 'Section 4 of test';\r
94 localA();\r
95 addThis();\r
96 \r
97 status = 'Section 5 of test';\r
98 localB();\r
99 addThis();\r
100 \r
101 status = 'Section 6 of test';\r
102 localC();\r
103 addThis();\r
104 \r
105 status = 'Section 7 of test';\r
106 localC(new Object());\r
107 addThis();\r
108 \r
109 status = 'Section 8 of test';\r
110 localC.apply(new Object());\r
111 addThis();\r
112 \r
113 status = 'Section 9 of test';\r
114 localC.apply(new Object(), [objTEST]);\r
115 addThis();\r
116 \r
117 status = 'Section 10 of test';\r
118 localC.apply(objTEST, [objTEST]);\r
119 addThis();\r
120 \r
121 status = 'Section 11 of test';\r
122 localD(new Object());\r
123 addThis();\r
124 \r
125 status = 'Section 12 of test';\r
126 localD.apply(new Object(), [objTEST]);\r
127 addThis();\r
128 \r
129 status = 'Section 13 of test';\r
130 localD.apply(objTEST, [objTEST]);\r
131 addThis();\r
132 \r
133 \r
134 \r
135 //-------------------------------------------------------------------------------------------------\r
136 test();\r
137 //-------------------------------------------------------------------------------------------------\r
138 \r
139 \r
140 \r
141 // contains a with(new Object()) block -\r
142 function localA()\r
143 {\r
144   var A = 'local A';\r
145 \r
146   with(new Object())\r
147   {\r
148     actual = A;\r
149     expect = 'local A';\r
150   }\r
151 }\r
152 \r
153 \r
154 // contains a with(Number) block -\r
155 function localB()\r
156 {\r
157   var B = 'local B';\r
158 \r
159   with(Number)\r
160   {\r
161     actual = B;\r
162     expect = 'local B';\r
163   }\r
164 }\r
165 \r
166 \r
167 // contains a with(this) block -\r
168 function localC(obj)\r
169 {\r
170   var C = 'local C';\r
171 \r
172   with(this)\r
173   {\r
174     actual = C;\r
175   }\r
176 \r
177   if ('C' in this)\r
178     expect = this.C;\r
179   else\r
180     expect = 'local C';\r
181 }\r
182 \r
183 \r
184 // contains a with(obj) block -\r
185 function localD(obj)\r
186 {\r
187   var D = 'local D';\r
188 \r
189   with(obj)\r
190   {\r
191     actual = D;\r
192   }\r
193 \r
194   if ('D' in obj)\r
195     expect = obj.D;\r
196   else\r
197     expect = 'local D';\r
198 }\r
199 \r
200 \r
201 function addThis()\r
202 {\r
203   statusitems[UBound] = status;\r
204   actualvalues[UBound] = actual;\r
205   expectedvalues[UBound] = expect;\r
206   UBound++;\r
207 }\r
208 \r
209 \r
210 function test()\r
211 {\r
212   enterFunc ('test');\r
213   printBugNumber (bug);\r
214   printStatus (summary);\r
215 \r
216   for (var i = 0; i < UBound; i++)\r
217   {\r
218     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);\r
219   }\r
220 \r
221   exitFunc ('test');\r
222 }\r