1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 28 August 2001
*
* SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
* See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
*
* NOTE: some inefficiencies in the test are made for the sake of readability.
* Sorting properties alphabetically is done for definiteness in comparisons.
*/
//-----------------------------------------------------------------------------
var UBound = 0;
var bug = 90596;
var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
var cnCOMMA = ',';
var cnLBRACE = '{';
var cnRBRACE = '}';
var cnLPAREN = '(';
var cnRPAREN = ')';
var status = '';
var statusitems = [];
var actual = '';
var actualvalues = [];
var expect= '';
var expectedvalues = [];
var obj = {};
status = inSection(1);
obj = {toString:9};
actual = uneval(obj);
expect = '({toString:9})';
addThis();
status = inSection(2);
obj = {hasOwnProperty:"Hi"};
actual = uneval(obj);
expect = '({hasOwnProperty:"Hi"})';
addThis();
status = inSection(3);
obj = {toString:9, hasOwnProperty:"Hi"};
actual = uneval(obj);
expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis();
status = inSection(4);
obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
actual = uneval(obj);
expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis();
// TRY THE SAME THING IN EVAL CODE
var s = '';
status = inSection(5);
s = 'obj = {toString:9}';
eval(s);
actual = uneval(obj);
expect = '({toString:9})';
addThis();
status = inSection(6);
s = 'obj = {hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({hasOwnProperty:"Hi"})';
addThis();
status = inSection(7);
s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis();
status = inSection(8);
s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis();
// TRY THE SAME THING IN FUNCTION CODE
function A()
{
status = inSection(9);
var s = 'obj = {toString:9}';
eval(s);
actual = uneval(obj);
expect = '({toString:9})';
addThis();
}
A();
function B()
{
status = inSection(10);
var s = 'obj = {hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({hasOwnProperty:"Hi"})';
addThis();
}
B();
function C()
{
status = inSection(11);
var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis();
}
C();
function D()
{
status = inSection(12);
var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s);
actual = uneval(obj);
expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis();
}
D();
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
/*
* Sort properties alphabetically -
*/
function addThis()
{
statusitems[UBound] = status;
actualvalues[UBound] = sortThis(actual);
expectedvalues[UBound] = sortThis(expect);
UBound++;
}
/*
* Takes string of form '({"c", "b", "a", 2})' and returns '({"a","b","c",2})'
*/
function sortThis(sList)
{
sList = compactThis(sList);
sList = stripParens(sList);
sList = stripBraces(sList);
var arr = sList.split(cnCOMMA);
arr = arr.sort();
var ret = String(arr);
ret = addBraces(ret);
ret = addParens(ret);
return ret;
}
/*
* Strips out any whitespace from the text -
*/
function compactThis(text)
{
var charCode = 0;
var ret = '';
for (var i=0; i<text.length; i++)
{
charCode = text.charCodeAt(i);
if (!isWhiteSpace(charCode))
ret += text.charAt(i);
}
return ret;
}
function isWhiteSpace(charCode)
{
switch (charCode)
{
case (0x0009):
case (0x000B):
case (0x000C):
case (0x0020):
case (0x000A): // '\n'
case (0x000D): // '\r'
return true;
break;
default:
return false;
}
}
/*
* strips off parens at beginning and end of text -
*/
function stripParens(text)
{
// remember to escape the parens...
var arr = text.match(/^\((.*)\)$/);
// defend against a null match...
if (arr != null && arr[1] != null)
return arr[1];
return text;
}
/*
* strips off braces at beginning and end of text -
*/
function stripBraces(text)
{
// remember to escape the braces...
var arr = text.match(/^\{(.*)\}$/);
// defend against a null match...
if (arr != null && arr[1] != null)
return arr[1];
return text;
}
function addBraces(text)
{
return cnLBRACE + text + cnRBRACE;
}
function addParens(text)
{
return cnLPAREN + text + cnRPAREN;
}
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (var i=0; i<UBound; i++)
{
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
}
exitFunc ('test');
}
|