Skip to content

Commit

Permalink
fix: try to run gc() with more JS runtimes
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Sep 28, 2024
1 parent 5146ef7 commit 1cef68c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1cef68c

Please sign in to comment.