diff options
author | rmdm <rmdm@users.noreply.github.com> | 2017-05-30 23:44:34 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-06-01 20:48:59 -0700 |
commit | b1ed55f259b075c43198404113a07dc55ca3983d (patch) | |
tree | 6ca730fd7d206d3db011a3250cc452782fdc3656 /lib/assert.js | |
parent | 592d7d2f2a153edabee8a60dbcc1c7c6fce45463 (diff) | |
download | android-node-v8-b1ed55f259b075c43198404113a07dc55ca3983d.tar.gz android-node-v8-b1ed55f259b075c43198404113a07dc55ca3983d.tar.bz2 android-node-v8-b1ed55f259b075c43198404113a07dc55ca3983d.zip |
assert: fix deepEqual RangeError: Maximum call stack size exceeded
Fixes: https://github.com/nodejs/node/issues/13314
Refs: https://github.com/nodejs/node/issues/6416
This commit changes semantics of the memos cycles tracker. Before
the change it was used to track all currently wisited nodes of an
object tree, which is a bit shifted from its original intention of
tracking cycles. The change brings intended semantics, by tracking
only objects of the current branch of the object tree.
PR-URL: https://github.com/nodejs/node/pull/13318
Fixes: https://github.com/nodejs/node/issues/13314
Ref: https://github.com/nodejs/node/issues/6416
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'lib/assert.js')
-rw-r--r-- | lib/assert.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/assert.js b/lib/assert.js index 0f0f3f165a..5aca511194 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -262,24 +262,27 @@ function _deepEqual(actual, expected, strict, memos) { // Use memos to handle cycles. if (!memos) { memos = { - actual: { map: new Map(), position: 0 }, - expected: { map: new Map(), position: 0 } + actual: new Map(), + expected: new Map(), + position: 0 }; - } - - const actualPosition = memos.actual.map.get(actual); - if (actualPosition !== undefined) { - if (actualPosition === memos.expected.map.get(expected)) { - return true; - } } else { - memos.actual.map.set(actual, memos.actual.position++); + memos.position++; } - if (!memos.expected.map.has(expected)) { - memos.expected.map.set(expected, memos.expected.position++); + + if (memos.actual.has(actual)) { + return memos.actual.get(actual) === memos.expected.get(expected); } - return objEquiv(actual, expected, strict, memos); + memos.actual.set(actual, memos.position); + memos.expected.set(expected, memos.position); + + const areEq = objEquiv(actual, expected, strict, memos); + + memos.actual.delete(actual); + memos.expected.delete(expected); + + return areEq; } function setHasSimilarElement(set, val1, strict, memo) { |