throw new TypeError('"value" argument must not be a number')
}
- if (value instanceof ArrayBuffer) {
+ if (isArrayBuffer(value)) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (Buffer.isBuffer(string)) {
return string.length
}
- if (isArrayBufferView(string) || string instanceof ArrayBuffer) {
+ if (isArrayBufferView(string) || isArrayBuffer(string)) {
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')
+}
+
// Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
function isArrayBufferView (obj) {
return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj)