mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
LibJS: Convert parse_temporal_date_string() to ThrowCompletionOr
This commit is contained in:
parent
2e28f0b371
commit
4cb6eaf588
3 changed files with 7 additions and 9 deletions
|
@ -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
|
// 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.
|
// 1. Assert: Type(isoString) is String.
|
||||||
|
|
||||||
|
@ -869,7 +869,7 @@ Optional<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, S
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// 3. Let result be ? ParseISODateTime(isoString).
|
// 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]] }.
|
// 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) };
|
return TemporalDate { .year = result.year, .month = result.month, .day = result.day, .calendar = move(result.calendar) };
|
||||||
|
|
|
@ -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<ISODateTime> parse_iso_date_time(GlobalObject&, String const& iso_string);
|
||||||
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(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);
|
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<ISODateTime> parse_temporal_date_time_string(GlobalObject&, String const& iso_string);
|
||||||
Optional<TemporalDuration> parse_temporal_duration_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);
|
Optional<TemporalTime> parse_temporal_time_string(GlobalObject&, String const& iso_string);
|
||||||
|
|
|
@ -139,20 +139,18 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 6. Let result be ? ParseTemporalDateString(string).
|
// 6. Let result be ? ParseTemporalDateString(string).
|
||||||
auto result = parse_temporal_date_string(global_object, string);
|
auto result = TRY_OR_DISCARD(parse_temporal_date_string(global_object, string));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
// 7. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
// 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]]).
|
// 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())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
|
// 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
|
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue