Skip to content

Commit

Permalink
assert: fix deepEqual/deepStrictEqual on equivalent typed arrays
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
feross authored and MylesBorins committed Dec 13, 2016
1 parent 76245b2 commit c5f82b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ function _deepEqual(actual, expected, strict, memos) {
pToString(actual) === pToString(expected) &&
!(actual instanceof Float32Array ||
actual instanceof Float64Array)) {
return compare(new Buffer(actual.buffer),
new Buffer(expected.buffer)) === 0;
return compare(
new Buffer(actual.buffer).slice(actual.byteOffset,
actual.byteOffset +
actual.byteLength),
new Buffer(expected.buffer).slice(expected.byteOffset,
expected.byteOffset +
expected.byteLength)) === 0;

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

0 comments on commit c5f82b8

Please sign in to comment.