1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * Date: 28 August 2001
42 * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
45 * NOTE: some inefficiencies in the test are made for the sake of readability.
46 * Sorting properties alphabetically is done for definiteness in comparisons.
48 //-----------------------------------------------------------------------------
50 var BUGNUMBER = 90596;
51 var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
60 var actualvalues = [];
62 var expectedvalues = [];
66 status = inSection(1);
69 expect = '({toString:9})';
72 status = inSection(2);
73 obj = {hasOwnProperty:"Hi"};
75 expect = '({hasOwnProperty:"Hi"})';
78 status = inSection(3);
79 obj = {toString:9, hasOwnProperty:"Hi"};
81 expect = '({toString:9, hasOwnProperty:"Hi"})';
84 status = inSection(4);
85 obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
87 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
91 // TRY THE SAME THING IN EVAL CODE
94 status = inSection(5);
95 s = 'obj = {toString:9}';
98 expect = '({toString:9})';
101 status = inSection(6);
102 s = 'obj = {hasOwnProperty:"Hi"}';
104 actual = uneval(obj);
105 expect = '({hasOwnProperty:"Hi"})';
108 status = inSection(7);
109 s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
111 actual = uneval(obj);
112 expect = '({toString:9, hasOwnProperty:"Hi"})';
115 status = inSection(8);
116 s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
118 actual = uneval(obj);
119 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
123 // TRY THE SAME THING IN FUNCTION CODE
126 status = inSection(9);
127 var s = 'obj = {toString:9}';
129 actual = uneval(obj);
130 expect = '({toString:9})';
137 status = inSection(10);
138 var s = 'obj = {hasOwnProperty:"Hi"}';
140 actual = uneval(obj);
141 expect = '({hasOwnProperty:"Hi"})';
148 status = inSection(11);
149 var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
151 actual = uneval(obj);
152 expect = '({toString:9, hasOwnProperty:"Hi"})';
159 status = inSection(12);
160 var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
162 actual = uneval(obj);
163 expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
170 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
177 * Sort properties alphabetically -
181 statusitems[UBound] = status;
182 actualvalues[UBound] = sortThis(actual);
183 expectedvalues[UBound] = sortThis(expect);
189 * Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
191 function sortThis(sList)
193 sList = compactThis(sList);
194 sList = stripParens(sList);
195 sList = stripBraces(sList);
196 var arr = sList.split(cnCOMMA);
198 var ret = String(arr);
199 ret = addBraces(ret);
200 ret = addParens(ret);
206 * Strips out any whitespace from the text -
208 function compactThis(text)
213 for (var i=0; i<text.length; i++)
215 charCode = text.charCodeAt(i);
217 if (!isWhiteSpace(charCode))
218 ret += text.charAt(i);
225 function isWhiteSpace(charCode)
233 case (0x000A): // '\n'
234 case (0x000D): // '\r'
245 * strips off parens at beginning and end of text -
247 function stripParens(text)
249 // remember to escape the parens...
250 var arr = text.match(/^\((.*)\)$/);
252 // defend against a null match...
253 if (arr != null && arr[1] != null)
260 * strips off braces at beginning and end of text -
262 function stripBraces(text)
264 // remember to escape the braces...
265 var arr = text.match(/^\{(.*)\}$/);
267 // defend against a null match...
268 if (arr != null && arr[1] != null)
274 function addBraces(text)
276 return cnLBRACE + text + cnRBRACE;
280 function addParens(text)
282 return cnLPAREN + text + cnRPAREN;
289 printBugNumber(BUGNUMBER);
290 printStatus (summary);
292 for (var i=0; i<UBound; i++)
294 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);