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 = "你好"; const text = "你好";
assertThrows(() => { assertThrows(() => {
btoa(text); btoa(text);
}, TypeError); }, DOMException);
}); });
unitTest(function textDecoder2(): void { unitTest(function textDecoder2(): void {

View file

@ -26,6 +26,7 @@
"use strict"; "use strict";
((window) => { ((window) => {
const webidl = window.__bootstrap.webidl;
const core = Deno.core; const core = Deno.core;
const CONTINUE = null; const CONTINUE = null;
@ -124,13 +125,17 @@
} }
function btoa(s) { function btoa(s) {
s = webidl.converters.DOMString(s, {
prefix: "Failed to execute 'bota'",
context: "Argument 1",
});
const byteArray = []; const byteArray = [];
for (let i = 0; i < s.length; i++) { for (let i = 0; i < s.length; i++) {
const charCode = s[i].charCodeAt(0); const charCode = s[i].charCodeAt(0);
if (charCode > 0xff) { if (charCode > 0xff) {
throw new TypeError( throw new DOMException(
"The string to be encoded contains characters " + "The string to be encoded contains characters outside of the Latin1 range.",
"outside of the Latin1 range.", "InvalidCharacterError",
); );
} }
byteArray.push(charCode); byteArray.push(charCode);

View file

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