Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / js1_5 / Object / regress-90596-002.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: 28 August 2001\r
39  *\r
40  * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().\r
41  * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596\r
42  *\r
43  * NOTE: some inefficiencies in the test are made for the sake of readability.\r
44  * Sorting properties alphabetically is done for definiteness in comparisons.\r
45  */\r
46 //-----------------------------------------------------------------------------\r
47 var UBound = 0;\r
48 var bug = 90596;\r
49 var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';\r
50 var cnCOMMA = ',';\r
51 var cnLBRACE = '{';\r
52 var cnRBRACE = '}';\r
53 var cnLPAREN = '(';\r
54 var cnRPAREN = ')';\r
55 var status = '';\r
56 var statusitems = [];\r
57 var actual = '';\r
58 var actualvalues = [];\r
59 var expect= '';\r
60 var expectedvalues = [];\r
61 var obj = {};\r
62 \r
63 \r
64 status = inSection(1);\r
65 obj = {toString:9};\r
66 actual = uneval(obj);\r
67 expect = '({toString:9})';\r
68 addThis();\r
69 \r
70 status = inSection(2);\r
71 obj = {hasOwnProperty:"Hi"};\r
72 actual = uneval(obj);\r
73 expect = '({hasOwnProperty:"Hi"})';\r
74 addThis();\r
75 \r
76 status = inSection(3);\r
77 obj = {toString:9, hasOwnProperty:"Hi"};\r
78 actual = uneval(obj);\r
79 expect = '({toString:9, hasOwnProperty:"Hi"})';\r
80 addThis();\r
81 \r
82 status = inSection(4);\r
83 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};\r
84 actual = uneval(obj);\r
85 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';\r
86 addThis();\r
87 \r
88 \r
89 // TRY THE SAME THING IN EVAL CODE\r
90 var s = '';\r
91 \r
92 status = inSection(5);\r
93 s = 'obj = {toString:9}';\r
94 eval(s);\r
95 actual = uneval(obj);\r
96 expect = '({toString:9})';\r
97 addThis();\r
98 \r
99 status = inSection(6);\r
100 s = 'obj = {hasOwnProperty:"Hi"}';\r
101 eval(s);\r
102 actual = uneval(obj);\r
103 expect = '({hasOwnProperty:"Hi"})';\r
104 addThis();\r
105 \r
106 status = inSection(7);\r
107 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';\r
108 eval(s);\r
109 actual = uneval(obj);\r
110 expect = '({toString:9, hasOwnProperty:"Hi"})';\r
111 addThis();\r
112 \r
113 status = inSection(8);\r
114 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';\r
115 eval(s);\r
116 actual = uneval(obj);\r
117 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';\r
118 addThis();\r
119 \r
120 \r
121 // TRY THE SAME THING IN FUNCTION CODE\r
122 function A()\r
123 {\r
124   status = inSection(9);\r
125   var s = 'obj = {toString:9}';\r
126   eval(s);\r
127   actual = uneval(obj);\r
128   expect = '({toString:9})';\r
129   addThis();\r
130 }\r
131 A();\r
132 \r
133 function B()\r
134 {\r
135   status = inSection(10);\r
136   var s = 'obj = {hasOwnProperty:"Hi"}';\r
137   eval(s);\r
138   actual = uneval(obj);\r
139   expect = '({hasOwnProperty:"Hi"})';\r
140   addThis();\r
141 }\r
142 B();\r
143 \r
144 function C()\r
145 {\r
146   status = inSection(11);\r
147   var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';\r
148   eval(s);\r
149   actual = uneval(obj);\r
150   expect = '({toString:9, hasOwnProperty:"Hi"})';\r
151   addThis();\r
152 }\r
153 C();\r
154 \r
155 function D()\r
156 {\r
157   status = inSection(12);\r
158   var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';\r
159   eval(s);\r
160   actual = uneval(obj);\r
161   expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';\r
162   addThis();\r
163 }\r
164 D();\r
165 \r
166 \r
167 \r
168 //-----------------------------------------------------------------------------\r
169 test();\r
170 //-----------------------------------------------------------------------------\r
171 \r
172 \r
173 \r
174 /*\r
175  * Sort properties alphabetically -\r
176  */\r
177 function addThis()\r
178 {\r
179   statusitems[UBound] = status;\r
180   actualvalues[UBound] = sortThis(actual);\r
181   expectedvalues[UBound] = sortThis(expect);\r
182   UBound++;\r
183 }\r
184 \r
185 \r
186 /*\r
187  * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'\r
188  */\r
189 function sortThis(sList)\r
190 {\r
191   sList = compactThis(sList);\r
192   sList = stripParens(sList);\r
193   sList = stripBraces(sList);\r
194   var arr = sList.split(cnCOMMA);\r
195   arr = arr.sort();\r
196   var ret = String(arr);\r
197   ret = addBraces(ret);\r
198   ret = addParens(ret);\r
199   return ret;\r
200 }\r
201 \r
202 \r
203 /*\r
204  * Strips out any whitespace from the text -\r
205  */\r
206 function compactThis(text)\r
207 {\r
208   var charCode = 0;\r
209   var ret = '';\r
210 \r
211   for (var i=0; i<text.length; i++)\r
212   {\r
213     charCode = text.charCodeAt(i);\r
214 \r
215     if (!isWhiteSpace(charCode))\r
216       ret += text.charAt(i);\r
217   }\r
218 \r
219   return ret;\r
220 }\r
221 \r
222 \r
223 function isWhiteSpace(charCode)\r
224 {\r
225   switch (charCode)\r
226   {\r
227     case (0x0009):\r
228     case (0x000B):\r
229     case (0x000C):\r
230     case (0x0020):\r
231     case (0x000A):  // '\n'\r
232     case (0x000D):  // '\r'\r
233       return true;\r
234       break;\r
235 \r
236     default:\r
237       return false;\r
238   }\r
239 }\r
240 \r
241 \r
242 /*\r
243  * strips off parens at beginning and end of text -\r
244  */\r
245 function stripParens(text)\r
246 {\r
247   // remember to escape the parens...\r
248   var arr = text.match(/^\((.*)\)$/);\r
249 \r
250   // defend against a null match...\r
251   if (arr != null && arr[1] != null)\r
252     return arr[1];\r
253   return text;\r
254 }\r
255 \r
256 \r
257 /*\r
258  * strips off braces at beginning and end of text -\r
259  */\r
260 function stripBraces(text)\r
261 {\r
262   // remember to escape the braces...\r
263   var arr = text.match(/^\{(.*)\}$/);\r
264 \r
265   // defend against a null match...\r
266   if (arr != null && arr[1] != null)\r
267     return arr[1];\r
268   return text;\r
269 }\r
270 \r
271 \r
272 function addBraces(text)\r
273 {\r
274   return cnLBRACE + text + cnRBRACE;\r
275 }\r
276 \r
277 \r
278 function addParens(text)\r
279 {\r
280   return cnLPAREN + text + cnRPAREN;\r
281 }\r
282 \r
283 \r
284 function test()\r
285 {\r
286   enterFunc ('test');\r
287   printBugNumber (bug);\r
288   printStatus (summary);\r
289 \r
290   for (var i=0; i<UBound; i++)\r
291   {\r
292     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);\r
293   }\r
294 \r
295   exitFunc ('test');\r
296 }\r