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: https://github.com/nodejs/node/issues/8001
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Feross Aboukhadijeh 2016-08-06 16:29:02 -07:00 committed by James M Snell
parent bb3b4d7d49
commit 387ab62939

View File

@ -180,8 +180,12 @@ function _deepEqual(actual, expected, strict, memos) {
pToString(actual) === pToString(expected) &&
!(actual instanceof Float32Array ||
actual instanceof Float64Array)) {
return compare(Buffer.from(actual.buffer),
Buffer.from(expected.buffer)) === 0;
return compare(Buffer.from(actual.buffer,
actual.byteOffset,
actual.byteLength),
Buffer.from(expected.buffer,
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