diff --git a/src/lib.js b/src/lib.js index 75b1b65..5066590 100644 --- a/src/lib.js +++ b/src/lib.js @@ -90,7 +90,8 @@ export const spawnSync = (() => { export const gc = (() => { return { - unknown: () => emptyFunction, + unknown: () => + typeof globalThis.gc === 'function' ? globalThis.gc() : emptyFunction, browser: () => { try { globalThis.$262.gc() diff --git a/src/logger.js b/src/logger.js index f3cc9d2..fd77c5e 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,16 +1,16 @@ /** * @returns {Function} logger */ -const buildLogger = () => { +const getLogger = () => { let logger - try { - logger = console.log - } catch { - logger = print + if (typeof globalThis.console?.log === 'function') { + logger = globalThis.console.log + } else if (typeof globalThis.print === 'function') { + logger = globalThis.print + } else { + throw new Error('no logger function found') } - if ('function' !== typeof logger) - throw new TypeError(`logger is not a function: ${typeof logger}`) return logger } -export const logger = buildLogger() +export const logger = getLogger()