mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibJS: Port parse_temporal_calendar_string()
Also make is_builtin_calendar() take a StringView as part of this, it only does equality checks.
This commit is contained in:
parent
8f7c2f8292
commit
ef389c086d
4 changed files with 9 additions and 9 deletions
|
@ -1413,7 +1413,7 @@ ThrowCompletionOr<ISODateTime> parse_temporal_zoned_date_time_string(VM& vm, Str
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.31 ParseTemporalCalendarString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
|
// 13.31 ParseTemporalCalendarString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
|
||||||
ThrowCompletionOr<DeprecatedString> parse_temporal_calendar_string(VM& vm, StringView iso_string)
|
ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, StringView iso_string)
|
||||||
{
|
{
|
||||||
// 1. Let parseResult be Completion(ParseISODateTime(isoString)).
|
// 1. Let parseResult be Completion(ParseISODateTime(isoString)).
|
||||||
auto parse_result_completion = parse_iso_date_time(vm, iso_string);
|
auto parse_result_completion = parse_iso_date_time(vm, iso_string);
|
||||||
|
@ -1425,10 +1425,10 @@ ThrowCompletionOr<DeprecatedString> parse_temporal_calendar_string(VM& vm, Strin
|
||||||
|
|
||||||
// b. If calendar is undefined, return "iso8601".
|
// b. If calendar is undefined, return "iso8601".
|
||||||
if (!calendar.has_value())
|
if (!calendar.has_value())
|
||||||
return "iso8601"sv;
|
return TRY_OR_THROW_OOM(vm, String::from_utf8("iso8601"sv));
|
||||||
// c. Else, return calendar.
|
// c. Else, return calendar.
|
||||||
else
|
else
|
||||||
return calendar.release_value();
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(*calendar));
|
||||||
}
|
}
|
||||||
// 3. Else,
|
// 3. Else,
|
||||||
else {
|
else {
|
||||||
|
@ -1440,7 +1440,7 @@ ThrowCompletionOr<DeprecatedString> parse_temporal_calendar_string(VM& vm, Strin
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarString, iso_string);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarString, iso_string);
|
||||||
// c. Else, return isoString.
|
// c. Else, return isoString.
|
||||||
else
|
else
|
||||||
return iso_string;
|
return TRY_OR_THROW_OOM(vm, String::from_utf8(iso_string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, ParseResult const& parse_result);
|
ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM&, ParseResult const& parse_result);
|
||||||
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM&, StringView iso_string);
|
ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<ISODateTime> parse_temporal_zoned_date_time_string(VM&, StringView iso_string);
|
ThrowCompletionOr<ISODateTime> parse_temporal_zoned_date_time_string(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<DeprecatedString> parse_temporal_calendar_string(VM&, StringView iso_string);
|
ThrowCompletionOr<String> parse_temporal_calendar_string(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(VM&, StringView iso_string);
|
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(VM&, StringView iso_string);
|
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(VM&, StringView iso_string);
|
||||||
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM&, StringView iso_string);
|
ThrowCompletionOr<DurationRecord> parse_temporal_duration_string(VM&, StringView iso_string);
|
||||||
|
|
|
@ -34,7 +34,7 @@ Calendar::Calendar(DeprecatedString identifier, Object& prototype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.1.1 IsBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-isbuiltincalendar
|
// 12.1.1 IsBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-isbuiltincalendar
|
||||||
bool is_builtin_calendar(DeprecatedString const& identifier)
|
bool is_builtin_calendar(StringView identifier)
|
||||||
{
|
{
|
||||||
// 1. Let calendars be AvailableCalendars().
|
// 1. Let calendars be AvailableCalendars().
|
||||||
auto calendars = available_calendars();
|
auto calendars = available_calendars();
|
||||||
|
@ -463,7 +463,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
// 2. Let identifier be ? ToString(temporalCalendarLike).
|
||||||
auto identifier = TRY(temporal_calendar_like.to_deprecated_string(vm));
|
auto identifier = TRY(temporal_calendar_like.to_string(vm));
|
||||||
|
|
||||||
// 3. Set identifier to ? ParseTemporalCalendarString(identifier).
|
// 3. Set identifier to ? ParseTemporalCalendarString(identifier).
|
||||||
identifier = TRY(parse_temporal_calendar_string(vm, identifier));
|
identifier = TRY(parse_temporal_calendar_string(vm, identifier));
|
||||||
|
@ -473,7 +473,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(VM& vm, Value temporal_calendar_
|
||||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidCalendarIdentifier, identifier);
|
||||||
|
|
||||||
// 5. Return ! CreateTemporalCalendar(identifier).
|
// 5. Return ! CreateTemporalCalendar(identifier).
|
||||||
return MUST(create_temporal_calendar(vm, identifier));
|
return MUST(create_temporal_calendar(vm, identifier.to_deprecated_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.2.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
|
// 12.2.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct YearWeekRecord {
|
||||||
i32 year { 0 };
|
i32 year { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_builtin_calendar(DeprecatedString const& identifier);
|
bool is_builtin_calendar(StringView identifier);
|
||||||
Span<StringView const> available_calendars();
|
Span<StringView const> available_calendars();
|
||||||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr);
|
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr);
|
||||||
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM&, DeprecatedString const& identifier);
|
ThrowCompletionOr<Calendar*> get_builtin_calendar(VM&, DeprecatedString const& identifier);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue