diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index 58905157a943d6..c7c07f9373c2cf 100644 --- a/cli/tests/unit/text_encoding_test.ts +++ b/cli/tests/unit/text_encoding_test.ts @@ -69,7 +69,7 @@ unitTest(function btoaFailed(): void { const text = "你好"; assertThrows(() => { btoa(text); - }, TypeError); + }, DOMException); }); unitTest(function textDecoder2(): void { diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js index c9d70874077e99..c3e622c994f237 100644 --- a/op_crates/web/08_text_encoding.js +++ b/op_crates/web/08_text_encoding.js @@ -26,6 +26,7 @@ "use strict"; ((window) => { + const webidl = window.__bootstrap.webidl; const core = Deno.core; const CONTINUE = null; @@ -124,13 +125,17 @@ } function btoa(s) { + s = webidl.converters.DOMString(s, { + prefix: "Failed to execute 'bota'", + context: "Argument 1", + }); const byteArray = []; for (let i = 0; i < s.length; i++) { const charCode = s[i].charCodeAt(0); if (charCode > 0xff) { - throw new TypeError( - "The string to be encoded contains characters " + - "outside of the Latin1 range.", + throw new DOMException( + "The string to be encoded contains characters outside of the Latin1 range.", + "InvalidCharacterError", ); } byteArray.push(charCode); diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 00f0040486c89d..b2df7e407b9a23 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -1041,6 +1041,9 @@ }, "html": { "webappapis": { + "atob": { + "base64.any.js": true + }, "timers": { "cleartimeout-clearinterval.any.js": true, "missing-timeout-setinterval.any.js": true,