зеркало из https://github.com/mozilla/gecko-dev.git
Bug 461180: Fix test case result comparison function.
The old code fails when actual is Number.NaN and expected is a number. (Patch from mrbkap, jimb, and Waldo.)
This commit is contained in:
Родитель
68b268583f
Коммит
0e3c433601
|
@ -693,48 +693,30 @@ if (typeof options == 'function')
|
|||
|
||||
function getTestCaseResult(expected, actual)
|
||||
{
|
||||
var expected_t = typeof expected;
|
||||
var actual_t = typeof actual;
|
||||
var passed = true;
|
||||
if (typeof expected != typeof actual)
|
||||
return false;
|
||||
if (typeof expected != 'number')
|
||||
// Note that many tests depend on the use of '==' here, not '==='.
|
||||
return actual == expected;
|
||||
|
||||
// because ( NaN == NaN ) always returns false, need to do
|
||||
// a special compare to see if we got the right result.
|
||||
// Distinguish NaN from other values. Using x != x comparisons here
|
||||
// works even if tests redefine isNaN.
|
||||
if (actual != actual)
|
||||
{
|
||||
if ( actual_t == "object" )
|
||||
{
|
||||
actual = "NaN object";
|
||||
}
|
||||
else
|
||||
{
|
||||
actual = "NaN number";
|
||||
}
|
||||
}
|
||||
return expected != expected;
|
||||
if (expected != expected)
|
||||
{
|
||||
if ( expected_t == "object" )
|
||||
{
|
||||
expected = "NaN object";
|
||||
}
|
||||
else
|
||||
{
|
||||
expected = "NaN number";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
if (expected_t != actual_t)
|
||||
{
|
||||
passed = false;
|
||||
}
|
||||
else if (expected != actual)
|
||||
{
|
||||
if (expected_t != 'number' || (Math.abs(actual - expected) > 1E-10))
|
||||
{
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
// Tolerate a certain degree of error.
|
||||
if (actual != expected)
|
||||
return Math.abs(actual - expected) <= 1E-10;
|
||||
|
||||
return passed;
|
||||
// Here would be a good place to distinguish 0 and -0, if we wanted
|
||||
// to. However, doing so would introduce a number of failures in
|
||||
// areas where they don't seem important. For example, the WeekDay
|
||||
// function in ECMA-262 returns -0 for Sundays before the epoch, but
|
||||
// the Date functions in SpiderMonkey specified in terms of WeekDay
|
||||
// often don't. This seems unimportant.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeof dump == 'undefined')
|
||||
|
|
Загрузка…
Ссылка в новой задаче