lib: add internal Temporal utils#63312
Open
Renegade334 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
50da00b to
907a6eb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63312 +/- ##
========================================
Coverage 90.05% 90.05%
========================================
Files 714 715 +1
Lines 225247 225438 +191
Branches 42578 42616 +38
========================================
+ Hits 202842 203019 +177
- Misses 14181 14195 +14
Partials 8224 8224
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spun out from #63154 to garner comments. See that PR for an example of how this might be used in practice, and #60789 for an example of a feature that could make use of it.
Integrating Temporal into Node.js APIs is currently made challenging by the fact that it is not available at bootstrapping, meaning no primordials and no user-resistant way of accessing the Temporal globals. Unlike other similar features like SharedArrayBuffer, Temporal is very commonly polyfilled across the ecosystem, so running into a non-builtin implementation in the global namespace is a real possibility.
The likelihood is that the combination of build-time and run-time flags that govern this behaviour is not going away any time soon, so in the meantime, we could really do with something more robust than seeking a property on
globalThisand hoping for the best.This introduces a
internal/util/temporalmodule which is initialized during the pre-execution phase, to mitigate against the user mutability issue. The module exports a number of utilities:hasTemporalproperty for determining whether Node.js is running with builtin Temporal supportisTemporalDuration(),isTemporalInstant()etc.) which perform realm-agnostic type checking for Temporal builtin objects, available regardless of whether Temporal support is enabledObviously this isn't snapshottable, so unlike primordials, there is a small per-run overhead here. Worthwhile?