1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibJS: Convert parse_temporal_instant_string() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-09-16 17:48:04 +01:00
parent 3112de6f35
commit 4f487266b4
3 changed files with 7 additions and 9 deletions

View file

@ -796,7 +796,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
} }
// 13.35 ParseTemporalInstantString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalinstantstring // 13.35 ParseTemporalInstantString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalinstantstring
Optional<TemporalInstant> parse_temporal_instant_string(GlobalObject& global_object, String const& iso_string) ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject& global_object, String const& iso_string)
{ {
auto& vm = global_object.vm(); auto& vm = global_object.vm();
@ -811,8 +811,8 @@ Optional<TemporalInstant> parse_temporal_instant_string(GlobalObject& global_obj
// 4. Let timeZoneResult be ? ParseTemporalTimeZoneString(isoString). // 4. Let timeZoneResult be ? ParseTemporalTimeZoneString(isoString).
auto time_zone_result = parse_temporal_time_zone_string(global_object, iso_string); auto time_zone_result = parse_temporal_time_zone_string(global_object, iso_string);
if (vm.exception()) if (auto* exception = vm.exception())
return {}; return throw_completion(exception->value());
// 5. Let offsetString be timeZoneResult.[[OffsetString]]. // 5. Let offsetString be timeZoneResult.[[OffsetString]].
auto offset_string = time_zone_result->offset; auto offset_string = time_zone_result->offset;

View file

@ -104,7 +104,7 @@ String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u
double constrain_to_range(double x, double minimum, double maximum); double constrain_to_range(double x, double minimum, double maximum);
BigInt* round_number_to_increment(GlobalObject&, BigInt const&, u64 increment, StringView rounding_mode); BigInt* round_number_to_increment(GlobalObject&, BigInt const&, u64 increment, StringView rounding_mode);
ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject&, String const& iso_string); ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject&, String const& iso_string);
Optional<TemporalInstant> parse_temporal_instant_string(GlobalObject&, String const& iso_string); ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject&, String const& iso_string);
Optional<String> parse_temporal_calendar_string(GlobalObject&, String const& iso_string); Optional<String> parse_temporal_calendar_string(GlobalObject&, String const& iso_string);
Optional<TemporalDate> parse_temporal_date_string(GlobalObject&, String const& iso_string); Optional<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);

View file

@ -112,18 +112,16 @@ BigInt* parse_temporal_instant(GlobalObject& global_object, String const& iso_st
// 1. Assert: Type(isoString) is String. // 1. Assert: Type(isoString) is String.
// 2. Let result be ? ParseTemporalInstantString(isoString). // 2. Let result be ? ParseTemporalInstantString(isoString).
auto result = parse_temporal_instant_string(global_object, iso_string); auto result = TRY_OR_DISCARD(parse_temporal_instant_string(global_object, iso_string));
if (vm.exception())
return {};
// 3. Let offsetString be result.[[TimeZoneOffsetString]]. // 3. Let offsetString be result.[[TimeZoneOffsetString]].
auto& offset_string = result->time_zone_offset; auto& offset_string = result.time_zone_offset;
// 4. Assert: offsetString is not undefined. // 4. Assert: offsetString is not undefined.
VERIFY(offset_string.has_value()); VERIFY(offset_string.has_value());
// 5. Let utc be ? GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]). // 5. Let utc be ? GetEpochFromISOParts(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
auto* utc = get_epoch_from_iso_parts(global_object, result->year, result->month, result->day, result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond); auto* utc = get_epoch_from_iso_parts(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond);
if (vm.exception()) if (vm.exception())
return {}; return {};