Skip to content

Commit a8af107

Browse files
ManishearthV8-internal LUCI CQ
authored andcommitted
[temporal] Add type definitions for Temporal.ZonedDateTime
Bug: 439921647 Change-Id: I6a6a696447522aaa927ef183f05c1efff3a55709 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8545988 Auto-Submit: Manish Goregaokar <manishearth@google.com> Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Manish Goregaokar <manishearth@google.com>
1 parent 4b58bf6 commit a8af107

File tree

1 file changed

+76
-9
lines changed

1 file changed

+76
-9
lines changed

Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ public extension ILType {
992992
static let wasmTable = ILType.object(ofGroup: "WasmTable", withProperties: ["length"], withMethods: ["get", "grow", "set"])
993993

994994
// Temporal types
995-
static let jsTemporalObject = ILType.object(ofGroup: "Temporal", withProperties: ["Instant", "Duration", "PlainTime", "PlainDate", "PlainDateTime"])
995+
static let jsTemporalObject = ILType.object(ofGroup: "Temporal", withProperties: ["Instant", "Duration", "PlainTime", "PlainDate", "PlainDateTime", "ZonedDateTime"])
996996

997997
// TODO(mliedtke): Can we stop documenting Object.prototype methods? It doesn't make much sense that half of the ObjectGroups register a toString method,
998998
// the other half doesn't and not a single one registers e.g. propertyIsEnumerable or isPrototypeOf.`?
@@ -1025,6 +1025,9 @@ public extension ILType {
10251025

10261026
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"])
10271027

1028+
static let jsTemporalZonedDateTime = ILType.object(ofGroup: "Temporal.ZonedDateTime", withProperties: dateProperties + timeProperties + ["timeZoneId", "epochMilliseconds", "epochNanoseconds", "offsetNanoseconds", "offset"], withMethods: ["with", "withPlainTime", "withTimeZone", "withCalendar", "add", "subtract", "until", "since", "round", "equals", "startOfDay", "getTimeZoneTransition", "toInstant", "toPlainDate", "toPlainTime", "toPlainDateTime"] + commonStringifierMethods)
1029+
1030+
static let jsTemporalZonedDateTimeConstructor = ILType.functionAndConstructor([.bigint, .string, .opt(.jsTemporalCalendarEnum)] => .jsTemporalZonedDateTime) + .object(ofGroup: "TemporalZonedDateTimeConstructor", withProperties: ["prototype"], withMethods: ["from", "compare"])
10281031
}
10291032

10301033
public extension ObjectGroup {
@@ -1927,6 +1930,7 @@ public extension ObjectGroup {
19271930
"PlainTime" : .jsTemporalPlainTimeConstructor,
19281931
"PlainDate" : .jsTemporalPlainDateConstructor,
19291932
"PlainDateTime" : .jsTemporalPlainDateTimeConstructor,
1933+
"ZonedDateTime" : .jsTemporalZonedDateTimeConstructor,
19301934
],
19311935
methods: [:]
19321936
)
@@ -2151,6 +2155,55 @@ public extension ObjectGroup {
21512155
)
21522156

21532157

2158+
static let jsTemporalZonedDateTime = ObjectGroup(
2159+
name: "Temporal.ZonedDateTime",
2160+
instanceType: .jsTemporalZonedDateTime,
2161+
properties: mergeFields(jsTemporalPlainDate.properties, jsTemporalPlainTime.properties, [
2162+
"timeZoneId": .string,
2163+
"epochMilliseconds": .integer,
2164+
"epochNanoseconds": .bigint,
2165+
"offsetNanoseconds": .integer,
2166+
"offset": .string,
2167+
]),
2168+
methods: [
2169+
"with": [jsTemporalZonedDateTimeLike, .opt(jsTemporalZonedInterpretationSettings)] => .jsTemporalZonedDateTime,
2170+
"withPlainTime": [.opt(jsTemporalPlainTimeLike)] => .jsTemporalZonedDateTime,
2171+
"withCalendar": [.plain(.jsTemporalCalendarEnum)] => .jsTemporalZonedDateTime,
2172+
"withTimeZone": [.string] => .jsTemporalZonedDateTime,
2173+
"add": [jsTemporalDurationLike, .opt(jsTemporalOverflowSettings)] => .jsTemporalZonedDateTime,
2174+
"subtract": [jsTemporalDurationLike, .opt(jsTemporalOverflowSettings)] => .jsTemporalZonedDateTime,
2175+
"until": [jsTemporalZonedDateTimeLike, .opt(jsTemporalDifferenceSettings)] => .jsTemporalDuration,
2176+
"since": [jsTemporalZonedDateTimeLike, .opt(jsTemporalDifferenceSettings)] => .jsTemporalDuration,
2177+
"round": [.plain(jsTemporalRoundTo)] => .jsTemporalZonedDateTime,
2178+
"equals": [jsTemporalZonedDateTimeLike] => .boolean,
2179+
"toString": [.opt(jsTemporalToStringSettings)] => .string,
2180+
"toJSON": [] => .string,
2181+
"toLocaleString": [.opt(.string), .opt(jsTemporalToLocaleStringSettings)] => .string,
2182+
"startOfDay": [] => .jsTemporalZonedDateTime,
2183+
"getTimeZoneTransition": [.plain(jsTemporalDirectionParam)] => .jsTemporalZonedDateTime,
2184+
"toInstant": [] => .jsTemporalInstant,
2185+
"toPlainDate": [] => .jsTemporalPlainDate,
2186+
"toPlainTime": [] => .jsTemporalPlainTime,
2187+
"toPlainDateTime": [] => .jsTemporalPlainDateTime,
2188+
2189+
]
2190+
)
2191+
2192+
static let jsTemporalZonedDateTimePrototype = createPrototypeObjectGroup(jsTemporalZonedDateTime)
2193+
2194+
/// ObjectGroup modelling the JavaScript Temporal.ZonedDateTime constructor
2195+
static let jsTemporalZonedDateTimeConstructor = ObjectGroup(
2196+
name: "TemporalZonedDateTimeConstructor",
2197+
instanceType: .jsTemporalZonedDateTimeConstructor,
2198+
properties: [
2199+
"prototype" : jsTemporalZonedDateTimePrototype.instanceType
2200+
],
2201+
methods: [
2202+
"from": [jsTemporalZonedDateTimeLike, .opt(jsTemporalZonedInterpretationSettings)] => .jsTemporalZonedDateTime,
2203+
"compare": [jsTemporalZonedDateTimeLike, jsTemporalZonedDateTimeLike] => .number,
2204+
]
2205+
)
2206+
21542207
// Temporal helpers
21552208

21562209
fileprivate static let jsTemporalDurationLikeObject = ObjectGroup(
@@ -2187,6 +2240,10 @@ public extension ObjectGroup {
21872240
"monthCode": .string | .undefined,
21882241
"day": .number | .undefined,
21892242
]
2243+
private static let jsTemporalZoneLikeFields : [String: ILType] = [
2244+
"timeZone": .string | .undefined,
2245+
"offset": .string | .undefined,
2246+
]
21902247

21912248
private static func mergeFields(_ fields: [String: ILType]...) -> [String: ILType] {
21922249
fields.reduce([:]) {
@@ -2214,20 +2271,28 @@ public extension ObjectGroup {
22142271
properties: mergeFields(jsTemporalDateLikeFields, jsTemporalTimeLikeFields),
22152272
methods: [:])
22162273

2274+
fileprivate static let jsTemporalZonedDateTimeLikeObject = ObjectGroup(
2275+
name: "TemporalZonedDateTimeLikeObject",
2276+
instanceType: nil,
2277+
properties: mergeFields(jsTemporalDateLikeFields, jsTemporalTimeLikeFields, jsTemporalZoneLikeFields),
2278+
methods: [:])
2279+
2280+
22172281
// Temporal-object-like parameters (accepted by ToTemporalFoo)
22182282
// TODO(manishearth, 439921647) type unions just produce .object(),
22192283
// we should ideally do something cleverer here.
22202284

22212285
// TODO(manishearth, 439921647) support duration strings
22222286
fileprivate static let jsTemporalDurationLike = Parameter.plain(jsTemporalDurationLikeObject.instanceType | .jsTemporalDuration | .string)
2223-
// TODO(manishearth, 439921647) support ZonedDateTime and instant strings
2224-
fileprivate static let jsTemporalInstantLike = Parameter.oneof(.jsTemporalInstant, .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)
2287+
// TODO(manishearth, 439921647) support instant strings
2288+
fileprivate static let jsTemporalInstantLike = Parameter.plain(.jsTemporalInstant | .jsTemporalZonedDateTime | .string)
2289+
// TODO(manishearth, 439921647) support instant strings
2290+
fileprivate static let jsTemporalPlainTimeLike = jsTemporalPlainTimeLikeObject.instanceType | .jsTemporalPlainTime | .jsTemporalPlainDateTime | .jsTemporalZonedDateTime | .string
2291+
// TODO(manishearth, 439921647) support instant strings
2292+
fileprivate static let jsTemporalPlainDateLike = Parameter.plain(jsTemporalPlainDateLikeObject.instanceType | .jsTemporalPlainDate | .jsTemporalPlainDateTime | .jsTemporalZonedDateTime | .string)
2293+
// TODO(manishearth, 439921647) support instant strings
2294+
fileprivate static let jsTemporalPlainDateTimeLike = Parameter.plain(jsTemporalPlainDateTimeLikeObject.instanceType | .jsTemporalPlainDate | .jsTemporalPlainDateTime | .jsTemporalZonedDateTime | .string)
2295+
fileprivate static let jsTemporalZonedDateTimeLike = Parameter.plain(jsTemporalZonedDateTimeLikeObject.instanceType | .string)
22312296

22322297
// Stringy objects
22332298
// TODO(manishearth, 439921647) support stringy objects
@@ -2240,6 +2305,8 @@ public extension ObjectGroup {
22402305
fileprivate static let jsTemporalRoundTo = OptionsBag.jsTemporalDifferenceSettingOrRoundTo.group.instanceType
22412306
fileprivate static let jsTemporalToStringSettings = OptionsBag.jsTemporalToStringSettings.group.instanceType
22422307
fileprivate static let jsTemporalOverflowSettings = OptionsBag.jsTemporalOverflowSettings.group.instanceType
2308+
fileprivate static let jsTemporalZonedInterpretationSettings = OptionsBag.jsTemporalZonedInterpretationSettings.group.instanceType
2309+
fileprivate static let jsTemporalDirectionParam = ILType.enumeration(ofName: "directionParam", withValues: ["previous", "next"])
22432310
// TODO(manishearth, 439921647) These are tricky and need other Temporal types
22442311
fileprivate static let jsTemporalDurationRoundTo = Parameter.jsAnything
22452312
fileprivate static let jsTemporalDurationTotalOf = Parameter.jsAnything

0 commit comments

Comments
 (0)