diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-07-06 14:38:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 14:38:12 +0200 |
commit | 1aac47720b8dad6826d59263f8e825c221f2a328 (patch) | |
tree | 198e239c8389ef168fbb8dde5aecb11105a170e4 /extensions/web/05_base64.js | |
parent | f139a0cc11f0b3a7e3cb1975310c079e4741d199 (diff) |
refactor: use primordials in extensions/web (#11273)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'extensions/web/05_base64.js')
-rw-r--r-- | extensions/web/05_base64.js | 23 |
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 = { |