Skip to content

inspect: add Temporal support#63154

Draft
Renegade334 wants to merge 1 commit into
nodejs:mainfrom
Renegade334:inspect-temporal
Draft

inspect: add Temporal support#63154
Renegade334 wants to merge 1 commit into
nodejs:mainfrom
Renegade334:inspect-temporal

Conversation

@Renegade334
Copy link
Copy Markdown
Member

Example output:

> Temporal.Now.instant()
Temporal.Instant 2026-05-06T16:19:21.226404053Z

> class XYZ extends Temporal.Duration {}
> new XYZ(1, 2, 3, 4, 5, 6, 7, 8, 9)
XYZ [Temporal.Duration] P1Y2M3W4DT5H6M7.008009S

> Object.assign(Temporal.Now.zonedDateTimeISO('Pacific/Honolulu'), { foo: 'bar' })
Temporal.ZonedDateTime 2026-05-06T06:24:22.920191895-10:00[Pacific/Honolulu] {
  foo: 'bar'
}

The Temporal global obviously has to be lazily accessed, and there's no way to do it that's immune from potential user tampering. The approach taken here is just to fetch it from the global object every time, since the output of inspect() is inherently aimed at the human reader, so it doesn't really need to be particularly hardened.

WIP: tests

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels May 6, 2026
@ljharb
Copy link
Copy Markdown
Member

ljharb commented May 6, 2026

i'm confused, why would it need to be lazily accessed instead of using primordials?

Comment thread lib/internal/util/inspect.js Outdated
Comment thread lib/internal/util/inspect.js Outdated
@legendecas
Copy link
Copy Markdown
Member

the subsystem should be "util".

@Renegade334
Copy link
Copy Markdown
Member Author

Alternative approach to the "how to Temporal" problem. This hooks into the pre-execution initializers and creates some typechecking functions and saves the constructor and prototype properties, primordial-ish, if Temporal exists.

We don't use this approach for any other ES builtins, only Node.js APIs, so does need consideration as to whether this is kosher. However, it does also provide for if we want to create or manipulate Temporal objects elsewhere in the API.

Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants