Skip to content

Commit b445655

Browse files
committed
Avoid augmenting subarrays post-ES2016
1 parent 54885d4 commit b445655

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ function utf16leSlice (buf, start, end) {
11171117
return res
11181118
}
11191119

1120+
let subarrayCallsChild = false;
1121+
11201122
Buffer.prototype.slice = function slice (start, end) {
11211123
const len = this.length
11221124
start = ~~start
@@ -1139,8 +1141,11 @@ Buffer.prototype.slice = function slice (start, end) {
11391141
if (end < start) end = start
11401142

11411143
const newBuf = this.subarray(start, end)
1142-
// Return an augmented `Uint8Array` instance
1143-
Object.setPrototypeOf(newBuf, Buffer.prototype)
1144+
1145+
if (!subarrayCallsChild) {
1146+
// Return an augmented `Uint8Array` instance
1147+
Object.setPrototypeOf(newBuf, Buffer.prototype)
1148+
}
11441149

11451150
return newBuf
11461151
}
@@ -2152,3 +2157,7 @@ function defineBigIntMethod (fn) {
21522157
function BufferBigIntNotDefined () {
21532158
throw new Error('BigInt not supported')
21542159
}
2160+
2161+
if (Buffer.TYPED_ARRAY_SUPPORT) {
2162+
subarrayCallsChild = createBuffer(1).subarray(0, 1) instanceof Buffer
2163+
}

0 commit comments

Comments
 (0)