mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00: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
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue