inspect: add Temporal support#63154
Conversation
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
|
i'm confused, why would it need to be lazily accessed instead of using primordials? |
| // Returns void if either the type checks fail or the attempt at calling | ||
| // .toString() fails, so that format() can fall back to standard object | ||
| // formatting in either case. | ||
| // TODO: Hopefully the V8 API will expose typechecks at some point. |
There was a problem hiding this comment.
Temporal itself exposes type checks via internal slots and builtin methods.
There was a problem hiding this comment.
Yes, but we can't guarantee a non-mutable path to get our hands on those methods.
There was a problem hiding this comment.
of course we can, via primordials
There was a problem hiding this comment.
Not while Temporal remains an optional feature, unfortunately.
There was a problem hiding this comment.
it's not? node 26 ships it unconditionally.
There was a problem hiding this comment.
It's enabled by default, but remains behind both runtime (cf. --no-harmony-temporal) and build flags, so this is unlikely to change any time soon.
There was a problem hiding this comment.
ahhh gotcha. surely we can still capture the builtins at startup, though, even if they're not real primordials yet?
There was a problem hiding this comment.
It's too early. Attempting to capture the global with something like const { Temporal } = globalThis in the header of inspect.js always hits thin air (I guess it's snapshotted?). We have to do it lazily from inspect(), at which point anything that intends to modify the Temporal global (polyfills etc.) will almost certainly already have run.
We could go full ham to hack around this, but it's not really a huge issue in the context of a function which only uses those methods to decide what flavour of human-readable output gets generated.
Example output:
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