From c73ef5fa143b473677d4cab069241ff018e0c971 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Sat, 5 Jun 2021 23:10:07 +0200 Subject: 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. --- extensions/web/lib.deno_web.d.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'extensions/web/lib.deno_web.d.ts') diff --git a/extensions/web/lib.deno_web.d.ts b/extensions/web/lib.deno_web.d.ts index 9ede84994..e91534567 100644 --- a/extensions/web/lib.deno_web.d.ts +++ b/extensions/web/lib.deno_web.d.ts @@ -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 -- cgit v1.2.3