fix(op_crates/web): TextEncoder should throw RangeError (#8039)

This commit changes error type thrown by TextEncoder, when
provided encoding is not supported matching Chromium behavior.
This commit is contained in:
Leonard Ginters 2020-10-19 23:56:29 +02:00 committed by GitHub
parent 1474d5d76d
commit 623ac9e6df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -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();