fs: add Temporal.Instant support to Stats and BigIntStats#60789
fs: add Temporal.Instant support to Stats and BigIntStats#60789LiviaMedeiros wants to merge 6 commits into
Temporal.Instant support to Stats and BigIntStats#60789Conversation
|
It might be better to have this as a switchable option similar to |
Converting from
These properties are lazy-loaded, so the overhead when not used should be minimal. |
| // TODO(LiviaMedeiros): TemporalInstant primordial | ||
| return new Temporal.Instant(BigInt(MathFloor(msec / kMsPerSec)) * kNsPerSecBigInt + BigInt(nsec)); |
There was a problem hiding this comment.
We're probably going to want to support building node without Temporal support for a while
| // TODO(LiviaMedeiros): TemporalInstant primordial | |
| return new Temporal.Instant(BigInt(MathFloor(msec / kMsPerSec)) * kNsPerSecBigInt + BigInt(nsec)); | |
| if (Temporal == null) throw 'informative error'; | |
| // TODO(LiviaMedeiros): TemporalInstant primordial | |
| return new Temporal.Instant(BigInt(MathFloor(msec / kMsPerSec)) * kNsPerSecBigInt + BigInt(nsec)); |
There was a problem hiding this comment.
Agreed, especially with mandatory Rust requirements.
Added the error, the message text is subject to changes (if this may land before enabling Temporal by default, it should also suggest --harmony-temporal flag)
| return this.atimeInstant = instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]); | ||
| }, | ||
| set(value) { | ||
| ObjectDefineProperty(this, 'atimeInstant', { __proto__: null, value, writable: true }); |
There was a problem hiding this comment.
| ObjectDefineProperty(this, 'atimeInstant', { __proto__: null, value, writable: true }); | |
| setOwnProperty(this, 'atimeInstant', value); |
There was a problem hiding this comment.
AFAICT this will make the property enumerable, even though the initial getter is not? I don't mind it, but this better be aligned with how Date setters behave.
There was a problem hiding this comment.
We should probably add an additional optional enumerable argument to setOwnProperty
There was a problem hiding this comment.
The original getter is enumerable though
There was a problem hiding this comment.
Hmm, yes. The difference is that original getter is defined on prototype, so Object.keys() won't list them... I'll open a PR changing enumerability for Dates; if for whatever reason the current behaviour would be preserved, i'd still prefer to align Temporal properties with Date ones.
enumerable argument might be justified if there's enough uses for it, however it's probably out of scope for this PR.
22dc64f to
d149857
Compare
e88849f to
056c074
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60789 +/- ##
========================================
Coverage 90.05% 90.05%
========================================
Files 714 714
Lines 225247 225514 +267
Branches 42578 42612 +34
========================================
+ Hits 202842 203092 +250
- Misses 14181 14211 +30
+ Partials 8224 8211 -13
🚀 New features to boost your workflow:
|
| enumerable: true, | ||
| configurable: true, | ||
| get() { | ||
| return this.atimeInstant = instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]); |
There was a problem hiding this comment.
let's avoid the additional setter call
| return this.atimeInstant = instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]); | |
| const value = instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]); | |
| setOwnProperty(this, 'atimeInstant', value); | |
| return value; |
There was a problem hiding this comment.
Sure. I guess we can do the same in lazyDateFields getters.
There was a problem hiding this comment.
With https://github.com/nodejs/node/pull/63328/changes#diff-f70ef1e11e07dbfe54a7470ee790031f214ed08577129d0a9d3891d7310c0a35 (since setOwnProperty() was designed to replace assignment rather than defineOwnProperty(), i believe it should return value itself), these also can be changed back to
- const value = instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]);
- setOwnProperty(this, 'atimeInstant', value);
- return value;
+ return setOwnProperty(this, 'atimeInstant', instantFromTimeSpecMs(this.atimeMs, this[kPartialAtimeNs]));Signed-off-by: LiviaMedeiros <livia@cirno.name>
b4c96e5 to
65d3bb8
Compare
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
64bc610 to
c2bd49a
Compare
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: #57891
This is a very rough draft, and probably shouldn't land until
Temporalimplementation is finalized and/or enabled by default.Opening early to see if there are any objections, suggestions to naming (the
*Instantproperties are facing userspace and having consistent convention would be nice), or to implementation.