Skip to content

Commit 22dc64f

Browse files
committed
squash: add ERR_NO_TEMPORAL error
1 parent 9eb700c commit 22dc64f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/internal/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,8 @@ E('ERR_NO_CRYPTO',
16341634
'Node.js is not compiled with OpenSSL crypto support', Error);
16351635
E('ERR_NO_ICU',
16361636
'%s is not supported on Node.js compiled without ICU', TypeError);
1637+
E('ERR_NO_TEMPORAL',
1638+
'Node.js is not compiled with Temporal support', Error);
16371639
E('ERR_NO_TYPESCRIPT',
16381640
'Node.js is not compiled with TypeScript support', Error);
16391641
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error, TypeError);

lib/internal/fs/utils.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
ERR_INCOMPATIBLE_OPTION_PAIR,
3636
ERR_INVALID_ARG_TYPE,
3737
ERR_INVALID_ARG_VALUE,
38+
ERR_NO_TEMPORAL,
3839
ERR_OUT_OF_RANGE,
3940
},
4041
hideStackFrames,
@@ -436,7 +437,18 @@ function nsFromTimeSpecBigInt(sec, nsec) {
436437
return sec * kNsPerSecBigInt + nsec;
437438
}
438439

440+
function instantFromNs(nsec) {
441+
if (Temporal === undefined) {
442+
throw new ERR_NO_TEMPORAL();
443+
}
444+
// TODO(LiviaMedeiros): TemporalInstant primordial
445+
return new Temporal.Instant(nsec);
446+
}
447+
439448
function instantFromTimeSpecMs(msec, nsec) {
449+
if (Temporal === undefined) {
450+
throw new ERR_NO_TEMPORAL();
451+
}
440452
// TODO(LiviaMedeiros): TemporalInstant primordial
441453
return new Temporal.Instant(BigInt(MathFloor(msec / kMsPerSec)) * kNsPerSecBigInt + BigInt(nsec));
442454
}
@@ -556,7 +568,7 @@ const lazyTemporalBigIntFields = {
556568
enumerable: true,
557569
configurable: true,
558570
get() {
559-
return this.atimeInstant = new Temporal.Instant(this.atimeNs);
571+
return this.atimeInstant = instantFromNs(this.atimeNs);
560572
},
561573
set(value) {
562574
ObjectDefineProperty(this, 'atimeInstant', { __proto__: null, value, writable: true });
@@ -567,7 +579,7 @@ const lazyTemporalBigIntFields = {
567579
enumerable: true,
568580
configurable: true,
569581
get() {
570-
return this.mtimeInstant = new Temporal.Instant(this.mtimeNs);
582+
return this.mtimeInstant = instantFromNs(this.mtimeNs);
571583
},
572584
set(value) {
573585
ObjectDefineProperty(this, 'mtimeInstant', { __proto__: null, value, writable: true });
@@ -578,7 +590,7 @@ const lazyTemporalBigIntFields = {
578590
enumerable: true,
579591
configurable: true,
580592
get() {
581-
return this.ctimeInstant = new Temporal.Instant(this.ctimeNs);
593+
return this.ctimeInstant = instantFromNs(this.ctimeNs);
582594
},
583595
set(value) {
584596
ObjectDefineProperty(this, 'ctimeInstant', { __proto__: null, value, writable: true });
@@ -589,7 +601,7 @@ const lazyTemporalBigIntFields = {
589601
enumerable: true,
590602
configurable: true,
591603
get() {
592-
return this.birthtimeInstant = new Temporal.Instant(this.birthtimeNs);
604+
return this.birthtimeInstant = instantFromNs(this.birthtimeNs);
593605
},
594606
set(value) {
595607
ObjectDefineProperty(this, 'birthtimeInstant', { __proto__: null, value, writable: true });

0 commit comments

Comments
 (0)