1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

LibJS: Throw on conversion from TimeZone to Calendar and vice versa

This is a normative change in the Temporal spec.

See: 2084e77
This commit is contained in:
Linus Groh 2022-12-01 16:07:13 +01:00
parent ca038c1a4e
commit b0e7d59b8b
5 changed files with 60 additions and 10 deletions

View file

@ -20,6 +20,7 @@
#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
#include <LibJS/Runtime/Temporal/PlainTime.h>
#include <LibJS/Runtime/Temporal/PlainYearMonth.h>
#include <LibJS/Runtime/Temporal/TimeZone.h>
#include <LibJS/Runtime/Temporal/ZonedDateTime.h>
#include <LibJS/Runtime/Value.h>
@ -446,16 +447,27 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
if (is<ZonedDateTime>(temporal_calendar_like_object))
return &static_cast<ZonedDateTime&>(temporal_calendar_like_object).calendar();
// c. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
// c. If temporalCalendarLike has an [[InitializedTemporalTimeZone]] internal slot, throw a RangeError exception.
if (is<TimeZone>(temporal_calendar_like_object))
return vm.throw_completion<RangeError>(ErrorType::TemporalUnexpectedTimeZoneObject);
// d. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
if (!TRY(temporal_calendar_like_object.has_property(vm.names.calendar)))
return &temporal_calendar_like_object;
// d. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
// e. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
temporal_calendar_like = TRY(temporal_calendar_like_object.get(vm.names.calendar));
// e. If Type(temporalCalendarLike) is Object and ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
if (temporal_calendar_like.is_object() && !TRY(temporal_calendar_like.as_object().has_property(vm.names.calendar)))
return &temporal_calendar_like.as_object();
// f. If Type(temporalCalendarLike) is Object, then
if (temporal_calendar_like.is_object()) {
// i. If temporalCalendarLike has an [[InitializedTemporalTimeZone]] internal slot, throw a RangeError exception.
if (is<TimeZone>(temporal_calendar_like.as_object()))
return vm.throw_completion<RangeError>(ErrorType::TemporalUnexpectedTimeZoneObject);
// ii. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
if (!TRY(temporal_calendar_like.as_object().has_property(vm.names.calendar)))
return &temporal_calendar_like.as_object();
}
}
// 2. Let identifier be ? ToString(temporalCalendarLike).