summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-16 17:51:37 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-16 22:34:24 +0100
commit4cb6eaf5885fa3f961cd0d077ae3625027e019d1 (patch)
treea80b346e59b87012d8aa0b718b7e9a4078afc337 /Userland/Libraries/LibJS
parent2e28f0b371bb73d61f85203edd22f504e6933f5d (diff)
downloadserenity-4cb6eaf5885fa3f961cd0d077ae3625027e019d1.zip
LibJS: Convert parse_temporal_date_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/PlainDate.cpp10
3 files changed, 7 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index e173712f04..0a86a2373b 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -860,7 +860,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_ob
}
// 13.38 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring
-Optional<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, String const& iso_string)
+ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, String const& iso_string)
{
// 1. Assert: Type(isoString) is String.
@@ -869,7 +869,7 @@ Optional<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, S
// 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 TemporalDate { .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 851815915a..1af0f62b2e 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
@@ -106,7 +106,7 @@ BigInt* round_number_to_increment(GlobalObject&, BigInt const&, u64 increment, S
ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject&, String const& iso_string);
-Optional<TemporalDate> parse_temporal_date_string(GlobalObject&, String const& iso_string);
+ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject&, String const& iso_string);
Optional<ISODateTime> parse_temporal_date_time_string(GlobalObject&, String const& iso_string);
Optional<TemporalDuration> parse_temporal_duration_string(GlobalObject&, String const& iso_string);
Optional<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
index c4d71eeb2c..5729cf914a 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
@@ -139,20 +139,18 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt
return {};
// 6. Let result be ? ParseTemporalDateString(string).
- auto result = parse_temporal_date_string(global_object, string);
- if (vm.exception())
- return {};
+ auto result = TRY_OR_DISCARD(parse_temporal_date_string(global_object, string));
// 7. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
- VERIFY(is_valid_iso_date(result->year, result->month, result->day));
+ VERIFY(is_valid_iso_date(result.year, result.month, result.day));
// 8. 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 (vm.exception())
return {};
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
- return create_temporal_date(global_object, result->year, result->month, result->day, *calendar);
+ return create_temporal_date(global_object, result.year, result.month, result.day, *calendar);
}
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate