Skip to content

Commit 69a03f6

Browse files
committed
[Fix] TAs can take a DataView in node 0.8; use a simpler check
1 parent 0852be6 commit 69a03f6

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
"extends": "@ljharb",
55

6+
"globals": {
7+
"DataView": false,
8+
},
9+
610
"rules": {
711
"new-cap": ["error", {
812
"capIsNewExceptions": [

index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
var callBind = require('call-bind');
44
var callBound = require('call-bind/callBound');
55
var GetIntrinsic = require('get-intrinsic');
6-
var isTypedArray = require('is-typed-array');
76

87
var $ArrayBuffer = GetIntrinsic('ArrayBuffer', true);
9-
var $Float32Array = GetIntrinsic('Float32Array', true);
108
var $byteLength = callBound('ArrayBuffer.prototype.byteLength', true);
9+
var $toString = callBound('Object.prototype.toString');
1110

1211
// in node 0.10, ArrayBuffers have no prototype methods, but have an own slot-checking `slice` method
1312
var abSlice = $ArrayBuffer && !$byteLength && new $ArrayBuffer().slice;
@@ -29,14 +28,10 @@ module.exports = $byteLength || $abSlice
2928
return false;
3029
}
3130
}
32-
: $Float32Array
33-
// in node 0.8, ArrayBuffers have no prototype or own methods
31+
: $ArrayBuffer
32+
// in node 0.8, ArrayBuffers have no prototype or own methods, but also no Symbol.toStringTag
3433
? function IsArrayBuffer(obj) {
35-
try {
36-
return (new $Float32Array(obj)).buffer === obj && !isTypedArray(obj);
37-
} catch (e) {
38-
return typeof obj === 'object' && e.name === 'RangeError';
39-
}
34+
return $toString(obj) === '[object ArrayBuffer]';
4035
}
4136
: function isArrayBuffer(obj) { // eslint-disable-line no-unused-vars
4237
return false;

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@
6666
"startingVersion": "2.0.1"
6767
},
6868
"dependencies": {
69-
"call-bind": "^1.0.5",
70-
"get-intrinsic": "^1.2.2",
71-
"is-typed-array": "^1.1.13"
69+
"call-bind": "^1.0.2",
70+
"get-intrinsic": "^1.2.1"
7271
},
7372
"publishConfig": {
7473
"ignore": [

test/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ test('isArrayBuffer', function (t) {
2626
var ab42 = new ArrayBuffer(42);
2727
st.equal(isArrayBuffer(ab42), true, inspect(ab42) + ' is an ArrayBuffer');
2828

29+
var dv = new DataView(ab42);
30+
st.equal(isArrayBuffer(dv), false, inspect(dv) + ' is not an ArrayBuffer');
31+
2932
st.end();
3033
});
3134

0 commit comments

Comments
 (0)