Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ function utf16leSlice (buf, start, end) {
return res
}

let subarrayCallsChild = false

Buffer.prototype.slice = function slice (start, end) {
const len = this.length
start = ~~start
Expand All @@ -1139,8 +1141,11 @@ Buffer.prototype.slice = function slice (start, end) {
if (end < start) end = start

const newBuf = this.subarray(start, end)
// Return an augmented `Uint8Array` instance
Object.setPrototypeOf(newBuf, Buffer.prototype)

if (!subarrayCallsChild) {
// Return an augmented `Uint8Array` instance
Object.setPrototypeOf(newBuf, Buffer.prototype)
}

return newBuf
}
Expand Down Expand Up @@ -2152,3 +2157,7 @@ function defineBigIntMethod (fn) {
function BufferBigIntNotDefined () {
throw new Error('BigInt not supported')
}

if (Buffer.TYPED_ARRAY_SUPPORT) {
subarrayCallsChild = createBuffer(1).subarray(0, 1) instanceof Buffer
}