1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-10 16:11:13 -05:00

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".
This commit is contained in:
Thiago de Arruda Padilha 2021-04-11 08:47:06 -03:00 committed by GitHub
parent 29eca72fea
commit c0b6e09172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)) {