1 /* ***** BEGIN LICENSE BLOCK *****
\r
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
\r
4 * The contents of this file are subject to the Mozilla Public License Version
\r
5 * 1.1 (the "License"); you may not use this file except in compliance with
\r
6 * the License. You may obtain a copy of the License at
\r
7 * http://www.mozilla.org/MPL/
\r
9 * Software distributed under the License is distributed on an "AS IS" basis,
\r
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
\r
11 * for the specific language governing rights and limitations under the
\r
14 * The Original Code is mozilla.org code.
\r
16 * The Initial Developer of the Original Code is
\r
17 * Netscape Communications Corporation.
\r
18 * Portions created by the Initial Developer are Copyright (C) 1998
\r
19 * the Initial Developer. All Rights Reserved.
\r
22 * pschwartau@netscape.com
\r
24 * Alternatively, the contents of this file may be used under the terms of
\r
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
\r
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
\r
27 * in which case the provisions of the GPL or the LGPL are applicable instead
\r
28 * of those above. If you wish to allow use of your version of this file only
\r
29 * under the terms of either the GPL or the LGPL, and not to allow others to
\r
30 * use your version of this file under the terms of the MPL, indicate your
\r
31 * decision by deleting the provisions above and replace them with the notice
\r
32 * and other provisions required by the GPL or the LGPL. If you do not delete
\r
33 * the provisions above, a recipient may use your version of this file under
\r
34 * the terms of any one of the MPL, the GPL or the LGPL.
\r
36 * ***** END LICENSE BLOCK *****
\r
38 * Date: 28 August 2001
\r
40 * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
\r
41 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
\r
43 * NOTE: some inefficiencies in the test are made for the sake of readability.
\r
44 * Sorting properties alphabetically is done for definiteness in comparisons.
\r
46 //-----------------------------------------------------------------------------
\r
49 var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
\r
56 var statusitems = [];
\r
58 var actualvalues = [];
\r
60 var expectedvalues = [];
\r
64 status = inSection(1);
\r
66 actual = uneval(obj);
\r
67 expect = '({toString:9})';
\r
70 status = inSection(2);
\r
71 obj = {hasOwnProperty:"Hi"};
\r
72 actual = uneval(obj);
\r
73 expect = '({hasOwnProperty:"Hi"})';
\r
76 status = inSection(3);
\r
77 obj = {toString:9, hasOwnProperty:"Hi"};
\r
78 actual = uneval(obj);
\r
79 expect = '({toString:9, hasOwnProperty:"Hi"})';
\r
82 status = inSection(4);
\r
83 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
\r
84 actual = uneval(obj);
\r
85 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
\r
89 // TRY THE SAME THING IN EVAL CODE
\r
92 status = inSection(5);
\r
93 s = 'obj = {toString:9}';
\r
95 actual = uneval(obj);
\r
96 expect = '({toString:9})';
\r
99 status = inSection(6);
\r
100 s = 'obj = {hasOwnProperty:"Hi"}';
\r
102 actual = uneval(obj);
\r
103 expect = '({hasOwnProperty:"Hi"})';
\r
106 status = inSection(7);
\r
107 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
\r
109 actual = uneval(obj);
\r
110 expect = '({toString:9, hasOwnProperty:"Hi"})';
\r
113 status = inSection(8);
\r
114 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
\r
116 actual = uneval(obj);
\r
117 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
\r
121 // TRY THE SAME THING IN FUNCTION CODE
\r
124 status = inSection(9);
\r
125 var s = 'obj = {toString:9}';
\r
127 actual = uneval(obj);
\r
128 expect = '({toString:9})';
\r
135 status = inSection(10);
\r
136 var s = 'obj = {hasOwnProperty:"Hi"}';
\r
138 actual = uneval(obj);
\r
139 expect = '({hasOwnProperty:"Hi"})';
\r
146 status = inSection(11);
\r
147 var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
\r
149 actual = uneval(obj);
\r
150 expect = '({toString:9, hasOwnProperty:"Hi"})';
\r
157 status = inSection(12);
\r
158 var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
\r
160 actual = uneval(obj);
\r
161 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
\r
168 //-----------------------------------------------------------------------------
\r
170 //-----------------------------------------------------------------------------
\r
175 * Sort properties alphabetically -
\r
179 statusitems[UBound] = status;
\r
180 actualvalues[UBound] = sortThis(actual);
\r
181 expectedvalues[UBound] = sortThis(expect);
\r
187 * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
\r
189 function sortThis(sList)
\r
191 sList = compactThis(sList);
\r
192 sList = stripParens(sList);
\r
193 sList = stripBraces(sList);
\r
194 var arr = sList.split(cnCOMMA);
\r
196 var ret = String(arr);
\r
197 ret = addBraces(ret);
\r
198 ret = addParens(ret);
\r
204 * Strips out any whitespace from the text -
\r
206 function compactThis(text)
\r
211 for (var i=0; i<text.length; i++)
\r
213 charCode = text.charCodeAt(i);
\r
215 if (!isWhiteSpace(charCode))
\r
216 ret += text.charAt(i);
\r
223 function isWhiteSpace(charCode)
\r
231 case (0x000A): // '\n'
\r
232 case (0x000D): // '\r'
\r
243 * strips off parens at beginning and end of text -
\r
245 function stripParens(text)
\r
247 // remember to escape the parens...
\r
248 var arr = text.match(/^\((.*)\)$/);
\r
250 // defend against a null match...
\r
251 if (arr != null && arr[1] != null)
\r
258 * strips off braces at beginning and end of text -
\r
260 function stripBraces(text)
\r
262 // remember to escape the braces...
\r
263 var arr = text.match(/^\{(.*)\}$/);
\r
265 // defend against a null match...
\r
266 if (arr != null && arr[1] != null)
\r
272 function addBraces(text)
\r
274 return cnLBRACE + text + cnRBRACE;
\r
278 function addParens(text)
\r
280 return cnLPAREN + text + cnRPAREN;
\r
286 enterFunc ('test');
\r
287 printBugNumber (bug);
\r
288 printStatus (summary);
\r
290 for (var i=0; i<UBound; i++)
\r
292 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
\r