summaryrefslogtreecommitdiff
path: root/ext/web/05_base64.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/web/05_base64.js')
-rw-r--r--ext/web/05_base64.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/ext/web/05_base64.js b/ext/web/05_base64.js
index 7f4b607c9..1244ecfd5 100644
--- a/ext/web/05_base64.js
+++ b/ext/web/05_base64.js
@@ -19,6 +19,7 @@
ArrayPrototypeMap,
StringPrototypeCharCodeAt,
ArrayPrototypeJoin,
+ SafeArrayIterator,
StringFromCharCode,
TypedArrayFrom,
Uint8Array,
@@ -38,7 +39,7 @@
const uint8Array = forgivingBase64Decode(data);
const result = ArrayPrototypeMap(
- [...uint8Array],
+ [...new SafeArrayIterator(uint8Array)],
(byte) => StringFromCharCode(byte),
);
return ArrayPrototypeJoin(result, "");
@@ -55,16 +56,19 @@
prefix,
context: "Argument 1",
});
- 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.",
- "InvalidCharacterError",
- );
- }
- return charCode;
- });
+ const byteArray = ArrayPrototypeMap(
+ [...new SafeArrayIterator(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.",
+ "InvalidCharacterError",
+ );
+ }
+ return charCode;
+ },
+ );
return forgivingBase64Encode(TypedArrayFrom(Uint8Array, byteArray));
}