summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/text_encoding_test.ts11
-rw-r--r--op_crates/web/08_text_encoding.js2
-rw-r--r--op_crates/web/text_encoding_test.js16
3 files changed, 26 insertions, 3 deletions
diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts
index 23799fba3..6a9274d02 100644
--- a/cli/tests/unit/text_encoding_test.ts
+++ b/cli/tests/unit/text_encoding_test.ts
@@ -112,6 +112,17 @@ unitTest(function textDecoderErrorEncoding(): void {
assert(didThrow);
});
+unitTest(function textDecoderHandlesNotFoundInternalDecoder() {
+ let didThrow = false;
+ try {
+ new TextDecoder("gbk");
+ } catch (e) {
+ didThrow = true;
+ assert(e instanceof RangeError);
+ }
+ assert(didThrow);
+});
+
unitTest(function textEncoder(): void {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js
index f55646e12..5a84ea8a4 100644
--- a/op_crates/web/08_text_encoding.js
+++ b/op_crates/web/08_text_encoding.js
@@ -981,7 +981,7 @@
);
}
if (!decoders.has(encoding) && encoding !== "utf-8") {
- throw new TypeError(`Internal decoder ('${encoding}') not found.`);
+ throw new RangeError(`Internal decoder ('${encoding}') not found.`);
}
this.#encoding = encoding;
}
diff --git a/op_crates/web/text_encoding_test.js b/op_crates/web/text_encoding_test.js
index b51122f90..7f6774ed4 100644
--- a/op_crates/web/text_encoding_test.js
+++ b/op_crates/web/text_encoding_test.js
@@ -171,6 +171,17 @@ function textDecoderErrorEncoding() {
assert(didThrow);
}
+function textDecoderHandlesNotFoundInternalDecoder() {
+ let didThrow = false;
+ try {
+ new TextDecoder("gbk");
+ } catch (e) {
+ didThrow = true;
+ assert(e instanceof RangeError);
+ }
+ assert(didThrow);
+}
+
function textDecoderHandlesUndefined() {
const fixture = undefined;
const decoder = new TextDecoder();
@@ -948,8 +959,8 @@ function singleByteEncodings() {
9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508,
9516, 9524, 9532, 9600, 9604, 9608, 9612, 9616,
9617, 9618, 9619, 8992, 9632, 8729, 8730, 8776,
- 8804, 8805, 160, 8993, 176, 178, 183, 247,
- 9552, 9553, 9554, 1105, 9555, 9556, 9557, 9558,
+ 8804, 8805, 160, 8993, 176, 178, 183, 247,
+ 9552, 9553, 9554, 1105, 9555, 9556, 9557, 9558,
9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566,
9567, 9568, 9569, 1025, 9570, 9571, 9572, 9573,
9574, 9575, 9576, 9577, 9578, 9579, 9580, 169,
@@ -1256,6 +1267,7 @@ function main() {
textDecoderSharedInt32Array();
toStringShouldBeWebCompatibility();
singleByteEncodings();
+ textDecoderHandlesNotFoundInternalDecoder();
}
main();