Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

text-decoder-polyfill.ts

17 lines632 Bytes

1// Hermes's TextDecoder rejects legacy labels such as GB18030, so GBK source files could not be previewed.
2// Native decoders stay in use; only labels Hermes rejects fall back to a WHATWG-complete decoder.
3import { TextDecoder as SpecTextDecoder } from "@exodus/bytes/encoding.js";
4​
5globalThis.TextDecoder = new Proxy(globalThis.TextDecoder, {
6 construct(NativeTextDecoder, args: ConstructorParameters<typeof TextDecoder>) {
7 try {
8 return new NativeTextDecoder(...args);
9 } catch (nativeError) {
10 try {
11 return new SpecTextDecoder(...args);
12 } catch {
13 throw nativeError;
14 }
15 }
16 },
17});