Skip to content

Commit 41546ff

Browse files
ferosscjihrig
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: nodejs#8001 PR-URL: nodejs#8002 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 54c38eb commit 41546ff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/assert.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ function _deepEqual(actual, expected, strict, memos) {
176176
pToString(actual) === pToString(expected) &&
177177
!(actual instanceof Float32Array ||
178178
actual instanceof Float64Array)) {
179-
return compare(new Buffer(actual.buffer),
180-
new Buffer(expected.buffer)) === 0;
179+
return compare(
180+
new Buffer(actual.buffer).slice(actual.byteOffset,
181+
actual.byteOffset +
182+
actual.byteLength),
183+
new Buffer(expected.buffer).slice(expected.byteOffset,
184+
expected.byteOffset +
185+
expected.byteLength)) === 0;
181186

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

0 commit comments

Comments
 (0)