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 <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>
  • Loading branch information
feross authored and MylesBorins committed Dec 21, 2016
1 parent 2bce891 commit ee931cd
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 ee931cd

Please sign in to comment.