Skip to content

Commit

Permalink
refactor(op_crates/web): remove unused code path in TextEncoder (deno…
Browse files Browse the repository at this point in the history
…land#10104)

According to
https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder,
TextEncoder should ignore the "encoding" parameter and always use
"utf-8".
  • Loading branch information
tarruda committed Apr 11, 2021
1 parent 29eca72 commit c0b6e09
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions op_crates/web/08_text_encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit c0b6e09

Please sign in to comment.