summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-01-26 15:27:53 +0000
committerLinus Groh <mail@linusgroh.de>2023-01-26 20:20:54 +0000
commitbcca5efd5ad0f063beaf80cc3c97912178f35411 (patch)
tree56c215eeeafffca745882930787b9e9dee05ff1c /Userland/Libraries/LibJS/Runtime
parent269f3c41058348a5c99634c8be2585a37d499f21 (diff)
downloadserenity-bcca5efd5ad0f063beaf80cc3c97912178f35411.zip
LibJS: Port format_calendar_annotation() to String
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp2
4 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index b653618d79..0ba5ca1739 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -578,27 +578,27 @@ ThrowCompletionOr<String> maybe_format_calendar_annotation(VM& vm, Object const*
auto calendar_id = TRY(Value(calendar_object).to_string(vm));
// 4. Return FormatCalendarAnnotation(calendarID, showCalendar).
- return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(format_calendar_annotation(calendar_id, show_calendar)));
+ return format_calendar_annotation(vm, calendar_id, show_calendar);
}
// 12.2.28 FormatCalendarAnnotation ( id, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-formatcalendarannotation
-DeprecatedString format_calendar_annotation(StringView id, StringView show_calendar)
+ThrowCompletionOr<String> format_calendar_annotation(VM& vm, StringView id, StringView show_calendar)
{
VERIFY(show_calendar == "auto"sv || show_calendar == "always"sv || show_calendar == "never"sv || show_calendar == "critical"sv);
// 1. If showCalendar is "never", return the empty String.
if (show_calendar == "never"sv)
- return DeprecatedString::empty();
+ return String {};
// 2. If showCalendar is "auto" and id is "iso8601", return the empty String.
if (show_calendar == "auto"sv && id == "iso8601"sv)
- return DeprecatedString::empty();
+ return String {};
// 3. If showCalendar is "critical", let flag be "!"; else, let flag be the empty String.
auto flag = show_calendar == "critical"sv ? "!"sv : ""sv;
// 4. Return the string-concatenation of "[", flag, "u-ca=", id, and "]".
- return DeprecatedString::formatted("[{}u-ca={}]", flag, id);
+ return TRY_OR_THROW_OOM(vm, String::formatted("[{}u-ca={}]", flag, id));
}
// 12.2.29 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h
index 2b438c1079..011088b0bc 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h
@@ -68,7 +68,7 @@ ThrowCompletionOr<PlainDate*> calendar_date_from_fields(VM&, Object& calendar, O
ThrowCompletionOr<PlainYearMonth*> calendar_year_month_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(VM&, Object& calendar, Object const& fields, Object const* options = nullptr);
ThrowCompletionOr<String> maybe_format_calendar_annotation(VM&, Object const* calendar_object, StringView show_calendar);
-DeprecatedString format_calendar_annotation(StringView id, StringView show_calendar);
+ThrowCompletionOr<String> format_calendar_annotation(VM&, StringView id, StringView show_calendar);
ThrowCompletionOr<bool> calendar_equals(VM&, Object& one, Object& two);
ThrowCompletionOr<Object*> consolidate_calendars(VM&, Object& one, Object& two);
u8 iso_days_in_month(i32 year, u8 month);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
index 1419943af9..ead6405019 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
@@ -195,7 +195,7 @@ ThrowCompletionOr<DeprecatedString> temporal_month_day_to_string(VM& vm, PlainMo
}
// 8. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
- auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
+ auto calendar_string = MUST_OR_THROW_OOM(format_calendar_annotation(vm, calendar_id, show_calendar));
// 9. Set result to the string-concatenation of result and calendarString.
// 10. Return result.
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
index 6a2c70146f..ac3799ac2b 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
@@ -222,7 +222,7 @@ ThrowCompletionOr<DeprecatedString> temporal_year_month_to_string(VM& vm, PlainY
}
// 8. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
- auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
+ auto calendar_string = MUST_OR_THROW_OOM(format_calendar_annotation(vm, calendar_id, show_calendar));
// 9. Set result to the string-concatenation of result and calendarString.
// 10. Return result.