Skip to content

Commit

Permalink
Caching the result of atob is causing webworker to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Itayp-harmonie committed Feb 21, 2024
1 parent 53644d0 commit 43f4a49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
* @deprecated use lowercase `version`.
*/
var VERSION = version;
var _hasatob = typeof atob === 'function';
var _hasbtoa = typeof btoa === 'function';
var typeof atob === 'function' = typeof atob === 'function';
var typeof btoa === 'function' = typeof btoa === 'function';
var _hasBuffer = typeof Buffer === 'function';
var _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
Expand Down Expand Up @@ -87,7 +87,7 @@
* @param {String} bin binary string
* @returns {string} Base64-encoded string
*/
var _btoa = _hasbtoa ? function (bin) { return btoa(bin); }
var _btoa = typeof btoa === 'function' ? function (bin) { return btoa(bin); }
: _hasBuffer ? function (bin) { return Buffer.from(bin, 'binary').toString('base64'); }
: btoaPolyfill;
var _fromUint8Array = _hasBuffer
Expand Down Expand Up @@ -216,7 +216,7 @@
* @param {String} asc Base64-encoded string
* @returns {string} binary string
*/
var _atob = _hasatob ? function (asc) { return atob(_tidyB64(asc)); }
var _atob = typeof atob === 'function' ? function (asc) { return atob(_tidyB64(asc)); }
: _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); }
: atobPolyfill;
//
Expand Down
6 changes: 2 additions & 4 deletions base64.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const version = '3.7.6';
* @deprecated use lowercase `version`.
*/
const VERSION = version;
const _hasatob = typeof atob === 'function';
const _hasbtoa = typeof btoa === 'function';
const _hasBuffer = typeof Buffer === 'function';
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
Expand Down Expand Up @@ -59,7 +57,7 @@ const btoaPolyfill = (bin) => {
* @param {String} bin binary string
* @returns {string} Base64-encoded string
*/
const _btoa = _hasbtoa ? (bin) => btoa(bin)
const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
: btoaPolyfill;
const _fromUint8Array = _hasBuffer
Expand Down Expand Up @@ -182,7 +180,7 @@ const atobPolyfill = (asc) => {
* @param {String} asc Base64-encoded string
* @returns {string} binary string
*/
const _atob = _hasatob ? (asc) => atob(_tidyB64(asc))
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
: atobPolyfill;
//
Expand Down
6 changes: 2 additions & 4 deletions base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const version = '3.7.6';
* @deprecated use lowercase `version`.
*/
const VERSION = version;
const _hasatob = typeof atob === 'function';
const _hasbtoa = typeof btoa === 'function';
const _hasBuffer = typeof Buffer === 'function';
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
Expand Down Expand Up @@ -61,7 +59,7 @@ const btoaPolyfill = (bin: string) => {
* @param {String} bin binary string
* @returns {string} Base64-encoded string
*/
const _btoa = _hasbtoa ? (bin: string) => btoa(bin)
const _btoa = typeof btoa === 'function' ? (bin: string) => btoa(bin)
: _hasBuffer ? (bin: string) => Buffer.from(bin, 'binary').toString('base64')
: btoaPolyfill;
const _fromUint8Array = _hasBuffer
Expand Down Expand Up @@ -188,7 +186,7 @@ const atobPolyfill = (asc: string) => {
* @param {String} asc Base64-encoded string
* @returns {string} binary string
*/
const _atob = _hasatob ? (asc: string) => atob(_tidyB64(asc))
const _atob = typeof atob === 'function' ? (asc: string) => atob(_tidyB64(asc))
: _hasBuffer ? (asc: string) => Buffer.from(asc, 'base64').toString('binary')
: atobPolyfill;
//
Expand Down

0 comments on commit 43f4a49

Please sign in to comment.