]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Object/regress-90596-002.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 uneval().
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 * Sorting properties alphabetically is done for definiteness in comparisons.
28 //-----------------------------------------------------------------------------
31 var summary
= 'A [DontEnum] prop, if overridden, should appear in uneval()';
40 var actualvalues
= [];
42 var expectedvalues
= [];
46 status
= inSection(1);
49 expect
= '({toString:9})';
52 status
= inSection(2);
53 obj
= {hasOwnProperty:"Hi"};
55 expect
= '({hasOwnProperty:"Hi"})';
58 status
= inSection(3);
59 obj
= {toString:9, hasOwnProperty:"Hi"};
61 expect
= '({toString:9, hasOwnProperty:"Hi"})';
64 status
= inSection(4);
65 obj
= {prop1:1, toString:9, hasOwnProperty:"Hi"};
67 expect
= '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
71 // TRY THE SAME THING IN EVAL CODE
74 status
= inSection(5);
75 s
= 'obj = {toString:9}';
78 expect
= '({toString:9})';
81 status
= inSection(6);
82 s
= 'obj = {hasOwnProperty:"Hi"}';
85 expect
= '({hasOwnProperty:"Hi"})';
88 status
= inSection(7);
89 s
= 'obj = {toString:9, hasOwnProperty:"Hi"}';
92 expect
= '({toString:9, hasOwnProperty:"Hi"})';
95 status
= inSection(8);
96 s
= 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
99 expect
= '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
103 // TRY THE SAME THING IN FUNCTION CODE
106 status
= inSection(9);
107 var s
= 'obj = {toString:9}';
109 actual
= uneval(obj
);
110 expect
= '({toString:9})';
117 status
= inSection(10);
118 var s
= 'obj = {hasOwnProperty:"Hi"}';
120 actual
= uneval(obj
);
121 expect
= '({hasOwnProperty:"Hi"})';
128 status
= inSection(11);
129 var s
= 'obj = {toString:9, hasOwnProperty:"Hi"}';
131 actual
= uneval(obj
);
132 expect
= '({toString:9, hasOwnProperty:"Hi"})';
139 status
= inSection(12);
140 var s
= 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
142 actual
= uneval(obj
);
143 expect
= '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
157 * Sort properties alphabetically -
161 statusitems
[UBound
] = status
;
162 actualvalues
[UBound
] = sortThis(actual
);
163 expectedvalues
[UBound
] = sortThis(expect
);
169 * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
171 function sortThis(sList
)
173 sList
= compactThis(sList
);
174 sList
= stripParens(sList
);
175 sList
= stripBraces(sList
);
176 var arr
= sList
.split(cnCOMMA
);
178 var ret
= String(arr
);
179 ret
= addBraces(ret
);
180 ret
= addParens(ret
);
186 * Strips out any whitespace from the text -
188 function compactThis(text
)
193 for (var i
=0; i
<text
.length
; i
++)
195 charCode
= text
.charCodeAt(i
);
197 if (!isWhiteSpace(charCode
))
198 ret
+= text
.charAt(i
);
205 function isWhiteSpace(charCode
)
213 case (0x000A): // '\n'
214 case (0x000D): // '\r'
225 * strips off parens at beginning and end of text -
227 function stripParens(text
)
229 // remember to escape the parens...
230 var arr
= text
.match(/^\((.*)\)$/);
232 // defend against a null match...
233 if (arr
!= null && arr
[1] != null)
240 * strips off braces at beginning and end of text -
242 function stripBraces(text
)
244 // remember to escape the braces...
245 var arr
= text
.match(/^\{(.*)\}$/);
247 // defend against a null match...
248 if (arr
!= null && arr
[1] != null)
254 function addBraces(text
)
256 return cnLBRACE
+ text
+ cnRBRACE
;
260 function addParens(text
)
262 return cnLPAREN
+ text
+ cnRPAREN
;
269 printBugNumber (bug
);
270 printStatus (summary
);
272 for (var i
=0; i
<UBound
; i
++)
274 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);