2005-08-16 Marek Safar <marek.safar@seznam.cz>
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / js1_5 / Regress / regress-252892.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\r
2 /* ***** BEGIN LICENSE BLOCK *****\r
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
4  *\r
5  * The contents of this file are subject to the Mozilla Public License Version\r
6  * 1.1 (the "License"); you may not use this file except in compliance with\r
7  * the License. You may obtain a copy of the License at\r
8  * http://www.mozilla.org/MPL/\r
9  *\r
10  * Software distributed under the License is distributed on an "AS IS" basis,\r
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
12  * for the specific language governing rights and limitations under the\r
13  * License.\r
14  *\r
15  * The Original Code is JavaScript Engine testing utilities.\r
16  *\r
17  * The Initial Developer of the Original Code is\r
18  * Mozilla Foundation.\r
19  * Portions created by the Initial Developer are Copyright (C) 2005\r
20  * the Initial Developer. All Rights Reserved.\r
21  *\r
22  * Contributor(s): Aleksey Chernoraenko <archer@meta-comm.com>\r
23  *                 Brendan Eich <brendan@mozilla.org>\r
24  *                 Bob Clary <bob@bclary.com>\r
25  *\r
26  * Alternatively, the contents of this file may be used under the terms of\r
27  * either the GNU General Public License Version 2 or later (the "GPL"), or\r
28  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
29  * in which case the provisions of the GPL or the LGPL are applicable instead\r
30  * of those above. If you wish to allow use of your version of this file only\r
31  * under the terms of either the GPL or the LGPL, and not to allow others to\r
32  * use your version of this file under the terms of the MPL, indicate your\r
33  * decision by deleting the provisions above and replace them with the notice\r
34  * and other provisions required by the GPL or the LGPL. If you do not delete\r
35  * the provisions above, a recipient may use your version of this file under\r
36  * the terms of any one of the MPL, the GPL or the LGPL.\r
37  *\r
38  * ***** END LICENSE BLOCK ***** */\r
39 //-----------------------------------------------------------------------------\r
40 var bug = 252892;\r
41 var summary = 'for (var i in o) in heavyweight function f should define i in f\'s activation';\r
42 var actual = '';\r
43 var expect = '';\r
44 \r
45 printBugNumber (bug);\r
46 printStatus (summary);\r
47 \r
48 var status;  \r
49 \r
50 var dodis;\r
51 \r
52 function f1(o){for(var x in o)printStatus(o[x]); return x}\r
53 function f2(o){with(this)for(var x in o)printStatus(o[x]); return x}\r
54 function f2novar(o){with(this)for(x in o)printStatus(o[x]); return x}\r
55 function f3(i,o){for(var x=i in o)printStatus(o[x]); return x}\r
56 function f4(i,o){with(this)for(var x=i in o)printStatus(o[x]); return x}\r
57 \r
58 const f1src = \r
59 "function f1(o) {\n" +\r
60 "    for (var x in o) {\n" +\r
61 "        printStatus(o[x]);\n" +\r
62 "    }\n" +\r
63 "    return x;\n" +\r
64 "}";\r
65 \r
66 const f2src = \r
67 "function f2(o) {\n" +\r
68 "    with (this) {\n" +\r
69 "        for (var x in o) {\n" +\r
70 "            printStatus(o[x]);\n" +\r
71 "        }\n" +\r
72 "    }\n" +\r
73 "    return x;\n" +\r
74 "}";\r
75 \r
76 const f2novarsrc = \r
77 "function f2novar(o) {\n" +\r
78 "    with (this) {\n" +\r
79 "        for (x in o) {\n" +\r
80 "            printStatus(o[x]);\n" +\r
81 "        }\n" +\r
82 "    }\n" +\r
83 "    return x;\n" +\r
84 "}";\r
85 \r
86 const f3src = \r
87 "function f3(i, o) {\n" +\r
88 "    var x = i;\n" +\r
89 "    for (x in o) {\n" +\r
90 "        printStatus(o[x]);\n" +\r
91 "    }\n" +\r
92 "    return x;\n" +\r
93 "}";\r
94 \r
95 const f4src = \r
96 "function f4(i, o) {\n" +\r
97 "    with (this) {\n" +\r
98 "        var x = i;\n" +\r
99 "        for (x in o) {\n" +\r
100 "            printStatus(o[x]);\n" +\r
101 "        }\n" +\r
102 "    }\n" +\r
103 "    return x;\n" +\r
104 "}";\r
105 \r
106 var t=0;\r
107 function assert(c)\r
108 {\r
109   ++t; \r
110 \r
111   status = summary + ' ' + inSection(t);\r
112   expect = true;\r
113   actual = c;\r
114 \r
115   if (!c)\r
116   {\r
117     printStatus(t + " FAILED!"); \r
118   }\r
119   reportCompare(expect, actual, summary);\r
120 }\r
121 \r
122 if (dodis && this.dis) dis(f1);\r
123 assert(f1 == f1src);\r
124 \r
125 if (dodis && this.dis) dis(f2);\r
126 assert(f2 == f2src);\r
127 \r
128 if (dodis && this.dis) dis(f2novar);\r
129 assert(f2novar == f2novarsrc);\r
130 \r
131 if (dodis && this.dis) dis(f3);\r
132 assert(f3 == f3src);\r
133 \r
134 if (dodis && this.dis) dis(f4);\r
135 assert(f4 == f4src);\r
136 \r
137 assert(f1([]) == undefined);\r
138 \r
139 assert(f1(['first']) == 0);\r
140 \r
141 assert(f2([]) == undefined);\r
142 \r
143 assert(f2(['first']) == 0);\r
144 \r
145 assert(f3(42, []) == 42);\r
146 \r
147 assert(f3(42, ['first']) == 0);\r
148 \r
149 assert(f4(42, []) == 42);\r
150 \r
151 assert(f4(42, ['first']) == 0);\r
152 \r
153 this.x = 41;\r
154 \r
155 assert(f2([]) == undefined);\r
156 \r
157 assert(f2novar([]) == 41);\r
158 \r
159 assert(f2(['first']) == undefined);\r
160 \r
161 assert(f2novar(['first']) == 0);\r