From c0b6e09172f242e98a5bc82bd6f5dc20f705c8a2 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Padilha Date: Sun, 11 Apr 2021 08:47:06 -0300 Subject: [PATCH] refactor(op_crates/web): remove unused code path in TextEncoder (#10104) According to https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder, TextEncoder should ignore the "encoding" parameter and always use "utf-8". --- op_crates/web/08_text_encoding.js | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js index 1fda1a8167ffa8..980de339cae749 100644 --- a/op_crates/web/08_text_encoding.js +++ b/op_crates/web/08_text_encoding.js @@ -4212,25 +4212,8 @@ class TextEncoder { encoding = "utf-8"; encode(input = "") { - input = String(input); // Deno.core.encode() provides very efficient utf-8 encoding - if (this.encoding === "utf-8") { - return core.encode(input); - } - - const encoder = new UTF8Encoder(); - const inputStream = new Stream(stringToCodePoints(input)); - const output = []; - - while (true) { - const result = encoder.handler(inputStream.read()); - if (result === "finished") { - break; - } - output.push(...result); - } - - return new Uint8Array(output); + return core.encode(String(input)); } encodeInto(input, dest) { if (!(dest instanceof Uint8Array)) {