summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-10-16 00:01:19 +0100
committerLinus Groh <mail@linusgroh.de>2022-10-16 13:40:21 +0200
commit8c3512d6ce8a95427a3132cb1362a76c3dbfc0cb (patch)
treebd3bc5c7ebd918c911a8163df82bc283a6433d70 /Userland/Libraries/LibJS/Runtime
parent4b27c6e6888aa40983f049adfb65506986b7d3df (diff)
downloadserenity-8c3512d6ce8a95427a3132cb1362a76c3dbfc0cb.zip
LibJS: Fast-path ToTemporalCalendar when the argument is a Calendar
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/2a43b39
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index 03a22a2e1a..6419eadef5 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -369,7 +369,14 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
// 1. If Type(temporalCalendarLike) is Object, then
if (temporal_calendar_like.is_object()) {
auto& temporal_calendar_like_object = temporal_calendar_like.as_object();
- // a. If temporalCalendarLike has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
+
+ // a. If temporalCalendarLike has an [[InitializedTemporalCalendar]] internal slot, then
+ if (is<Calendar>(temporal_calendar_like_object)) {
+ // i. Return temporalCalendarLike.
+ return &temporal_calendar_like_object;
+ }
+
+ // b. If temporalCalendarLike has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
// i. Return temporalCalendarLike.[[Calendar]].
if (is<PlainDate>(temporal_calendar_like_object))
return &static_cast<PlainDate&>(temporal_calendar_like_object).calendar();
@@ -384,14 +391,14 @@ 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();
- // b. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
+ // c. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
if (!TRY(temporal_calendar_like_object.has_property(vm.names.calendar)))
return &temporal_calendar_like_object;
- // c. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
+ // d. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
temporal_calendar_like = TRY(temporal_calendar_like_object.get(vm.names.calendar));
- // d. If Type(temporalCalendarLike) is Object and ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
+ // 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();
}