From 608c855f1166e0ed76762fd9afd00bb52cc65032 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 22 Feb 2023 00:14:15 +0900 Subject: [PATCH] fix(ext/node): fix process.uptime (#17839) --- cli/tests/node_compat/config.json | 2 +- ext/node/polyfills/process.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cli/tests/node_compat/config.json b/cli/tests/node_compat/config.json index 5bf150d9bb..85e5f09c5c 100644 --- a/cli/tests/node_compat/config.json +++ b/cli/tests/node_compat/config.json @@ -540,7 +540,7 @@ "test-process-exit-recursive.js", "test-process-exit.js", "test-process-kill-pid.js", - "TODO:test-process-uptime.js", + "test-process-uptime.js", "test-promise-unhandled-silent.js", "test-promise-unhandled-throw-handler.js", "TODO:test-punycode.js", diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index 42c55ccc52..779eefb8c2 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -647,7 +647,11 @@ class Process extends EventEmitter { execPath = path; } - #startTime = Date.now(); + setStartTime(t: number) { + this.#startTime = t; + } + + #startTime = 0; /** https://nodejs.org/api/process.html#processuptime */ uptime() { return (Date.now() - this.#startTime) / 1000; @@ -762,6 +766,9 @@ internals.__bootstrapNodeProcess = function ( "stdout", ); + process.setStartTime(Date.now()); + // @ts-ignore Remove setStartTime and #startTime is not modifiable + delete process.setStartTime; delete internals.__bootstrapNodeProcess; };