From 2d21b7a6d5df0894ac613b84a6036896f4538e9c Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Tue, 22 Sep 2009 14:35:14 -0700 Subject: [PATCH] Adjust the assertEq replacement function in JS tests not run in the shell to use same-value semantics. No bug, driveby fix, r=samantha the wonder dog --- js/tests/shell.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/js/tests/shell.js b/js/tests/shell.js index fadbe9ebc62..fb4d25f8821 100644 --- a/js/tests/shell.js +++ b/js/tests/shell.js @@ -274,18 +274,31 @@ function escapeString (str) } /* - * assertEq(actual, expected) - * Throw if the two arguments are not === - * see https://bugzilla.mozilla.org/show_bug.cgi?id=480199 + * assertEq(actual, expected [, message]) + * Throw if the two arguments are not the same. The sameness of two values + * is determined as follows. If both values are zero, they are the same iff + * their signs are the same. Otherwise, if both values are NaN, they are the + * same. Otherwise, they are the same if they compare equal using ===. + * see https://bugzilla.mozilla.org/show_bug.cgi?id=480199 and + * https://bugzilla.mozilla.org/show_bug.cgi?id=515285 */ if (typeof assertEq == 'undefined') { var assertEq = - function (actual, expected) + function (actual, expected, message) { - if (actual !== expected) + function SameValue(v1, v2) { - throw new TypeError('Assertion failed: got "' + actual + '", expected "' + expected); + if (v1 === 0 && v2 === 0) + return 1 / v1 === 1 / v2; + if (v1 !== v1 && v2 !== v2) + return true; + return v1 === v2; + } + if (!SameValue(actual, expected)) + { + throw new TypeError('Assertion failed: got "' + actual + '", expected "' + expected + + (message ? ": " + message : "")); } }; }