Add support for comparing array buffers to _.isEqual.

This commit is contained in:
John-David Dalton
2015-12-23 18:18:12 -06:00
parent 5e639d1704
commit 1c781389d2
2 changed files with 26 additions and 0 deletions

View File

@@ -4512,6 +4512,13 @@
*/
function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
switch (tag) {
case arrayBufferTag:
if ((object.byteLength != other.byteLength) ||
!equalFunc(new Uint8Array(object), new Uint8Array(other))) {
return false;
}
return true;
case boolTag:
case dateTag:
// Coerce dates and booleans to numbers, dates to milliseconds and booleans

View File

@@ -8024,6 +8024,25 @@
assert.strictEqual(_.isEqual(new Foo, args), false);
});
QUnit.test('should compare array buffers', function(assert) {
assert.expect(2);
if (ArrayBuffer) {
var buffer1 = new ArrayBuffer(4),
buffer2 = new ArrayBuffer(8);
assert.strictEqual(_.isEqual(buffer1, buffer2), false);
buffer1 = new Int8Array([-1]).buffer;
buffer2 = new Uint8Array([255]).buffer;
assert.strictEqual(_.isEqual(buffer1, buffer2), true);
}
else {
skipTest(assert, 2);
}
});
QUnit.test('should compare date objects', function(assert) {
assert.expect(4);