From 5146ef7cec8d18dcea14c04adca5a49e18f5d813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 Sep 2024 16:53:45 +0200 Subject: [PATCH] fix: improve gc() detection on browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/lib.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib.js b/src/lib.js index bbc9e49..75b1b65 100644 --- a/src/lib.js +++ b/src/lib.js @@ -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]() })() @@ -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')