From ae6abd7a9e7fcce64f7b8d8f4c5ea46b8747e251 Mon Sep 17 00:00:00 2001 From: teppeis Date: Sun, 21 Dec 2014 19:08:23 +0900 Subject: [PATCH] ensure that deepEqual does not depend on arguments order from https://github.com/joyent/node/commit/aae51ecf7d407b2fb56c1f3e1edf91a16940c973 --- assert.js | 9 +++++---- test.js | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/assert.js b/assert.js index 6d15eb3..08d2ca2 100644 --- a/assert.js +++ b/assert.js @@ -227,10 +227,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.js b/test.js index 3151a93..a6200d3 100644 --- a/test.js +++ b/test.js @@ -264,6 +264,11 @@ test('assert - Make sure deepEqual doesn\'t loop forever on circular refs', func assert.ok(gotError); }); +test('assert - Ensure reflexivity of deepEqual with `arguments` objects', function() { + var args = (function() { return arguments; })(); + assert.throws(makeBlock(assert.deepEqual, [], args), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, args, []), assert.AssertionError); +}); test('assert - test assertion message', function () { function testAssertionMessage(actual, expected) {