summaryrefslogtreecommitdiff
path: root/op_crates/web/08_text_encoding.js
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-16 09:10:59 +0800
committerGitHub <noreply@github.com>2021-02-16 02:10:59 +0100
commit3f5265b21ec578e543d09cdc9d8b19d9655aebd9 (patch)
treea47bbe4ff1245cd1dcc8dae70d2e5095758b4574 /op_crates/web/08_text_encoding.js
parent7e9028b53227ce67f56df79f623b2f12fda756b5 (diff)
fix: align btoa to spec (#9053)
Diffstat (limited to 'op_crates/web/08_text_encoding.js')
-rw-r--r--op_crates/web/08_text_encoding.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/op_crates/web/08_text_encoding.js b/op_crates/web/08_text_encoding.js
index c9d708740..c3e622c99 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);