summaryrefslogtreecommitdiff
path: root/extensions/web/05_base64.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/web/05_base64.js')
-rw-r--r--extensions/web/05_base64.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/extensions/web/05_base64.js b/extensions/web/05_base64.js
index f0490f240..818815ecd 100644
--- a/extensions/web/05_base64.js
+++ b/extensions/web/05_base64.js
@@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// @ts-check
+/// <reference path="../../core/internal.d.ts" />
/// <reference path="../webidl/internal.d.ts" />
/// <reference path="../web/internal.d.ts" />
/// <reference lib="esnext" />
@@ -14,6 +15,13 @@
forgivingBase64Decode,
} = window.__bootstrap.infra;
const { DOMException } = window.__bootstrap.domException;
+ const {
+ ArrayPrototypeMap,
+ StringPrototypeCharCodeAt,
+ ArrayPrototypeJoin,
+ StringFromCharCode,
+ TypedArrayFrom,
+ } = window.__bootstrap.primordials;
/**
* @param {string} data
@@ -26,10 +34,11 @@
});
const uint8Array = forgivingBase64Decode(data);
- const result = [...uint8Array]
- .map((byte) => String.fromCharCode(byte))
- .join("");
- return result;
+ const result = ArrayPrototypeMap(
+ [...uint8Array],
+ (byte) => StringFromCharCode(byte),
+ );
+ return ArrayPrototypeJoin(result, "");
}
/**
@@ -43,8 +52,8 @@
prefix,
context: "Argument 1",
});
- const byteArray = [...data].map((char) => {
- const charCode = char.charCodeAt(0);
+ const byteArray = ArrayPrototypeMap([...data], (char) => {
+ const charCode = StringPrototypeCharCodeAt(char, 0);
if (charCode > 0xff) {
throw new DOMException(
"The string to be encoded contains characters outside of the Latin1 range.",
@@ -53,7 +62,7 @@
}
return charCode;
});
- return forgivingBase64Encode(Uint8Array.from(byteArray));
+ return forgivingBase64Encode(TypedArrayFrom(Uint8Array, byteArray));
}
window.__bootstrap.base64 = {