diff --git a/src/constants.js b/src/constants.js index c778d1d..40e1181 100644 --- a/src/constants.js +++ b/src/constants.js @@ -7,7 +7,7 @@ export const runtimes = { browser: 'browser', } -export const emptyFunction = () => {} +export const emptyFunction = Object.freeze(() => {}) export const tatamiNgGroup = '$tatami-ng_group' diff --git a/src/lib.js b/src/lib.js index f50daad..1c78ec1 100644 --- a/src/lib.js +++ b/src/lib.js @@ -33,10 +33,6 @@ export const version = (() => { node: () => globalThis.process.version, deno: () => globalThis.Deno.version.deno, bun: () => globalThis.process.versions.bun, - // hermes: () => - // globalThis.HermesInternal?.getRuntimeProperties?.()?.[ - // 'OSS Release Version' - // ], }[runtime]() })() diff --git a/src/time.js b/src/time.js index d27d1f3..c60d6d6 100644 --- a/src/time.js +++ b/src/time.js @@ -9,7 +9,8 @@ export const now = (() => { return () => 1e6 * now() } catch { - return () => 1e6 * Date.now() + const now = Date.now.bind(Date) + return () => 1e6 * now() } }, browser: () => { @@ -25,10 +26,22 @@ export const now = (() => { return () => 1e6 * $262.agent.monotonicNow() } catch {} - return () => 1e6 * performance.now() + return () => { + const now = performance.now.bind(performance) + return 1e6 * now() + } + }, + node: () => () => { + const hrtimeNow = process.hrtime.bigint.bind(process) + return Number(hrtimeNow()) + }, + deno: () => () => { + const now = performance.now.bind(performance) + return 1e6 * now() + }, + bun: () => { + const now = Bun.nanoseconds.bind(Bun) + return now }, - node: () => () => Number(process.hrtime.bigint()), - deno: () => () => 1e6 * performance.now(), - bun: () => Bun.nanoseconds, }[runtime]() })() diff --git a/src/utils.js b/src/utils.js index ff2bc4e..56ccb81 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,5 @@ +import { emptyFunction } from './constants.js' + /** * Checks if a value is a promise-like object. * @@ -48,7 +50,7 @@ export const isFunctionAsyncResource = fn => { if (promiseLike) { // silence promise rejection try { - fnCall.then(() => {})?.catch(() => {}) + fnCall.then(emptyFunction)?.catch(emptyFunction) } catch { // ignore }