assert: Ensure reflexivity of deepEqual
authorMike Pennisi <mike@mikepennisi.com>
Mon, 24 Feb 2014 19:16:40 +0000 (14:16 -0500)
committerFedor Indutny <fedor.indutny@gmail.com>
Tue, 25 Feb 2014 16:32:49 +0000 (20:32 +0400)
Ensure that the behavior of `assert.deepEqual` does not depend on
argument ordering  when comparing an `arguments` object with a
non-`arguments` object.

lib/assert.js
test/simple/test-assert.js

index 11fef45..52b89ba 100644 (file)
@@ -199,10 +199,11 @@ function objEquiv(a, b) {
   if (a.prototype !== b.prototype) return false;
   //~~~I've managed to break Object.keys through screwy arguments passing.
   //   Converting to array solves the problem.
-  if (isArguments(a)) {
-    if (!isArguments(b)) {
-      return false;
-    }
+  var aIsArgs = isArguments(a),
+      bIsArgs = isArguments(b);
+  if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
+    return false;
+  if (aIsArgs) {
     a = pSlice.call(a);
     b = pSlice.call(b);
     return _deepEqual(a, b);
index 2885858..6b83500 100644 (file)
@@ -249,6 +249,11 @@ try {
   gotError = true;
 }
 
+// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
+var args = (function() { return arguments; })();
+a.throws(makeBlock(a.deepEqual, [], args));
+a.throws(makeBlock(a.deepEqual, args, []));
+
 console.log('All OK');
 assert.ok(gotError);