diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2023-02-22 00:14:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 00:14:15 +0900 |
commit | 608c855f1166e0ed76762fd9afd00bb52cc65032 (patch) | |
tree | 885473c25a25ce2cd16736790c56fc3bb262fbe5 | |
parent | 914b08fc19e5c7268e7b04a216337e765d6a06e8 (diff) |
fix(ext/node): fix process.uptime (#17839)
-rw-r--r-- | cli/tests/node_compat/config.json | 2 | ||||
-rw-r--r-- | 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 5bf150d9b..85e5f09c5 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 42c55ccc5..779eefb8c 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; }; |