Permalink
Browse files

assert: handle sparse arrays in deepStrictEqual

Detect sparse array ends and add a fail early path for
unequal array length.

PR-URL: #15027
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information...
BridgeAR authored and MylesBorins committed Aug 19, 2017
1 parent b293b5a commit ff891d44094053d4e2ab974d29c60d5a412f7cf8
Showing with 11 additions and 1 deletion.
  1. +8 −1 lib/assert.js
  2. +3 −0 test/parallel/test-assert-deep.js
View
@@ -178,7 +178,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;
}
@@ -404,4 +404,7 @@ assertOnlyDeepEqual(
assertDeepAndStrictEqual(m3, m4);
}
assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
/* eslint-enable */

0 comments on commit ff891d4

Please sign in to comment.