mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -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:
parent
29eca72fea
commit
c0b6e09172
1 changed files with 1 additions and 18 deletions
|
@ -4212,25 +4212,8 @@
|
||||||
class TextEncoder {
|
class TextEncoder {
|
||||||
encoding = "utf-8";
|
encoding = "utf-8";
|
||||||
encode(input = "") {
|
encode(input = "") {
|
||||||
input = String(input);
|
|
||||||
// Deno.core.encode() provides very efficient utf-8 encoding
|
// Deno.core.encode() provides very efficient utf-8 encoding
|
||||||
if (this.encoding === "utf-8") {
|
return core.encode(String(input));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
encodeInto(input, dest) {
|
encodeInto(input, dest) {
|
||||||
if (!(dest instanceof Uint8Array)) {
|
if (!(dest instanceof Uint8Array)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue