LibJS: Convert parse_temporal_year_month_string() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-09-16 17:59:54 +01:00
parent 14f16d9ed4
commit 2f56fd48ca
3 changed files with 6 additions and 8 deletions

View file

@ -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) };

View file

@ -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);

View file

@ -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);