This is more accurate. Also using sorting now, for definiteness in comparisons.

This commit is contained in:
pschwartau%netscape.com 2001-09-05 00:46:24 +00:00
Родитель d643acd8b3
Коммит 018096156d
2 изменённых файлов: 194 добавлений и 56 удалений

Просмотреть файл

@ -21,13 +21,19 @@
* *
* SUMMARY: A [DontEnum] prop, if overridden, should appear in toSource(). * SUMMARY: A [DontEnum] prop, if overridden, should appear in toSource().
* See http://bugzilla.mozilla.org/show_bug.cgi?id=90596 * 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 UBound = 0;
var bug = 90596; var bug = 90596;
var summary = 'A [DontEnum] prop, if overridden, should appear in toSource()'; var summary = 'A [DontEnum] prop, if overridden, should appear in toSource()';
var LParen = '('; var cnCOMMA = ',';
var RParen = ')'; var cnLBRACE = '{';
var cnRBRACE = '}';
var cnLPAREN = '(';
var cnRPAREN = ')';
var status = ''; var status = '';
var statusitems = []; var statusitems = [];
var actual = ''; var actual = '';
@ -35,61 +41,62 @@ var actualvalues = [];
var expect= ''; var expect= '';
var expectedvalues = []; var expectedvalues = [];
var obj = {}; var obj = {};
var s = '';
status = inSection(1); status = inSection(1);
obj = {toString:9}; obj = {toString:9};
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
status = inSection(2); status = inSection(2);
obj = {hasOwnProperty:"Hi"}; obj = {hasOwnProperty:"Hi"};
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(3); status = inSection(3);
obj = {toString:9, hasOwnProperty:"Hi"}; obj = {toString:9, hasOwnProperty:"Hi"};
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(4); status = inSection(4);
obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}; obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
// TRY THE SAME THING IN EVAL CODE // TRY THE SAME THING IN EVAL CODE
var s = '';
status = inSection(5); status = inSection(5);
s = 'obj = {toString:9}'; s = 'obj = {toString:9}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
status = inSection(6); status = inSection(6);
s = 'obj = {hasOwnProperty:"Hi"}'; s = 'obj = {hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(7); status = inSection(7);
s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(8); status = inSection(8);
s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
@ -100,7 +107,7 @@ function A()
var s = 'obj = {toString:9}'; var s = 'obj = {toString:9}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
} }
A(); A();
@ -111,7 +118,7 @@ function B()
var s = 'obj = {hasOwnProperty:"Hi"}'; var s = 'obj = {hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
B(); B();
@ -122,7 +129,7 @@ function C()
var s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
C(); C();
@ -133,7 +140,7 @@ function D()
var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = obj.toSource(); actual = obj.toSource();
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
D(); D();
@ -146,31 +153,51 @@ test();
function addParens(text) /*
{ * Sort properties alphabetically -
return LParen + text + RParen; */
}
function addThis() function addThis()
{ {
statusitems[UBound] = status; statusitems[UBound] = status;
actualvalues[UBound] = stripSpaces(actual); actualvalues[UBound] = sortThis(actual);
expectedvalues[UBound] = stripSpaces(expect); expectedvalues[UBound] = sortThis(expect);
UBound++; UBound++;
} }
function stripSpaces(text) /*
* 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 = ''; var ret = '';
for (var i=0; i<text.length; i++) for (var i=0; i<text.length; i++)
{ {
if (!isWhiteSpace(text.charCodeAt(i))) charCode = text.charCodeAt(i);
{
if (!isWhiteSpace(charCode))
ret += text.charAt(i); ret += text.charAt(i);
}
} }
return ret; return ret;
} }
@ -194,13 +221,55 @@ function isWhiteSpace(charCode)
} }
/*
* 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() function test()
{ {
enterFunc ('test'); enterFunc ('test');
printBugNumber (bug); printBugNumber (bug);
printStatus (summary); printStatus (summary);
for (var i = 0; i < UBound; i++) for (var i=0; i<UBound; i++)
{ {
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
} }

Просмотреть файл

@ -21,13 +21,19 @@
* *
* SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval(). * SUMMARY: A [DontEnum] prop, if overridden, should appear in uneval().
* See http://bugzilla.mozilla.org/show_bug.cgi?id=90596 * 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 UBound = 0;
var bug = 90596; var bug = 90596;
var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()'; var summary = 'A [DontEnum] prop, if overridden, should appear in uneval()';
var LParen = '('; var cnCOMMA = ',';
var RParen = ')'; var cnLBRACE = '{';
var cnRBRACE = '}';
var cnLPAREN = '(';
var cnRPAREN = ')';
var status = ''; var status = '';
var statusitems = []; var statusitems = [];
var actual = ''; var actual = '';
@ -35,61 +41,62 @@ var actualvalues = [];
var expect= ''; var expect= '';
var expectedvalues = []; var expectedvalues = [];
var obj = {}; var obj = {};
var s = '';
status = inSection(1); status = inSection(1);
obj = {toString:9}; obj = {toString:9};
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
status = inSection(2); status = inSection(2);
obj = {hasOwnProperty:"Hi"}; obj = {hasOwnProperty:"Hi"};
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(3); status = inSection(3);
obj = {toString:9, hasOwnProperty:"Hi"}; obj = {toString:9, hasOwnProperty:"Hi"};
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(4); status = inSection(4);
obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}; obj = {prop1:1, toString:9, hasOwnProperty:"Hi"};
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
// TRY THE SAME THING IN EVAL CODE // TRY THE SAME THING IN EVAL CODE
var s = '';
status = inSection(5); status = inSection(5);
s = 'obj = {toString:9}'; s = 'obj = {toString:9}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
status = inSection(6); status = inSection(6);
s = 'obj = {hasOwnProperty:"Hi"}'; s = 'obj = {hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(7); status = inSection(7);
s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
status = inSection(8); status = inSection(8);
s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
@ -100,7 +107,7 @@ function A()
var s = 'obj = {toString:9}'; var s = 'obj = {toString:9}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9}'); expect = '({toString:9})';
addThis(); addThis();
} }
A(); A();
@ -111,7 +118,7 @@ function B()
var s = 'obj = {hasOwnProperty:"Hi"}'; var s = 'obj = {hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{hasOwnProperty:"Hi"}'); expect = '({hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
B(); B();
@ -122,7 +129,7 @@ function C()
var s = 'obj = {toString:9, hasOwnProperty:"Hi"}'; var s = 'obj = {toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{toString:9, hasOwnProperty:"Hi"}'); expect = '({toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
C(); C();
@ -133,7 +140,7 @@ function D()
var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}'; var s = 'obj = {prop1:1, toString:9, hasOwnProperty:"Hi"}';
eval(s); eval(s);
actual = uneval(obj); actual = uneval(obj);
expect = addParens('{prop1:1, toString:9, hasOwnProperty:"Hi"}'); expect = '({prop1:1, toString:9, hasOwnProperty:"Hi"})';
addThis(); addThis();
} }
D(); D();
@ -146,31 +153,51 @@ test();
function addParens(text) /*
{ * Sort properties alphabetically -
return LParen + text + RParen; */
}
function addThis() function addThis()
{ {
statusitems[UBound] = status; statusitems[UBound] = status;
actualvalues[UBound] = stripSpaces(actual); actualvalues[UBound] = sortThis(actual);
expectedvalues[UBound] = stripSpaces(expect); expectedvalues[UBound] = sortThis(expect);
UBound++; UBound++;
} }
function stripSpaces(text) /*
* 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 = ''; var ret = '';
for (var i=0; i<text.length; i++) for (var i=0; i<text.length; i++)
{ {
if (!isWhiteSpace(text.charCodeAt(i))) charCode = text.charCodeAt(i);
{
if (!isWhiteSpace(charCode))
ret += text.charAt(i); ret += text.charAt(i);
}
} }
return ret; return ret;
} }
@ -194,13 +221,55 @@ function isWhiteSpace(charCode)
} }
/*
* 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() function test()
{ {
enterFunc ('test'); enterFunc ('test');
printBugNumber (bug); printBugNumber (bug);
printStatus (summary); printStatus (summary);
for (var i = 0; i < UBound; i++) for (var i=0; i<UBound; i++)
{ {
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
} }