Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e488763

Browse filesBrowse files
committed
[Fix] in node 0.8, TAs do not coerce Uint8Arrays to an ArrayBuffer properly
1 parent 8eebfa2 commit e488763
Copy full SHA for e488763

File tree

3 files changed

+16
-2
lines changed
Filter options

3 files changed

+16
-2
lines changed

‎index.js

Copy file name to clipboardExpand all lines: index.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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');
67

78
var $ArrayBuffer = GetIntrinsic('ArrayBuffer', true);
89
var $Float32Array = GetIntrinsic('Float32Array', true);
@@ -32,7 +33,7 @@ module.exports = $byteLength || $abSlice
3233
// in node 0.8, ArrayBuffers have no prototype or own methods
3334
? function IsArrayBuffer(obj) {
3435
try {
35-
return (new $Float32Array(obj)).buffer === obj;
36+
return (new $Float32Array(obj)).buffer === obj && !isTypedArray(obj);
3637
} catch (e) {
3738
return false;
3839
}

‎package.json

Copy file name to clipboardExpand all lines: package.json
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@ljharb/eslint-config": "^21.0.1",
4646
"aud": "^2.0.2",
4747
"auto-changelog": "^2.4.0",
48+
"available-typed-arrays": "^1.0.5",
4849
"es-value-fixtures": "^1.4.2",
4950
"eslint": "=8.8.0",
5051
"for-each": "^0.3.3",
@@ -66,7 +67,8 @@
6667
},
6768
"dependencies": {
6869
"call-bind": "^1.0.2",
69-
"get-intrinsic": "^1.1.3"
70+
"get-intrinsic": "^1.1.3",
71+
"is-typed-array": "^1.1.10"
7072
},
7173
"publishConfig": {
7274
"ignore": [

‎test/index.js

Copy file name to clipboardExpand all lines: test/index.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var test = require('tape');
44
var inspect = require('object-inspect');
55
var forEach = require('for-each');
66
var v = require('es-value-fixtures');
7+
var availableTypedArrays = require('available-typed-arrays')();
78

89
var isArrayBuffer = require('..');
910

@@ -26,5 +27,15 @@ test('isArrayBuffer', function (t) {
2627
st.end();
2728
});
2829

30+
t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
31+
forEach(availableTypedArrays, function (TypedArray) {
32+
var ta = new global[TypedArray](0);
33+
st.equal(isArrayBuffer(ta.buffer), true, inspect(ta.buffer) + ', the TA\'s buffer, is an ArrayBuffer');
34+
st.equal(isArrayBuffer(ta), false, inspect(ta) + ' is not an ArrayBuffer');
35+
});
36+
37+
st.end();
38+
});
39+
2940
t.end();
3041
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.