Debian Codegraph @

js/src/tests/non262/extensions/regress-90596-001.js

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