Skip to content

Commit ae6abd7

Browse files
committed
ensure that deepEqual does not depend on arguments order
from nodejs/node-v0.x-archive@aae51ec
1 parent e2cf7f3 commit ae6abd7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

assert.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ function objEquiv(a, b) {
227227
if (a.prototype !== b.prototype) return false;
228228
//~~~I've managed to break Object.keys through screwy arguments passing.
229229
// Converting to array solves the problem.
230-
if (isArguments(a)) {
231-
if (!isArguments(b)) {
232-
return false;
233-
}
230+
var aIsArgs = isArguments(a),
231+
bIsArgs = isArguments(b);
232+
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
233+
return false;
234+
if (aIsArgs) {
234235
a = pSlice.call(a);
235236
b = pSlice.call(b);
236237
return _deepEqual(a, b);

test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ test('assert - Make sure deepEqual doesn\'t loop forever on circular refs', func
264264
assert.ok(gotError);
265265
});
266266

267+
test('assert - Ensure reflexivity of deepEqual with `arguments` objects', function() {
268+
var args = (function() { return arguments; })();
269+
assert.throws(makeBlock(assert.deepEqual, [], args), assert.AssertionError);
270+
assert.throws(makeBlock(assert.deepEqual, args, []), assert.AssertionError);
271+
});
267272

268273
test('assert - test assertion message', function () {
269274
function testAssertionMessage(actual, expected) {

0 commit comments

Comments
 (0)