1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

LibJS: Make PrimitiveString::utf8_string() infallible

Work towards #20449.
This commit is contained in:
Andreas Kling 2023-08-08 19:17:55 +02:00
parent 7849950383
commit c084269e5f
29 changed files with 79 additions and 93 deletions

View file

@ -106,11 +106,11 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 8. If calendar is not undefined, then
if (!calendar.is_undefined()) {
// a. If calendar cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(TRY(calendar.as_string().utf8_string_view())))
if (!::Locale::is_type_identifier(calendar.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, calendar, "calendar"sv);
// 9. Set opt.[[ca]] to calendar.
opt.ca = TRY(calendar.as_string().utf8_string());
opt.ca = calendar.as_string().utf8_string();
}
// 10. Let numberingSystem be ? GetOption(options, "numberingSystem", string, empty, undefined).
@ -119,11 +119,11 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 11. If numberingSystem is not undefined, then
if (!numbering_system.is_undefined()) {
// a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(TRY(numbering_system.as_string().utf8_string_view())))
if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
// 12. Set opt.[[nu]] to numberingSystem.
opt.nu = TRY(numbering_system.as_string().utf8_string());
opt.nu = numbering_system.as_string().utf8_string();
}
// 13. Let hour12 be ? GetOption(options, "hour12", boolean, empty, undefined).
@ -140,7 +140,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 16. Set opt.[[hc]] to hourCycle.
if (!hour_cycle.is_nullish())
opt.hc = TRY(hour_cycle.as_string().utf8_string());
opt.hc = hour_cycle.as_string().utf8_string();
// 17. Let localeData be %DateTimeFormat%.[[LocaleData]].
// 18. Let r be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]], localeData).
@ -275,7 +275,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// d. Set formatOptions.[[<prop>]] to value.
if (!value.is_undefined()) {
option = ::Locale::calendar_pattern_style_from_string(TRY(value.as_string().utf8_string_view()));
option = ::Locale::calendar_pattern_style_from_string(value.as_string().utf8_string_view());
// e. If value is not undefined, then
// i. Set hasExplicitFormatComponents to true.
@ -294,14 +294,14 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
// 40. Set dateTimeFormat.[[DateStyle]] to dateStyle.
if (!date_style.is_undefined())
date_time_format->set_date_style(TRY(date_style.as_string().utf8_string_view()));
date_time_format->set_date_style(date_style.as_string().utf8_string_view());
// 41. Let timeStyle be ? GetOption(options, "timeStyle", string, « "full", "long", "medium", "short" », undefined).
auto time_style = TRY(get_option(vm, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
// 42. Set dateTimeFormat.[[TimeStyle]] to timeStyle.
if (!time_style.is_undefined())
date_time_format->set_time_style(TRY(time_style.as_string().utf8_string_view()));
date_time_format->set_time_style(time_style.as_string().utf8_string_view());
Optional<::Locale::CalendarPattern> best_format {};
@ -397,7 +397,7 @@ ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm,
auto formats = TRY_OR_THROW_OOM(vm, ::Locale::get_calendar_available_formats(data_locale, date_time_format->calendar()));
// g. If matcher is "basic", then
if (TRY(matcher.as_string().utf8_string_view()) == "basic"sv) {
if (matcher.as_string().utf8_string_view() == "basic"sv) {
// i. Let bestFormat be BasicFormatMatcher(formatOptions, formats).
best_format = basic_format_matcher(format_options, move(formats));
}