summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/string_decoder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/string_decoder.ts')
-rw-r--r--ext/node/polyfills/string_decoder.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/node/polyfills/string_decoder.ts b/ext/node/polyfills/string_decoder.ts
index 4a49c2e3e..19aff8124 100644
--- a/ext/node/polyfills/string_decoder.ts
+++ b/ext/node/polyfills/string_decoder.ts
@@ -39,10 +39,15 @@ const {
Symbol,
MathMin,
DataViewPrototypeGetBuffer,
+ DataViewPrototypeGetByteLength,
+ DataViewPrototypeGetByteOffset,
ObjectPrototypeIsPrototypeOf,
String,
TypedArrayPrototypeGetBuffer,
+ TypedArrayPrototypeGetByteLength,
+ TypedArrayPrototypeGetByteOffset,
StringPrototypeToLowerCase,
+ Uint8Array,
} = primordials;
const { isTypedArray } = core;
@@ -83,11 +88,21 @@ function normalizeBuffer(buf: Buffer) {
}
if (isBufferType(buf)) {
return buf;
+ } else if (isTypedArray(buf)) {
+ return Buffer.from(
+ new Uint8Array(
+ TypedArrayPrototypeGetBuffer(buf),
+ TypedArrayPrototypeGetByteOffset(buf),
+ TypedArrayPrototypeGetByteLength(buf),
+ ),
+ );
} else {
return Buffer.from(
- isTypedArray(buf)
- ? TypedArrayPrototypeGetBuffer(buf)
- : DataViewPrototypeGetBuffer(buf),
+ new Uint8Array(
+ DataViewPrototypeGetBuffer(buf),
+ DataViewPrototypeGetByteOffset(buf),
+ DataViewPrototypeGetByteLength(buf),
+ ),
);
}
}