Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: fix deepEqual RangeError: Maximum call stack size exceeded #13318

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ function _deepEqual(actual, expected, strict, memos) {

const actualPosition = memos.actual.map.get(actual);
if (actualPosition !== undefined) {
if (actualPosition === memos.expected.map.get(expected)) {
return true;
}
return actualPosition === memos.expected.map.get(expected);
Copy link
Member

@joyeecheung joyeecheung May 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the failed test case is caused by memos.expected.map.get(expected) returning undefined? To make sure the two are visited in the same order, we need to first make sure expected has actually been visited before, so this should not return false when expected has not been visited (memos.expected.map.get(expected) === undefined).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the point. I tried it and indeed, it makes the case pass. However, at first, it breaks (or changes expectations of the) test added by the PR from "throws" to "not throws", which is probably not a bad thing, but rather a point that requires some discussion. Secondly, I was able to create a case that still fails:

var a = [ 1, 2 ]
var b = [ 3, 4 ]
var c = [ 1, 2 ]
var d = [ 3, 4 ]

assertDeepAndStrictEqual({
  v: a,
  s: new Set([a, b])
}, {
  v: c,
  s: new Set([d, c])
});

} else {
memos.actual.map.set(actual, memos.actual.position++);
}
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@ a.throws(makeBlock(thrower, TypeError), function(err) {

a.throws(makeBlock(a.deepEqual, d, e), /AssertionError/);
a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/);

// https://github.com/nodejs/node/issues/13314
const f = {};
f.ref = f;

const g = {};
g.ref = g;

const h = {ref: g};

a.throws(makeBlock(a.deepEqual, f, h), /AssertionError/);
a.throws(makeBlock(a.deepStrictEqual, f, h), /AssertionError/);
}
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
const args = (function() { return arguments; })();
Expand Down