fix(op_crates/web): throw TypeError on invalid input types in TextDecoder.decode() (#7179)

This commit is contained in:
Craig Morten 2020-08-24 19:09:31 +01:00 committed by GitHub
parent 545ea8e217
commit 2d800f2cb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 2 deletions

View file

@ -131,6 +131,44 @@ function textDecoderErrorEncoding() {
assert(didThrow);
}
function textDecoderHandlesUndefined() {
const fixture = undefined;
const decoder = new TextDecoder();
assert(decoder.decode(fixture) === "");
}
function textDecoderThrowsOnEmpty() {
const fixture = "";
const decoder = new TextDecoder();
let didThrow = false;
try {
decoder.decode(fixture);
} catch (e) {
didThrow = true;
assert(
e.message ===
"Provided input is not of type ArrayBuffer or ArrayBufferView",
);
}
assert(didThrow);
}
function textDecoderThrowsOnNull() {
const fixture = null;
const decoder = new TextDecoder();
let didThrow = false;
try {
decoder.decode(fixture);
} catch (e) {
didThrow = true;
assert(
e.message ===
"Provided input is not of type ArrayBuffer or ArrayBufferView",
);
}
assert(didThrow);
}
function textEncoder() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
@ -231,6 +269,9 @@ function main() {
textDecoderNotBOM();
textDecoderASCII();
textDecoderErrorEncoding();
textDecoderHandlesUndefined();
textDecoderThrowsOnEmpty();
textDecoderThrowsOnNull();
textEncoder();
textEncodeInto();
textEncodeInto2();