Skip to content
Closed
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
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,7 @@ 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)

return newBuf
return this.subarray(start, end)
}

/*
Expand Down Expand Up @@ -1813,6 +1809,19 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
return this
}

// A number of mobile web views do not seem to implement the
// ES2016 "subarray instantiates child class" behavior. Test
// for this and monkey-patch subarray if need be. Only check
// for this once we're done setting up the Buffer prototype.
// See: https://github.com/feross/buffer/issues/329
if (!(createBuffer(1).subarray(0, 1) instanceof Buffer)) {
Buffer.prototype.subarray = function subarray() {
const buf = Uint8Array.prototype.subarray.apply(this, arguments)
Object.setPrototypeOf(buf, Buffer.prototype)
return buf
}
}

// CUSTOM ERRORS
// =============

Expand Down