1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:47:35 +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

@ -27,7 +27,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
auto usage = TRY(get_option(vm, *options, vm.names.usage, OptionType::String, { "sort"sv, "search"sv }, "sort"sv));
// 4. Set collator.[[Usage]] to usage.
collator.set_usage(TRY(usage.as_string().utf8_string_view()));
collator.set_usage(usage.as_string().utf8_string_view());
// 5. If usage is "sort", then
// a. Let localeData be %Collator%.[[SortLocaleData]].
@ -49,11 +49,11 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 11. If collation is not undefined, then
if (!collation.is_undefined()) {
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!::Locale::is_type_identifier(TRY(collation.as_string().utf8_string_view())))
if (!::Locale::is_type_identifier(collation.as_string().utf8_string_view()))
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, collation, "collation"sv);
// 12. Set opt.[[co]] to collation.
opt.co = TRY(collation.as_string().utf8_string());
opt.co = collation.as_string().utf8_string();
}
// 13. Let numeric be ? GetOption(options, "numeric", boolean, empty, undefined).
@ -69,7 +69,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 17. Set opt.[[kf]] to caseFirst.
auto case_first = TRY(get_option(vm, *options, vm.names.caseFirst, OptionType::String, { "upper"sv, "lower"sv, "false"sv }, Empty {}));
if (!case_first.is_undefined())
opt.kf = TRY(case_first.as_string().utf8_string());
opt.kf = case_first.as_string().utf8_string();
// 18. Let relevantExtensionKeys be %Collator%.[[RelevantExtensionKeys]].
auto relevant_extension_keys = Collator::relevant_extension_keys();
@ -117,7 +117,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
}
// 28. Set collator.[[Sensitivity]] to sensitivity.
collator.set_sensitivity(TRY(sensitivity.as_string().utf8_string_view()));
collator.set_sensitivity(sensitivity.as_string().utf8_string_view());
// 29. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", boolean, empty, false).
auto ignore_punctuation = TRY(get_option(vm, *options, vm.names.ignorePunctuation, OptionType::Boolean, {}, false));