diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-03-15 16:29:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 16:29:54 -0400 |
commit | bb642e8c7c9f8ab16540d2e3b1ef6a5543ded91e (patch) | |
tree | 2c93ae4faa665b93e8f10793b1edf54362581a5b /js/text_encoding.ts | |
parent | b2f15cf21ae7b08986468dd8d18b06f9c2e97dc2 (diff) |
Fix TextDecoder for SharedArrayBuffer backed TypedArray (#1940)
Diffstat (limited to 'js/text_encoding.ts')
-rw-r--r-- | js/text_encoding.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/js/text_encoding.ts b/js/text_encoding.ts index d0e08f73b..364a0f020 100644 --- a/js/text_encoding.ts +++ b/js/text_encoding.ts @@ -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 { |