Skip to content

Commit

Permalink
[Refactor] use is-array-buffer package
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 5, 2023
1 parent df3e3c4 commit 0360ee1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"no-magic-numbers": [2, { "ignore": [0, 1] }],
},

"globals": {
"Int8Array": false,
"Uint8Array": false,
},

"overrides": [
{
"files": "example/**",
Expand Down
17 changes: 3 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@ var getIterator = require('es-get-iterator');
var getSideChannel = require('side-channel');
var whichTypedArray = require('which-typed-array');
var assign = require('object.assign');
var isArrayBuffer = require('is-array-buffer');

// TODO: use extracted package
var byteLength = callBound('ArrayBuffer.prototype.byteLength', true);
function isArrayBuffer(buffer) {
if (!buffer || typeof buffer !== 'object' || !byteLength) {
return false;
}
try {
byteLength(buffer);
return true;
} catch (e) {
return false;
}
}
var byteLength = callBound('%ArrayBuffer.prototype.byteLength%', true)
|| function byteLength(ab) { return ab.byteLength; }; // in node < 0.11, byteLength is an own nonconfigurable property

var $getTime = callBound('Date.prototype.getTime');
var gPO = Object.getPrototypeOf;
Expand Down Expand Up @@ -342,7 +332,6 @@ function objEquiv(a, b, opts, channel) {
if (aIsArrayBuffer !== bIsArrayBuffer) { return false; }
if (aIsArrayBuffer || bIsArrayBuffer) { // && would work too, because both are true or both false here
if (byteLength(a) !== byteLength(b)) { return false; }
/* global Uint8Array */
return typeof Uint8Array === 'function' && internalDeepEqual(new Uint8Array(a), new Uint8Array(b), opts, channel);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"es-get-iterator": "^1.1.2",
"get-intrinsic": "^1.1.3",
"is-arguments": "^1.1.1",
"is-array-buffer": "^3.0.1",
"is-date-object": "^1.0.5",
"is-regex": "^1.1.4",
"isarray": "^2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion test/cmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ test('TypedArrays', { skip: !hasTypedArrays }, function (t) {
});

t.test('one TypedArray faking as another', { skip: !hasDunderProto }, function (st) {
/* globals Uint8Array, Int8Array */
var a = new Uint8Array(10);
var b = tag(new Int8Array(10), 'Uint8Array');
b.__proto__ = Uint8Array.prototype; // eslint-disable-line no-proto
Expand Down Expand Up @@ -1218,6 +1217,7 @@ test('TypedArrays', { skip: !hasTypedArrays }, function (t) {
false
);

// node < 0.11 has a nonconfigurable own byteLength property
t.test('lies about byteLength', { skip: !('byteLength' in ArrayBuffer.prototype) }, function (s2t) {
var empty4 = new ArrayBuffer(4);
var empty6 = new ArrayBuffer(6);
Expand Down

0 comments on commit 0360ee1

Please sign in to comment.