diff --git a/cli/tests/unit_node/perf_hooks_test.ts b/cli/tests/unit_node/perf_hooks_test.ts index 78375d54dc..2249e62f82 100644 --- a/cli/tests/unit_node/perf_hooks_test.ts +++ b/cli/tests/unit_node/perf_hooks_test.ts @@ -1,7 +1,10 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import * as perfHooks from "node:perf_hooks"; import { performance } from "node:perf_hooks"; -import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { + assertEquals, + assertThrows, +} from "../../../test_util/std/testing/asserts.ts"; Deno.test({ name: "[perf_hooks] performance", @@ -39,3 +42,14 @@ Deno.test({ assertEquals(perfHooks.PerformanceEntry, PerformanceEntry); }, }); + +Deno.test({ + name: "[perf_hooks] performance.timeOrigin", + fn() { + assertEquals(typeof performance.timeOrigin, "number"); + assertThrows(() => { + // @ts-expect-error: Cannot assign to 'timeOrigin' because it is a read-only property + performance.timeOrigin = 1; + }); + }, +}); diff --git a/ext/node/polyfills/perf_hooks.ts b/ext/node/polyfills/perf_hooks.ts index 059677c9bc..64c2c3e062 100644 --- a/ext/node/polyfills/perf_hooks.ts +++ b/ext/node/polyfills/perf_hooks.ts @@ -54,8 +54,10 @@ const performance: nodeTiming: {}, now: () => shimPerformance.now(), timerify: () => notImplemented("timerify from performance"), - // deno-lint-ignore no-explicit-any - timeOrigin: (shimPerformance as any).timeOrigin, + get timeOrigin() { + // deno-lint-ignore no-explicit-any + return (shimPerformance as any).timeOrigin; + }, markResourceTiming: () => {}, // @ts-ignore waiting on update in `deno`, but currently this is // a circular dependency