2005-08-19 Florian Gross <flgr@ccan.de>
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / js1_2 / version120 / regress-99663.js
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is mozilla.org code.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corporation.
18  * Portions created by the Initial Developer are Copyright (C) 1998
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *   brendan@mozilla.org, pschwartau@netscape.com
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 //-----------------------------------------------------------------------------
38 var UBound = 0;
39 var bug = 99663;
40 var summary = 'Regression test for Bugzilla bug 99663';
41 /*
42  * This testcase expects error messages containing
43  * the phrase 'read-only' or something similar -
44  */
45 var READONLY = /read\s*-?\s*only/;
46 var READONLY_TRUE = 'a "read-only" error';
47 var READONLY_FALSE = 'Error: ';
48 var FAILURE = 'NO ERROR WAS GENERATED!';
49 var status = '';
50 var actual = '';
51 var expect= '';
52 var statusitems = [];
53 var expectedvalues = [];
54 var actualvalues = [];
55
56
57 /*
58  * These MUST be compiled in JS1.2 or less for the test to work - see above
59  */
60 function f1()
61 {
62   with (it)
63   {
64     for (rdonly in this);
65   }
66 }
67
68
69 function f2()
70 {
71   for (it.rdonly in this);
72 }
73
74
75 function f3(s)
76 {
77   for (it[s] in this);
78 }
79
80
81
82 /*
83  * Begin testing by capturing actual vs. expected values.
84  * Initialize to FAILURE; this will get reset if all goes well -
85  */
86 actual = FAILURE;
87 try
88 {
89   f1();
90 }
91 catch(e)
92 {
93   actual = readOnly(e.message);
94 }
95 expect= READONLY_TRUE;
96 status = 'Section 1 of test - got ' + actual;
97 addThis();
98
99
100 actual = FAILURE;
101 try
102 {
103   f2();
104 }
105 catch(e)
106 {
107   actual = readOnly(e.message);
108 }
109 expect= READONLY_TRUE;
110 status = 'Section 2 of test - got ' + actual;
111 addThis();
112
113
114 actual = FAILURE;
115 try
116 {
117   f3('rdonly');
118 }
119 catch(e)
120 {
121   actual = readOnly(e.message);
122 }
123 expect= READONLY_TRUE;
124 status = 'Section 3 of test - got ' + actual;
125 addThis();
126
127
128
129 //-----------------------------------------------------------------------------
130 test();
131 //-----------------------------------------------------------------------------
132
133
134
135 function readOnly(msg)
136 {
137   if (msg.match(READONLY))
138     return READONLY_TRUE;
139   return READONLY_FALSE + msg;
140 }
141
142
143 function addThis()
144 {
145   statusitems[UBound] = status;
146   actualvalues[UBound] = actual;
147   expectedvalues[UBound] = expect;
148   UBound++;
149 }
150
151
152 function test()
153 {
154   writeLineToLog ('Bug Number ' + bug);
155   writeLineToLog ('STATUS: ' + summary);
156
157   for (var i=0; i<UBound; i++)
158   {
159     writeTestCaseResult(expectedvalues[i], actualvalues[i], statusitems[i]);
160   }
161 }