Skip to content

Commit 387ab62

Browse files
ferossjasnell
authored andcommitted
assert: fix deepEqual/deepStrictEqual on equivalent typed arrays
The typed array's underlying ArrayBuffer is used in `Buffer.from`. Let's respect it's .byteOffset or .byteLength (i.e. position within the parent ArrayBuffer). Fixes: #8001 PR-URL: #8002 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent bb3b4d7 commit 387ab62

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/assert.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ function _deepEqual(actual, expected, strict, memos) {
180180
pToString(actual) === pToString(expected) &&
181181
!(actual instanceof Float32Array ||
182182
actual instanceof Float64Array)) {
183-
return compare(Buffer.from(actual.buffer),
184-
Buffer.from(expected.buffer)) === 0;
183+
return compare(Buffer.from(actual.buffer,
184+
actual.byteOffset,
185+
actual.byteLength),
186+
Buffer.from(expected.buffer,
187+
expected.byteOffset,
188+
expected.byteLength)) === 0;
185189

186190
// 7.5 For all other Object pairs, including Array objects, equivalence is
187191
// determined by having the same number of owned properties (as verified

0 commit comments

Comments
 (0)