// Can typed array instances can be augmented?
try {
var arr = new Uint8Array(1)
- arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
+ var proto = { foo: function () { return 42 } }
+ Object.setPrototypeOf(proto, Uint8Array.prototype)
+ Object.setPrototypeOf(arr, proto)
return arr.foo() === 42
} catch (e) {
return false
}
// Return an augmented `Uint8Array` instance
var buf = new Uint8Array(length)
- buf.__proto__ = Buffer.prototype
+ Object.setPrototypeOf(buf, Buffer.prototype)
return buf
}
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
// https://github.com/feross/buffer/pull/148
-Buffer.prototype.__proto__ = Uint8Array.prototype
-Buffer.__proto__ = Uint8Array
+Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
+Object.setPrototypeOf(Buffer, Uint8Array)
function assertSize (size) {
if (typeof size !== 'number') {
}
// Return an augmented `Uint8Array` instance
- buf.__proto__ = Buffer.prototype
+ Object.setPrototypeOf(buf, Buffer.prototype)
+
return buf
}
var newBuf = this.subarray(start, end)
// Return an augmented `Uint8Array` instance
- newBuf.__proto__ = Buffer.prototype
+ Object.setPrototypeOf(newBuf, Buffer.prototype)
+
return newBuf
}