js/src/tests/js1_5/extensions/regress-90596-002.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:9f4972b7a4f8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 * Date: 28 August 2001
8 *
9 * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
11 *
12 * NOTE: some inefficiencies in the test are made for the sake of readability.
13 * Sorting properties alphabetically is done for definiteness in comparisons.
14 */
15 //-----------------------------------------------------------------------------
16 var UBound = 0;
17 var BUGNUMBER = 90596;
18 var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
19 var cnCOMMA = ',';
20 var cnLBRACE = '{';
21 var cnRBRACE = '}';
22 var cnLPAREN = '(';
23 var cnRPAREN = ')';
24 var status = '';
25 var statusitems = [];
26 var actual = '';
27 var actualvalues = [];
28 var expect= '';
29 var expectedvalues = [];
30 var obj = {};
31
32
33 status = inSection(1);
34 obj = {toString:9};
35 actual = uneval(obj);
36 expect = '({toString:9})';
37 addThis();
38
39 status = inSection(2);
40 obj = {hasOwnProperty:"Hi"};
41 actual = uneval(obj);
42 expect = '({hasOwnProperty:"Hi"})';
43 addThis();
44
45 status = inSection(3);
46 obj = {toString:9, hasOwnProperty:"Hi"};
47 actual = uneval(obj);
48 expect = '({toString:9, hasOwnProperty:"Hi"})';
49 addThis();
50
51 status = inSection(4);
52 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
53 actual = uneval(obj);
54 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
55 addThis();
56
57
58 // TRY THE SAME THING IN EVAL CODE
59 var s = '';
60
61 status = inSection(5);
62 s = 'obj = {toString:9}';
63 eval(s);
64 actual = uneval(obj);
65 expect = '({toString:9})';
66 addThis();
67
68 status = inSection(6);
69 s = 'obj = {hasOwnProperty:"Hi"}';
70 eval(s);
71 actual = uneval(obj);
72 expect = '({hasOwnProperty:"Hi"})';
73 addThis();
74
75 status = inSection(7);
76 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
77 eval(s);
78 actual = uneval(obj);
79 expect = '({toString:9, hasOwnProperty:"Hi"})';
80 addThis();
81
82 status = inSection(8);
83 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
84 eval(s);
85 actual = uneval(obj);
86 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
87 addThis();
88
89
90 // TRY THE SAME THING IN FUNCTION CODE
91 function A()
92 {
93 status = inSection(9);
94 var s = 'obj = {toString:9}';
95 eval(s);
96 actual = uneval(obj);
97 expect = '({toString:9})';
98 addThis();
99 }
100 A();
101
102 function B()
103 {
104 status = inSection(10);
105 var s = 'obj = {hasOwnProperty:"Hi"}';
106 eval(s);
107 actual = uneval(obj);
108 expect = '({hasOwnProperty:"Hi"})';
109 addThis();
110 }
111 B();
112
113 function C()
114 {
115 status = inSection(11);
116 var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
117 eval(s);
118 actual = uneval(obj);
119 expect = '({toString:9, hasOwnProperty:"Hi"})';
120 addThis();
121 }
122 C();
123
124 function D()
125 {
126 status = inSection(12);
127 var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
128 eval(s);
129 actual = uneval(obj);
130 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
131 addThis();
132 }
133 D();
134
135
136
137 //-----------------------------------------------------------------------------
138 test();
139 //-----------------------------------------------------------------------------
140
141
142
143 /*
144 * Sort properties alphabetically -
145 */
146 function addThis()
147 {
148 statusitems[UBound] = status;
149 actualvalues[UBound] = sortThis(actual);
150 expectedvalues[UBound] = sortThis(expect);
151 UBound++;
152 }
153
154
155 /*
156 * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
157 */
158 function sortThis(sList)
159 {
160 sList = compactThis(sList);
161 sList = stripParens(sList);
162 sList = stripBraces(sList);
163 var arr = sList.split(cnCOMMA);
164 arr = arr.sort();
165 var ret = String(arr);
166 ret = addBraces(ret);
167 ret = addParens(ret);
168 return ret;
169 }
170
171
172 /*
173 * Strips out any whitespace from the text -
174 */
175 function compactThis(text)
176 {
177 var charCode = 0;
178 var ret = '';
179
180 for (var i=0; i<text.length; i++)
181 {
182 charCode = text.charCodeAt(i);
183
184 if (!isWhiteSpace(charCode))
185 ret += text.charAt(i);
186 }
187
188 return ret;
189 }
190
191
192 function isWhiteSpace(charCode)
193 {
194 switch (charCode)
195 {
196 case (0x0009):
197 case (0x000B):
198 case (0x000C):
199 case (0x0020):
200 case (0x000A): // '\n'
201 case (0x000D): // '\r'
202 return true;
203 break;
204
205 default:
206 return false;
207 }
208 }
209
210
211 /*
212 * strips off parens at beginning and end of text -
213 */
214 function stripParens(text)
215 {
216 // remember to escape the parens...
217 var arr = text.match(/^\((.*)\)$/);
218
219 // defend against a null match...
220 if (arr != null && arr[1] != null)
221 return arr[1];
222 return text;
223 }
224
225
226 /*
227 * strips off braces at beginning and end of text -
228 */
229 function stripBraces(text)
230 {
231 // remember to escape the braces...
232 var arr = text.match(/^\{(.*)\}$/);
233
234 // defend against a null match...
235 if (arr != null && arr[1] != null)
236 return arr[1];
237 return text;
238 }
239
240
241 function addBraces(text)
242 {
243 return cnLBRACE + text + cnRBRACE;
244 }
245
246
247 function addParens(text)
248 {
249 return cnLPAREN + text + cnRPAREN;
250 }
251
252
253 function test()
254 {
255 enterFunc ('test');
256 printBugNumber(BUGNUMBER);
257 printStatus (summary);
258
259 for (var i=0; i<UBound; i++)
260 {
261 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
262 }
263
264 exitFunc ('test');
265 }

mercurial