mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
fix(op_crates/web): throw TypeError on invalid input types in TextDecoder.decode() (#7179)
This commit is contained in:
parent
545ea8e217
commit
2d800f2cb9
2 changed files with 47 additions and 2 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue