assert: handle sparse arrays in deepStrictEqual
Detect sparse array ends and add a fail early path for unequal array length. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
7854562143
commit
4381100371
@ -180,7 +180,14 @@ function strictDeepEqual(actual, expected) {
|
|||||||
if (Object.getPrototypeOf(actual) !== Object.getPrototypeOf(expected)) {
|
if (Object.getPrototypeOf(actual) !== Object.getPrototypeOf(expected)) {
|
||||||
return false;
|
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.
|
// Skip testing the part below and continue in the callee function.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -466,4 +466,7 @@ assertOnlyDeepEqual(
|
|||||||
assertDeepAndStrictEqual(m3, m4);
|
assertDeepAndStrictEqual(m3, m4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
|
||||||
|
assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
|
||||||
|
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user