Skip to content

Commit

Permalink
fix: improve gc() detection on browser
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 27, 2024
1 parent 58f5638 commit 5146ef7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const version = (() => {
node: () => process.version,
deno: () => Deno.version.deno,
bun: () => process.versions.bun,
// hermes: () =>
// globalThis.HermesInternal?.getRuntimeProperties?.()?.[
// 'OSS Release Version'
// ],
}[runtime]()
})()

Expand Down Expand Up @@ -87,7 +91,14 @@ export const spawnSync = (() => {
export const gc = (() => {
return {
unknown: () => emptyFunction,
browser: () => emptyFunction,
browser: () => {
try {
globalThis.$262.gc()

return () => globalThis.$262.gc()
} catch {}
return emptyFunction
},
node: () => () => {
setFlagsFromString('--expose_gc')
const gc = runInNewContext('gc')
Expand Down

0 comments on commit 5146ef7

Please sign in to comment.