summaryrefslogtreecommitdiff
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
parent7e9028b53227ce67f56df79f623b2f12fda756b5 (diff)
fix: align btoa to spec (#9053)
-rw-r--r--cli/tests/unit/text_encoding_test.ts2
-rw-r--r--op_crates/web/08_text_encoding.js11
-rw-r--r--tools/wpt/expectation.json3
3 files changed, 12 insertions, 4 deletions
diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts
index 58905157a..c7c07f937 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 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);
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 00f004048..b2df7e407 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,