@@ -382,6 +382,9 @@ public class JavaScriptEnvironment: ComponentBase {
382382 registerObjectGroup ( . jsTemporalPlainDate)
383383 registerObjectGroup ( . jsTemporalPlainDateConstructor)
384384 registerObjectGroup ( . jsTemporalPlainDatePrototype)
385+ registerObjectGroup ( . jsTemporalPlainDateTime)
386+ registerObjectGroup ( . jsTemporalPlainDateTimeConstructor)
387+ registerObjectGroup ( . jsTemporalPlainDateTimePrototype)
385388
386389 for group in additionalObjectGroups {
387390 registerObjectGroup ( group)
@@ -390,6 +393,7 @@ public class JavaScriptEnvironment: ComponentBase {
390393 registerOptionsBag ( . jsTemporalDifferenceSettingOrRoundTo)
391394 registerOptionsBag ( . jsTemporalToStringSettings)
392395 registerOptionsBag ( . jsTemporalOverflowSettings)
396+ registerOptionsBag ( . jsTemporalZonedInterpretationSettings)
393397
394398 // Register builtins that should be available for fuzzing.
395399 // Here it is easy to selectively disable/enable some APIs for fuzzing by
@@ -727,7 +731,6 @@ public struct ObjectGroup {
727731 public init ( name: String , instanceType: ILType ? , properties: [ String : ILType ] , methods: [ String : Signature ] , parent: String ? = nil ) {
728732 self . init ( name: name, instanceType: instanceType, properties: properties, overloads: methods. mapValues ( { [ $0] } ) , parent: parent)
729733 }
730-
731734}
732735
733736// Some APIs take an "options bag", a list of options like {foo: "something", bar: "something", baz: 1}
@@ -989,7 +992,7 @@ public extension ILType {
989992 static let wasmTable = ILType . object ( ofGroup: " WasmTable " , withProperties: [ " length " ] , withMethods: [ " get " , " grow " , " set " ] )
990993
991994 // Temporal types
992- static let jsTemporalObject = ILType . object ( ofGroup: " Temporal " , withProperties: [ " Instant " , " Duration " , " PlainTime " , " PlainDate " ] )
995+ static let jsTemporalObject = ILType . object ( ofGroup: " Temporal " , withProperties: [ " Instant " , " Duration " , " PlainTime " , " PlainDate " , " PlainDateTime " ] )
993996
994997 // TODO(mliedtke): Can we stop documenting Object.prototype methods? It doesn't make much sense that half of the ObjectGroups register a toString method,
995998 // the other half doesn't and not a single one registers e.g. propertyIsEnumerable or isPrototypeOf.`?
@@ -1017,6 +1020,11 @@ public extension ILType {
10171020
10181021 static let jsTemporalPlainDateConstructor = ILType . functionAndConstructor ( [ . number, . number, . number, . opt( . jsTemporalCalendarEnum) ] => . jsTemporalPlainDate) + . object( ofGroup: " TemporalPlainDateConstructor " , withProperties: [ " prototype " ] , withMethods: [ " from " , " compare " ] )
10191022
1023+
1024+ static let jsTemporalPlainDateTime = ILType . object ( ofGroup: " Temporal.PlainDateTime " , withProperties: dateProperties + timeProperties, withMethods: [ " with " , " withPlainTime " , " withCalendar " , " add " , " subtract " , " until " , " since " , " round " , " equals " , " toZonedDateTime " , " toPlainDate " , " toPlainTime " ] + commonStringifierMethods)
1025+
1026+ static let jsTemporalPlainDateTimeConstructor = ILType . functionAndConstructor ( [ . number, . number, . number, . opt( . number) , . opt( . number) , . opt( . number) , . opt( . number) , . opt( . number) , . opt( . number) , . opt( . jsTemporalCalendarEnum) ] => . jsTemporalPlainDateTime) + . object( ofGroup: " TemporalPlainDateTimeConstructor " , withProperties: [ " prototype " ] , withMethods: [ " from " , " compare " ] )
1027+
10201028}
10211029
10221030public extension ObjectGroup {
@@ -1918,6 +1926,7 @@ public extension ObjectGroup {
19181926 " Duration " : . jsTemporalDurationConstructor,
19191927 " PlainTime " : . jsTemporalPlainTimeConstructor,
19201928 " PlainDate " : . jsTemporalPlainDateConstructor,
1929+ " PlainDateTime " : . jsTemporalPlainDateTimeConstructor,
19211930 ] ,
19221931 methods: [ : ]
19231932 )
@@ -2079,8 +2088,7 @@ public extension ObjectGroup {
20792088 " until " : [ jsTemporalPlainDateLike, . opt( jsTemporalDifferenceSettings) ] => . jsTemporalDuration,
20802089 " since " : [ jsTemporalPlainDateLike, . opt( jsTemporalDifferenceSettings) ] => . jsTemporalDuration,
20812090 " equals " : [ jsTemporalPlainDateLike] => . boolean,
2082- // TODO(manishearth, 439921647) return the right types when we can
2083- " toPlainDateTime " : [ . opt( jsTemporalPlainTimeLike) ] => . jsAnything,
2091+ " toPlainDateTime " : [ . opt( jsTemporalPlainTimeLike) ] => . jsTemporalPlainDateTime,
20842092 " toZonedDateTime " : [ . jsAnything] => . jsAnything,
20852093 " toString " : [ . opt( jsTemporalToStringSettings) ] => . string,
20862094 " toJSON " : [ ] => . string,
@@ -2103,6 +2111,46 @@ public extension ObjectGroup {
21032111 ]
21042112 )
21052113
2114+ static let jsTemporalPlainDateTime = ObjectGroup (
2115+ name: " Temporal.PlainDateTime " ,
2116+ instanceType: . jsTemporalPlainDateTime,
2117+ properties: mergeFields ( jsTemporalPlainDate. properties, jsTemporalPlainTime. properties) ,
2118+ methods: [
2119+ " with " : [ jsTemporalPlainDateTimeLike, . opt( jsTemporalOverflowSettings) ] => . jsTemporalPlainDateTime,
2120+ " withPlainTime " : [ . opt( jsTemporalPlainTimeLike) ] => . jsTemporalPlainDateTime,
2121+ " withCalendar " : [ . plain( . jsTemporalCalendarEnum) ] => . jsTemporalPlainDateTime,
2122+ " add " : [ jsTemporalDurationLike, . opt( jsTemporalOverflowSettings) ] => . jsTemporalPlainDateTime,
2123+ " subtract " : [ jsTemporalDurationLike, . opt( jsTemporalOverflowSettings) ] => . jsTemporalPlainDateTime,
2124+ " until " : [ jsTemporalPlainDateTimeLike, . opt( jsTemporalDifferenceSettings) ] => . jsTemporalDuration,
2125+ " since " : [ jsTemporalPlainDateTimeLike, . opt( jsTemporalDifferenceSettings) ] => . jsTemporalDuration,
2126+ " round " : [ . plain( jsTemporalRoundTo) ] => . jsTemporalPlainDateTime,
2127+ " equals " : [ jsTemporalPlainDateTimeLike] => . boolean,
2128+ " toString " : [ . opt( jsTemporalToStringSettings) ] => . string,
2129+ " toJSON " : [ ] => . string,
2130+ " toLocaleString " : [ . opt( . string) , . opt( jsTemporalToLocaleStringSettings) ] => . string,
2131+ // TODO(manishearth, 439921647) return the right types when we can
2132+ " toZonedDateTime " : [ . string, . opt( OptionsBag . jsTemporalZonedInterpretationSettings. group. instanceType) ] => . jsAnything,
2133+ " toPlainDate " : [ ] => . jsTemporalPlainDate,
2134+ " toPlainTime " : [ ] => . jsTemporalPlainTime,
2135+ ]
2136+ )
2137+
2138+ static let jsTemporalPlainDateTimePrototype = createPrototypeObjectGroup ( jsTemporalPlainDateTime)
2139+
2140+ /// ObjectGroup modelling the JavaScript Temporal.PlainDateTime constructor
2141+ static let jsTemporalPlainDateTimeConstructor = ObjectGroup (
2142+ name: " TemporalPlainDateTimeConstructor " ,
2143+ instanceType: . jsTemporalPlainDateTimeConstructor,
2144+ properties: [
2145+ " prototype " : jsTemporalPlainDateTimePrototype. instanceType
2146+ ] ,
2147+ methods: [
2148+ " from " : [ jsTemporalPlainDateTimeLike, . opt( jsTemporalOverflowSettings) ] => . jsTemporalPlainDateTime,
2149+ " compare " : [ jsTemporalPlainDateTimeLike, jsTemporalPlainDateTimeLike] => . number,
2150+ ]
2151+ )
2152+
2153+
21062154 // Temporal helpers
21072155
21082156 fileprivate static let jsTemporalDurationLikeObject = ObjectGroup (
@@ -2122,30 +2170,48 @@ public extension ObjectGroup {
21222170 ] ,
21232171 methods: [ : ] )
21242172
2125- fileprivate static let jsTemporalPlainTimeLikeObject = ObjectGroup (
2126- name: " TemporalPlainTimeLikeObject " ,
2127- instanceType: nil ,
2128- properties: [
2173+ private static let jsTemporalTimeLikeFields : [ String : ILType ] = [
21292174 " hour " : . number | . undefined,
21302175 " minute " : . number | . undefined,
21312176 " second " : . number | . undefined,
21322177 " millisecond " : . number | . undefined,
21332178 " microsecond " : . number | . undefined,
21342179 " nanosecond " : . number | . undefined,
2135- ] ,
2136- methods: [ : ] )
2180+ ]
21372181
2138- fileprivate static let jsTemporalPlainDateLikeObject = ObjectGroup (
2139- name: " TemporalPlainDateLikeObject " ,
2140- instanceType: nil ,
2141- properties: [
2182+ private static let jsTemporalDateLikeFields : [ String : ILType ] = [
21422183 " calendar " : . jsTemporalCalendarEnum | . undefined,
21432184 " era " : . string | . undefined,
21442185 " eraYear " : . number | . undefined,
21452186 " month " : . number | . undefined,
21462187 " monthCode " : . string | . undefined,
21472188 " day " : . number | . undefined,
2148- ] ,
2189+ ]
2190+
2191+ private static func mergeFields( _ fields: [ String : ILType ] ... ) -> [ String : ILType ] {
2192+ fields. reduce ( [ : ] ) {
2193+ $0. merging ( $1) { _, _ in
2194+ fatalError ( " Duplicate field in \( fields) " )
2195+ }
2196+ }
2197+ }
2198+
2199+ fileprivate static let jsTemporalPlainTimeLikeObject = ObjectGroup (
2200+ name: " TemporalPlainTimeLikeObject " ,
2201+ instanceType: nil ,
2202+ properties: jsTemporalTimeLikeFields,
2203+ methods: [ : ] )
2204+
2205+ fileprivate static let jsTemporalPlainDateLikeObject = ObjectGroup (
2206+ name: " TemporalPlainDateLikeObject " ,
2207+ instanceType: nil ,
2208+ properties: jsTemporalDateLikeFields,
2209+ methods: [ : ] )
2210+
2211+ fileprivate static let jsTemporalPlainDateTimeLikeObject = ObjectGroup (
2212+ name: " TemporalPlainDateTimeLikeObject " ,
2213+ instanceType: nil ,
2214+ properties: mergeFields ( jsTemporalDateLikeFields, jsTemporalTimeLikeFields) ,
21492215 methods: [ : ] )
21502216
21512217 // Temporal-object-like parameters (accepted by ToTemporalFoo)
@@ -2156,10 +2222,12 @@ public extension ObjectGroup {
21562222 fileprivate static let jsTemporalDurationLike = Parameter . plain ( jsTemporalDurationLikeObject. instanceType | . jsTemporalDuration | . string)
21572223 // TODO(manishearth, 439921647) support ZonedDateTime and instant strings
21582224 fileprivate static let jsTemporalInstantLike = Parameter . oneof ( . jsTemporalInstant, . string)
2159- // TODO(manishearth, 439921647) support ZDT/DateTime and instant strings
2160- fileprivate static let jsTemporalPlainTimeLike = jsTemporalPlainTimeLikeObject. instanceType | . jsTemporalPlainTime | . string
2161- // TODO(manishearth, 439921647) support ZDT/DateTime and instant strings
2162- fileprivate static let jsTemporalPlainDateLike = Parameter . plain ( jsTemporalPlainDateLikeObject. instanceType | . jsTemporalPlainDate | . string)
2225+ // TODO(manishearth, 439921647) support ZDT and instant strings
2226+ fileprivate static let jsTemporalPlainTimeLike = jsTemporalPlainTimeLikeObject. instanceType | . jsTemporalPlainTime | . jsTemporalPlainDateTime | . string
2227+ // TODO(manishearth, 439921647) support ZDT and instant strings
2228+ fileprivate static let jsTemporalPlainDateLike = Parameter . plain ( jsTemporalPlainDateLikeObject. instanceType | . jsTemporalPlainDate | . jsTemporalPlainDateTime | . string)
2229+ // TODO(manishearth, 439921647) support ZDT and instant strings
2230+ fileprivate static let jsTemporalPlainDateTimeLike = Parameter . plain ( jsTemporalPlainDateTimeLikeObject. instanceType | . jsTemporalPlainDate | . jsTemporalPlainDateTime | . string)
21632231
21642232 // Stringy objects
21652233 // TODO(manishearth, 439921647) support stringy objects
@@ -2178,6 +2246,7 @@ public extension ObjectGroup {
21782246 // This is huge and comes from Intl, not Temporal
21792247 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#parameters
21802248 fileprivate static let jsTemporalToLocaleStringSettings = ILType . jsAnything
2249+ fileprivate static let jsTemporalZonedOptions = ILType . jsAnything
21812250}
21822251
21832252extension OptionsBag {
@@ -2187,6 +2256,9 @@ extension OptionsBag {
21872256 fileprivate static let jsTemporalShowCalendarEnum = ILType . enumeration ( ofName: " temporalShowCalendar " , withValues: [ " auto " , " always " , " never " , " critical " ] )
21882257 fileprivate static let jsTemporalShowOffsetEnum = ILType . enumeration ( ofName: " temporalShowOffset " , withValues: [ " auto " , " never " ] )
21892258 fileprivate static let jsTemporalShowTimeZoneEnum = ILType . enumeration ( ofName: " temporalShowOfTimeZone " , withValues: [ " auto " , " never " , " critical " ] )
2259+ fileprivate static let jsTemporalOverflowEnum = ILType . enumeration ( ofName: " temporalOverflow " , withValues: [ " constrain " , " reject " ] )
2260+ fileprivate static let jsTemporalDisambiguationEnum = ILType . enumeration ( ofName: " temporalDisambiguation " , withValues: [ " compatible " , " earlier " , " later " , " reject " ] )
2261+ fileprivate static let jsTemporalOffsetEnum = ILType . enumeration ( ofName: " temporalOffset " , withValues: [ " prefer " , " use " , " ignore " , " reject " ] )
21902262
21912263 // differenceSettings and roundTo are mostly the same, with differenceSettings accepting an additional largestUnit
21922264 // note that the Duration roundTo option is different
@@ -2215,7 +2287,15 @@ extension OptionsBag {
22152287 static let jsTemporalOverflowSettings = OptionsBag (
22162288 name: " jsTemporalOverflowSettingsObject " ,
22172289 properties: [
2218- " overflow " : ILType . enumeration ( ofName: " temporalOverflow " , withValues: [ " constrain " , " reject " ] ) ,
2290+ " overflow " : jsTemporalOverflowEnum,
2291+ ] )
2292+
2293+ static let jsTemporalZonedInterpretationSettings = OptionsBag (
2294+ name: " TemporalZonedInterpretationSettingsObject " ,
2295+ properties: [
2296+ " overflow " : jsTemporalOverflowEnum,
2297+ " disambiguation " : jsTemporalDisambiguationEnum,
2298+ " offset " : jsTemporalOffsetEnum,
22192299 ] )
22202300}
22212301
0 commit comments