summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-16 17:59:54 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-16 22:34:24 +0100
commit2f56fd48cab2ba11dfd317c3b3a05f33f747c353 (patch)
treec7e135f17fe831e129fb714066ded54e403afe0b /Userland/Libraries/LibJS
parent14f16d9ed445fe22472e9c5313b75b3de9a8ac79 (diff)
downloadserenity-2f56fd48cab2ba11dfd317c3b3a05f33f747c353.zip
LibJS: Convert parse_temporal_year_month_string() 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/PlainYearMonth.cpp8
3 files changed, 6 insertions, 8 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index c9e414c649..e0800b6684 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -1004,7 +1004,7 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
}
// 13.45 ParseTemporalYearMonthString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalyearmonthstring
-Optional<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject& global_object, String const& iso_string)
+ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject& global_object, String const& iso_string)
{
// 1. Assert: Type(isoString) is String.
@@ -1013,7 +1013,7 @@ Optional<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject& globa
// TODO
// 3. Let result be ? ParseISODateTime(isoString).
- auto result = TRY_OR_DISCARD(parse_iso_date_time(global_object, iso_string));
+ auto result = TRY(parse_iso_date_time(global_object, iso_string));
// 4. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Calendar]]: result.[[Calendar]] }.
return TemporalYearMonth { .year = result.year, .month = result.month, .day = result.day, .calendar = move(result.calendar) };
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
index 915eda15ce..dfe8c5ffd5 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
@@ -111,7 +111,7 @@ ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(GlobalObject&, St
ThrowCompletionOr<TemporalDuration> parse_temporal_duration_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject&, String const& iso_string);
-Optional<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject&, String const& iso_string);
+ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject&, String const& iso_string);
double to_positive_integer(GlobalObject&, Value argument);
Object* prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names, Vector<StringView> const& required_fields);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
index d7c59afe23..39f1a7f8bd 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp
@@ -79,17 +79,15 @@ ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(GlobalObject& global_o
return throw_completion(exception->value());
// 6. Let result be ? ParseTemporalYearMonthString(string).
- auto result = parse_temporal_year_month_string(global_object, string);
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto result = TRY(parse_temporal_year_month_string(global_object, string));
// 7. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
- auto* calendar = to_temporal_calendar_with_iso_default(global_object, result->calendar.has_value() ? js_string(vm, *result->calendar) : js_undefined());
+ auto* calendar = to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined());
if (auto* exception = vm.exception())
return throw_completion(exception->value());
// 8. Set result to ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[Day]]).
- auto* creation_result = TRY(create_temporal_year_month(global_object, result->year, result->month, *calendar, result->day));
+ auto* creation_result = TRY(create_temporal_year_month(global_object, result.year, result.month, *calendar, result.day));
// 9. Let canonicalYearMonthOptions be ! OrdinaryObjectCreate(null).
auto* canonical_year_month_options = Object::create(global_object, nullptr);