summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/text_encoding.ts6
-rw-r--r--js/text_encoding_test.ts8
2 files changed, 14 insertions, 0 deletions
diff --git a/js/text_encoding.ts b/js/text_encoding.ts
index 364a0f020..a9d0d74b1 100644
--- a/js/text_encoding.ts
+++ b/js/text_encoding.ts
@@ -442,6 +442,9 @@ export class TextDecoder {
return codePointsToString(output);
}
+ get [Symbol.toStringTag]() {
+ return "TextDecoder";
+ }
}
export class TextEncoder {
@@ -467,4 +470,7 @@ export class TextEncoder {
return new Uint8Array(output);
}
+ get [Symbol.toStringTag]() {
+ return "TextEncoder";
+ }
}
diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts
index 0799b1c3e..d33537b4f 100644
--- a/js/text_encoding_test.ts
+++ b/js/text_encoding_test.ts
@@ -91,3 +91,11 @@ test(function textDecoderSharedInt32Array() {
const actual = decoder.decode(i32);
assertEquals(actual, "ABCDEFGH");
});
+
+test(function toStringShouldBeWebCompatibility() {
+ const encoder = new TextEncoder();
+ assertEquals(encoder.toString(), "[object TextEncoder]");
+
+ const decoder = new TextDecoder();
+ assertEquals(decoder.toString(), "[object TextDecoder]");
+});