1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

LibJS: Fast-path ToTemporalTimeZone when the argument is a TimeZone

This is a normative change in the Temporal spec.

See: 54cea53
This commit is contained in:
Luke Wilde 2022-10-16 00:13:44 +01:00 committed by Linus Groh
parent 8c3512d6ce
commit f7bb79d6d1
2 changed files with 28 additions and 4 deletions

View file

@ -292,7 +292,13 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
{
// 1. If Type(temporalTimeZoneLike) is Object, then
if (temporal_time_zone_like.is_object()) {
// a. If temporalTimeZoneLike has an [[InitializedTemporalZonedDateTime]] internal slot, then
// a. If temporalTimeZoneLike has an [[InitializedTemporalTimeZone]] internal slot, then
if (is<TimeZone>(temporal_time_zone_like.as_object())) {
// i. Return temporalTimeZoneLike.
return &temporal_time_zone_like.as_object();
}
// b. If temporalTimeZoneLike has an [[InitializedTemporalZonedDateTime]] internal slot, then
if (is<ZonedDateTime>(temporal_time_zone_like.as_object())) {
auto& zoned_date_time = static_cast<ZonedDateTime&>(temporal_time_zone_like.as_object());
@ -300,14 +306,14 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
return &zoned_date_time.time_zone();
}
// b. If ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
// c. If ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
if (!TRY(temporal_time_zone_like.as_object().has_property(vm.names.timeZone)))
return &temporal_time_zone_like.as_object();
// c. Set temporalTimeZoneLike to ? Get(temporalTimeZoneLike, "timeZone").
// d. Set temporalTimeZoneLike to ? Get(temporalTimeZoneLike, "timeZone").
temporal_time_zone_like = TRY(temporal_time_zone_like.as_object().get(vm.names.timeZone));
// d. If Type(temporalTimeZoneLike) is Object and ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
// e. If Type(temporalTimeZoneLike) is Object and ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
if (temporal_time_zone_like.is_object() && !TRY(temporal_time_zone_like.as_object().has_property(vm.names.timeZone)))
return &temporal_time_zone_like.as_object();
}