diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-02-07 13:54:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 13:54:32 +0100 |
commit | bf22f114a6e049744866ebaba48faec2cb86549b (patch) | |
tree | ea6814e51bade2355144546f21178f54811a57f2 /ext/web/05_base64.js | |
parent | 9c7ed1c98b75c3557ac9e269212dcf655f69c0a2 (diff) |
refactor: update runtime code for primordial check for iterators (#13510)
Diffstat (limited to 'ext/web/05_base64.js')
-rw-r--r-- | ext/web/05_base64.js | 26 |
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)); } |