)
}
- if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
+ if (isInstance(value, ArrayBuffer) ||
+ (value && isInstance(value.buffer, ArrayBuffer))) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (Buffer.isBuffer(string)) {
return string.length
}
- if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
return i
}
-// ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
-// but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
-function isArrayBuffer (obj) {
- return obj instanceof ArrayBuffer ||
- (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
- typeof obj.byteLength === 'number')
+// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
+// the `instanceof` check but they should be treated as of that type.
+// See: https://github.com/feross/buffer/issues/166
+function isInstance (obj, type) {
+ return obj instanceof type ||
+ (obj != null && obj.constructor != null && obj.constructor.name === type.name)
}
function numberIsNaN (obj) {