@@ -37,6 +37,7 @@ const {
37
37
ObjectHasOwn,
38
38
ObjectKeys,
39
39
ObjectGetOwnPropertyDescriptor,
40
+ ObjectGetOwnPropertyDescriptors,
40
41
ObjectPrototypeIsPrototypeOf,
41
42
ObjectSetPrototypeOf,
42
43
PromisePrototypeThen,
@@ -45,6 +46,7 @@ const {
45
46
Symbol,
46
47
SymbolIterator,
47
48
TypeError,
49
+ uncurryThis,
48
50
} = primordials ;
49
51
const {
50
52
isNativeError,
@@ -459,6 +461,51 @@ function exposeUnstableFeaturesForWindowOrWorkerGlobalScope(unstableFeatures) {
459
461
}
460
462
}
461
463
464
+ function shimTemporalDurationToLocaleString ( ) {
465
+ const DurationFormat = Intl . DurationFormat ;
466
+ if ( ! DurationFormat ) {
467
+ // Intl.DurationFormat can be disabled with --v8-flags=--no-harmony-intl-duration-format
468
+ return ;
469
+ }
470
+ const DurationFormatPrototype = DurationFormat . prototype ;
471
+ const formatDuration = uncurryThis ( DurationFormatPrototype . format ) ;
472
+
473
+ const Duration = Temporal . Duration ;
474
+ const DurationPrototype = Duration . prototype ;
475
+ const desc = ObjectGetOwnPropertyDescriptors ( DurationPrototype ) ;
476
+ const assertDuration = uncurryThis ( desc . toLocaleString . value ) ;
477
+ const getYears = uncurryThis ( desc . years . get ) ;
478
+ const getMonths = uncurryThis ( desc . months . get ) ;
479
+ const getWeeks = uncurryThis ( desc . weeks . get ) ;
480
+ const getDays = uncurryThis ( desc . days . get ) ;
481
+ const getHours = uncurryThis ( desc . hours . get ) ;
482
+ const getMinutes = uncurryThis ( desc . minutes . get ) ;
483
+ const getSeconds = uncurryThis ( desc . seconds . get ) ;
484
+ const getMilliseconds = uncurryThis ( desc . milliseconds . get ) ;
485
+ const getMicroseconds = uncurryThis ( desc . microseconds . get ) ;
486
+ const getNanoseconds = uncurryThis ( desc . nanoseconds . get ) ;
487
+
488
+ ObjectAssign ( DurationPrototype , {
489
+ toLocaleString ( locales = undefined , options ) {
490
+ assertDuration ( this ) ;
491
+ const durationFormat = new DurationFormat ( locales , options ) ;
492
+ const duration = {
493
+ years : getYears ( this ) ,
494
+ months : getMonths ( this ) ,
495
+ weeks : getWeeks ( this ) ,
496
+ days : getDays ( this ) ,
497
+ hours : getHours ( this ) ,
498
+ minutes : getMinutes ( this ) ,
499
+ seconds : getSeconds ( this ) ,
500
+ milliseconds : getMilliseconds ( this ) ,
501
+ microseconds : getMicroseconds ( this ) ,
502
+ nanoseconds : getNanoseconds ( this ) ,
503
+ } ;
504
+ return formatDuration ( durationFormat , duration ) ;
505
+ } ,
506
+ } ) ;
507
+ }
508
+
462
509
// NOTE(bartlomieju): remove all the ops that have already been imported using
463
510
// "virtual op module" (`ext:core/ops`).
464
511
const NOT_IMPORTED_OPS = [
@@ -821,6 +868,11 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
821
868
} ) ;
822
869
delete globalThis . Temporal . Now . timeZone ;
823
870
}
871
+
872
+ if ( new Temporal . Duration ( ) . toLocaleString ( "en-US" ) !== "PT0S" ) {
873
+ throw "V8 supports Temporal.Duration.prototype.toLocaleString now, no need to shim it" ;
874
+ }
875
+ shimTemporalDurationToLocaleString ( ) ;
824
876
}
825
877
826
878
// Setup `Deno` global - we're actually overriding already existing global
@@ -1024,6 +1076,8 @@ function bootstrapWorkerRuntime(
1024
1076
} ) ;
1025
1077
delete globalThis . Temporal . Now . timeZone ;
1026
1078
}
1079
+
1080
+ shimTemporalDurationToLocaleString ( ) ;
1027
1081
}
1028
1082
1029
1083
// Setup `Deno` global - we're actually overriding already existing global
0 commit comments