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:
parent
7e9028b532
commit
3f5265b21e
3 changed files with 12 additions and 4 deletions
|
@ -69,7 +69,7 @@ unitTest(function btoaFailed(): void {
|
|||
const text = "你好";
|
||||
assertThrows(() => {
|
||||
btoa(text);
|
||||
}, TypeError);
|
||||
}, DOMException);
|
||||
});
|
||||
|
||||
unitTest(function textDecoder2(): void {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1041,6 +1041,9 @@
|
|||
},
|
||||
"html": {
|
||||
"webappapis": {
|
||||
"atob": {
|
||||
"base64.any.js": true
|
||||
},
|
||||
"timers": {
|
||||
"cleartimeout-clearinterval.any.js": true,
|
||||
"missing-timeout-setinterval.any.js": true,
|
||||
|
|
Loading…
Reference in a new issue