summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-15 23:45:02 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-16 22:34:24 +0100
commit65d26dd25ed8fb550b4267d623263666917204bc (patch)
tree1ed51d6ab4b89e3a80199c834a86fcd9e24517dc /Userland/Libraries/LibJS
parent509d13cf6718036b45d30d122c74683154f8a874 (diff)
downloadserenity-65d26dd25ed8fb550b4267d623263666917204bc.zip
LibJS: Convert to_show_calendar_option() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp6
5 files changed, 9 insertions, 15 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index 07ee3eec05..f6074ac64c 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -226,12 +226,12 @@ ThrowCompletionOr<String> to_temporal_rounding_mode(GlobalObject& global_object,
}
// 13.11 ToShowCalendarOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-toshowcalendaroption
-Optional<String> to_show_calendar_option(GlobalObject& global_object, Object const& normalized_options)
+ThrowCompletionOr<String> to_show_calendar_option(GlobalObject& global_object, Object const& normalized_options)
{
auto& vm = global_object.vm();
// 1. Return ? GetOption(normalizedOptions, "calendarName", « String », « "auto", "always", "never" », "auto").
- auto option = TRY_OR_DISCARD(get_option(global_object, normalized_options, vm.names.calendarName, { OptionType::String }, { "auto"sv, "always"sv, "never"sv }, js_string(vm, "auto"sv)));
+ auto option = TRY(get_option(global_object, normalized_options, vm.names.calendarName, { OptionType::String }, { "auto"sv, "always"sv, "never"sv }, js_string(vm, "auto"sv)));
VERIFY(option.is_string());
return option.as_string().string();
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
index 1a2dac3ae2..8e6c0ca52e 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
@@ -91,7 +91,7 @@ template<typename NumberType>
ThrowCompletionOr<Variant<String, NumberType>> get_string_or_number_option(GlobalObject&, Object const& options, PropertyName const& property, Vector<StringView> const& string_values, NumberType minimum, NumberType maximum, Value fallback);
ThrowCompletionOr<String> to_temporal_overflow(GlobalObject&, Object const& normalized_options);
ThrowCompletionOr<String> to_temporal_rounding_mode(GlobalObject&, Object const& normalized_options, String const& fallback);
-Optional<String> to_show_calendar_option(GlobalObject&, Object const& normalized_options);
+ThrowCompletionOr<String> to_show_calendar_option(GlobalObject&, Object const& normalized_options);
u64 to_temporal_rounding_increment(GlobalObject&, Object const& normalized_options, Optional<double> dividend, bool inclusive);
Optional<SecondsStringPrecision> to_seconds_string_precision(GlobalObject&, Object const& normalized_options);
Optional<String> to_largest_temporal_unit(GlobalObject&, Object const& normalized_options, Vector<StringView> const& disallowed_units, String const& fallback, Optional<String> auto_value);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
index bd477a31b9..a80d101706 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp
@@ -459,12 +459,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_string)
auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0)));
// 4. Let showCalendar be ? ToShowCalendarOption(options).
- auto show_calendar = to_show_calendar_option(global_object, *options);
- if (vm.exception())
- return {};
+ auto show_calendar = TRY_OR_DISCARD(to_show_calendar_option(global_object, *options));
// 5. Return ? TemporalDateToString(temporalDate, showCalendar).
- auto string = temporal_date_to_string(global_object, *temporal_date, *show_calendar);
+ auto string = temporal_date_to_string(global_object, *temporal_date, show_calendar);
if (vm.exception())
return {};
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
index 83d3b98c4c..a894747f15 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
@@ -127,12 +127,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string)
auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0)));
// 4. Let showCalendar be ? ToShowCalendarOption(options).
- auto show_calendar = to_show_calendar_option(global_object, *options);
- if (vm.exception())
- return {};
+ auto show_calendar = TRY_OR_DISCARD(to_show_calendar_option(global_object, *options));
// 5. Return ? TemporalMonthDayToString(monthDay, showCalendar).
- return js_string(vm, TRY_OR_DISCARD(temporal_month_day_to_string(global_object, *month_day, *show_calendar)));
+ return js_string(vm, TRY_OR_DISCARD(temporal_month_day_to_string(global_object, *month_day, show_calendar)));
}
// 10.3.9 Temporal.PlainMonthDay.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tolocalestring
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
index afff17295c..583c1ca525 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
@@ -248,12 +248,10 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_string)
return {};
// 4. Let showCalendar be ? ToShowCalendarOption(options).
- auto show_calendar = to_show_calendar_option(global_object, *options);
- if (vm.exception())
- return {};
+ auto show_calendar = TRY_OR_DISCARD(to_show_calendar_option(global_object, *options));
// 5. Return ? TemporalYearMonthToString(yearMonth, showCalendar).
- return js_string(vm, TRY_OR_DISCARD(temporal_year_month_to_string(global_object, *year_month, *show_calendar)));
+ return js_string(vm, TRY_OR_DISCARD(temporal_year_month_to_string(global_object, *year_month, show_calendar)));
}
// 9.3.18 Temporal.PlainYearMonth.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.tolocalestring