Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
assert: handle sparse arrays in deepStrictEqual
Browse files Browse the repository at this point in the history
Detect sparse array ends and add a fail early path for
unequal array length.

PR-URL: nodejs/node#15027
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
BridgeAR authored and Olivia Hugger committed Aug 30, 2017
1 parent c83c108 commit 2a3d73f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ function strictDeepEqual(actual, expected) {
if (Object.getPrototypeOf(actual) !== Object.getPrototypeOf(expected)) {
return false;
}
if (isObjectOrArrayTag(actualTag)) {
if (actualTag === '[object Array]') {
// Check for sparse arrays and general fast path
if (actual.length !== expected.length)
return false;
// Skip testing the part below and continue in the callee function.
return;
}
if (actualTag === '[object Object]') {
// Skip testing the part below and continue in the callee function.
return;
}
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,7 @@ assertOnlyDeepEqual(
assertDeepAndStrictEqual(m3, m4);
}

assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);

/* eslint-enable */

0 comments on commit 2a3d73f

Please sign in to comment.