refactor(web): use encoding_rs for text encoding (#10844)

This commit removes all JS based text encoding / text decoding. Instead
encoding now happens in Rust via encoding_rs (already in tree). This
implementation retains stream support, but adds the last missing
encodings. We are incredibly close to 100% WPT on text encoding now.

This should reduce our baseline heap by quite a bit.
This commit is contained in:
Luca Casonato 2021-06-05 23:10:07 +02:00 committed by GitHub
parent bb0c90cadb
commit c73ef5fa14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 641 additions and 4705 deletions

View file

@ -177,20 +177,32 @@ declare function atob(s: string): string;
*/
declare function btoa(s: string): string;
declare interface TextDecoderOptions {
fatal?: boolean;
ignoreBOM?: boolean;
}
declare interface TextDecodeOptions {
stream?: boolean;
}
declare class TextDecoder {
constructor(label?: string, options?: TextDecoderOptions);
/** Returns encoding's name, lowercased. */
readonly encoding: string;
/** Returns `true` if error mode is "fatal", and `false` otherwise. */
readonly fatal: boolean;
/** Returns `true` if ignore BOM flag is set, and `false` otherwise. */
readonly ignoreBOM = false;
constructor(
label?: string,
options?: { fatal?: boolean; ignoreBOM?: boolean },
);
/** Returns the result of running encoding's decoder. */
decode(input?: BufferSource, options?: { stream?: boolean }): string;
readonly [Symbol.toStringTag]: string;
decode(input?: BufferSource, options?: TextDecodeOptions): string;
}
declare interface TextEncoderEncodeIntoResult {
read: number;
written: number;
}
declare class TextEncoder {
@ -198,11 +210,7 @@ declare class TextEncoder {
readonly encoding = "utf-8";
/** Returns the result of running UTF-8's encoder. */
encode(input?: string): Uint8Array;
encodeInto(
input: string,
dest: Uint8Array,
): { read: number; written: number };
readonly [Symbol.toStringTag]: string;
encodeInto(input: string, dest: Uint8Array): TextEncoderEncodeIntoResult;
}
/** A controller object that allows you to abort one or more DOM requests as and