mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
Fix TextDecoder for SharedArrayBuffer backed TypedArray (#1940)
This commit is contained in:
parent
b2f15cf21a
commit
bb642e8c7c
2 changed files with 37 additions and 2 deletions
|
@ -356,6 +356,13 @@ export interface TextDecoderOptions {
|
|||
ignoreBOM?: false;
|
||||
}
|
||||
|
||||
type EitherArrayBuffer = SharedArrayBuffer | ArrayBuffer;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function isEitherArrayBuffer(x: any): x is EitherArrayBuffer {
|
||||
return x instanceof SharedArrayBuffer || x instanceof ArrayBuffer;
|
||||
}
|
||||
|
||||
export class TextDecoder {
|
||||
private _encoding: string;
|
||||
|
||||
|
@ -400,12 +407,14 @@ export class TextDecoder {
|
|||
}
|
||||
|
||||
let bytes: Uint8Array;
|
||||
if (typeof input === "object" && input instanceof ArrayBuffer) {
|
||||
if (input instanceof Uint8Array) {
|
||||
bytes = input;
|
||||
} else if (isEitherArrayBuffer(input)) {
|
||||
bytes = new Uint8Array(input);
|
||||
} else if (
|
||||
typeof input === "object" &&
|
||||
"buffer" in input &&
|
||||
input.buffer instanceof ArrayBuffer
|
||||
isEitherArrayBuffer(input.buffer)
|
||||
) {
|
||||
bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue