Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-90596-001.js

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