]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Object/regress-90596-003.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 28 August 2001
22 * SUMMARY: A [DontEnum] prop, if overridden, should appear in for-in loops.
23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
25 * NOTE: some inefficiencies in the test are made for the sake of readability.
26 * For example, we quote string values like "Hi" in lines like this:
28 * actual = enumerateThis(obj);
29 * expect = '{prop:"Hi"}';
31 * But enumerateThis(obj) gets literal value Hi for obj.prop, not literal "Hi".
32 * We take care of all these details in the compactThis(), sortThis() functions.
33 * Sorting properties alphabetically is necessary for the test to work in Rhino.
35 //-----------------------------------------------------------------------------
38 var summary
= '[DontEnum] props (if overridden) should appear in for-in loops';
46 var actualvalues
= [];
48 var expectedvalues
= [];
52 status
= inSection(1);
54 actual
= enumerateThis(obj
);
55 expect
= '{toString:9}';
58 status
= inSection(2);
59 obj
= {hasOwnProperty:"Hi"};
60 actual
= enumerateThis(obj
);
61 expect
= '{hasOwnProperty:"Hi"}';
64 status
= inSection(3);
65 obj
= {toString:9, hasOwnProperty:"Hi"};
66 actual
= enumerateThis(obj
);
67 expect
= '{toString:9, hasOwnProperty:"Hi"}';
70 status
= inSection(4);
71 obj
= {prop1:1, toString:9, hasOwnProperty:"Hi"};
72 actual
= enumerateThis(obj
);
73 expect
= '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
77 // TRY THE SAME THING IN EVAL CODE
80 status
= inSection(5);
81 s
= 'obj = {toString:9}';
83 actual
= enumerateThis(obj
);
84 expect
= '{toString:9}';
87 status
= inSection(6);
88 s
= 'obj = {hasOwnProperty:"Hi"}';
90 actual
= enumerateThis(obj
);
91 expect
= '{hasOwnProperty:"Hi"}';
94 status
= inSection(7);
95 s
= 'obj = {toString:9, hasOwnProperty:"Hi"}';
97 actual
= enumerateThis(obj
);
98 expect
= '{toString:9, hasOwnProperty:"Hi"}';
101 status
= inSection(8);
102 s
= 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
104 actual
= enumerateThis(obj
);
105 expect
= '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
109 // TRY THE SAME THING IN FUNCTION CODE
112 status
= inSection(9);
113 var s
= 'obj = {toString:9}';
115 actual
= enumerateThis(obj
);
116 expect
= '{toString:9}';
123 status
= inSection(10);
124 var s
= 'obj = {hasOwnProperty:"Hi"}';
126 actual
= enumerateThis(obj
);
127 expect
= '{hasOwnProperty:"Hi"}';
134 status
= inSection(11);
135 var s
= 'obj = {toString:9, hasOwnProperty:"Hi"}';
137 actual
= enumerateThis(obj
);
138 expect
= '{toString:9, hasOwnProperty:"Hi"}';
145 status
= inSection(12);
146 var s
= 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
148 actual
= enumerateThis(obj
);
149 expect
= '{prop1:1, toString:9, hasOwnProperty:"Hi"}';
156 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
162 function enumerateThis(obj
)
164 var arr
= new Array();
166 for (var prop
in obj
)
168 arr
.push(prop
+ cnCOLON
+ obj
[prop
]);
171 var ret
= addBraces(String(arr
));
176 function addBraces(text
)
178 return cnLBRACE
+ text
+ cnRBRACE
;
183 * Sort properties alphabetically so the test will work in Rhino
187 statusitems
[UBound
] = status
;
188 actualvalues
[UBound
] = sortThis(actual
);
189 expectedvalues
[UBound
] = sortThis(expect
);
195 * Takes a string of the form '{"c", "b", "a", 2}' and returns '{2,a,b,c}'
197 function sortThis(sList
)
199 sList
= compactThis(sList
);
200 sList
= stripBraces(sList
);
201 var arr
= sList
.split(cnCOMMA
);
203 var ret
= String(arr
);
204 ret
= addBraces(ret
);
210 * Strips out any whitespace or quotes from the text -
212 function compactThis(text
)
217 for (var i
=0; i
<text
.length
; i
++)
219 charCode
= text
.charCodeAt(i
);
221 if (!isWhiteSpace(charCode
) && !isQuote(charCode
))
222 ret
+= text
.charAt(i
);
229 function isWhiteSpace(charCode
)
237 case (0x000A): // '\n'
238 case (0x000D): // '\r'
248 function isQuote(charCode
)
252 case (0x0027): // single quote
253 case (0x0022): // double quote
264 * strips off braces at beginning and end of text -
266 function stripBraces(text
)
268 // remember to escape the braces...
269 var arr
= text
.match(/^\{(.*)\}$/);
271 // defend against a null match...
272 if (arr
!= null && arr
[1] != null)
281 printBugNumber (bug
);
282 printStatus (summary
);
284 for (var i
=0; i
<UBound
; i
++)
286 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);