Skip to content

Commit 67d1e18

Browse files
committed
Test for Buffer in isUint8Array if no Symbol.toStringTag support
Otherwise we can't detect buffers. However this also means we'll incorrectly detect fake buffers, so skip the fake buffer test.
1 parent 4614928 commit 67d1e18

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

support/types.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
'use strict';
55

6+
var isBuffer = require('./isBuffer');
7+
68
var isArgumentsObject = require('is-arguments');
79
var isGeneratorFunction = require('is-generator-function');
810
var isPromise = require('is-promise');
@@ -96,7 +98,10 @@ function isUint8Array(value) {
9698
if (Uint8ArraySupported && SymbolToStringTagSupported) {
9799
return TypedArrayProto_toStringTag(value) === 'Uint8Array';
98100
} else {
99-
return ObjectToString(value) === '[object Uint8Array]';
101+
return (
102+
ObjectToString(value) === '[object Uint8Array]' ||
103+
isBuffer(value)
104+
);
100105
}
101106
}
102107
exports.isUint8Array = isUint8Array;

test/node/types.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ if (SymbolToStringTagSupported) {
182182
var bigInt64Array = function bigInt64Array() { return new BigInt64Array(arrayBuffer()); };
183183
var bigUint64Array = function bigUint64Array() { return new BigUint64Array(arrayBuffer()); };
184184

185-
var fakeBuffer = function fakeBuffer() { return Object.create(Buffer.prototype); };
185+
var fakeBuffer = function fakeBuffer() {
186+
if (!SymbolToStringTagSupported) {
187+
throw new Error();
188+
}
189+
return Object.create(Buffer.prototype);
190+
};
186191
var fakeDataView = function fakeDataView() { return Object.create(DataView.prototype); };
187192
var fakeUint8Array = function fakeUint8Array() { return Object.create(Uint8Array.prototype); };
188193
var fakeUint8ClampedArray = function fakeUint8ClampedArray() { return Object.create(Uint8ClampedArray.prototype); };

0 commit comments

Comments
 (0)