1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix: align btoa to spec (#9053)

This commit is contained in:
Casper Beyer 2021-02-16 09:10:59 +08:00 committed by GitHub
parent 7e9028b532
commit 3f5265b21e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -69,7 +69,7 @@ unitTest(function btoaFailed(): void {
const text = "你好";
assertThrows(() => {
btoa(text);
}, TypeError);
}, DOMException);
});
unitTest(function textDecoder2(): void {

View file

@ -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);

View file

@ -1041,6 +1041,9 @@
},
"html": {
"webappapis": {
"atob": {
"base64.any.js": true
},
"timers": {
"cleartimeout-clearinterval.any.js": true,
"missing-timeout-setinterval.any.js": true,