1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

Improve new TextDecoder().toString() (#2032)

This commit is contained in:
迷渡 2019-04-02 01:05:19 +08:00 committed by Ryan Dahl
parent ada5ffa610
commit 659acadf77
2 changed files with 14 additions and 0 deletions

View file

@ -442,6 +442,9 @@ export class TextDecoder {
return codePointsToString(output); return codePointsToString(output);
} }
get [Symbol.toStringTag]() {
return "TextDecoder";
}
} }
export class TextEncoder { export class TextEncoder {
@ -467,4 +470,7 @@ export class TextEncoder {
return new Uint8Array(output); return new Uint8Array(output);
} }
get [Symbol.toStringTag]() {
return "TextEncoder";
}
} }

View file

@ -91,3 +91,11 @@ test(function textDecoderSharedInt32Array() {
const actual = decoder.decode(i32); const actual = decoder.decode(i32);
assertEquals(actual, "ABCDEFGH"); assertEquals(actual, "ABCDEFGH");
}); });
test(function toStringShouldBeWebCompatibility() {
const encoder = new TextEncoder();
assertEquals(encoder.toString(), "[object TextEncoder]");
const decoder = new TextDecoder();
assertEquals(decoder.toString(), "[object TextDecoder]");
});