From aae51ecf7d407b2fb56c1f3e1edf91a16940c973 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Mon, 24 Feb 2014 14:16:40 -0500 Subject: [PATCH] assert: Ensure reflexivity of deepEqual 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 | 9 +++++---- test/simple/test-assert.js | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 11fef455ab..52b89baef6 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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); diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js index 2885858cf4..6b8350095d 100644 --- a/test/simple/test-assert.js +++ b/test/simple/test-assert.js @@ -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);