1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

LibUnicode+LibJS+LibWeb: Propagate OOM from Unicode case transformations

This commit is contained in:
Timothy Flynn 2023-01-08 10:15:05 -05:00 committed by Linus Groh
parent 48474b0de6
commit 1ff29afc45
5 changed files with 91 additions and 91 deletions

View file

@ -916,13 +916,13 @@ static ThrowCompletionOr<DeprecatedString> transform_case(VM& vm, StringView str
// 9. If targetCase is lower, then
case TargetCase::Lower:
// a. Let newCodePoints be a List whose elements are the result of a lowercase transformation of codePoints according to an implementation-derived algorithm using locale or the Unicode Default Case Conversion algorithm.
new_code_points = Unicode::to_unicode_lowercase_full(string, *locale);
new_code_points = TRY_OR_THROW_OOM(vm, Unicode::to_unicode_lowercase_full(string, *locale));
break;
// 10. Else,
case TargetCase::Upper:
// a. Assert: targetCase is upper.
// b. Let newCodePoints be a List whose elements are the result of an uppercase transformation of codePoints according to an implementation-derived algorithm using locale or the Unicode Default Case Conversion algorithm.
new_code_points = Unicode::to_unicode_uppercase_full(string, *locale);
new_code_points = TRY_OR_THROW_OOM(vm, Unicode::to_unicode_uppercase_full(string, *locale));
break;
default:
VERIFY_NOT_REACHED();
@ -964,7 +964,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_locale_uppercase)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
{
auto string = TRY(ak_string_from(vm));
auto lowercase = Unicode::to_unicode_lowercase_full(string);
auto lowercase = TRY_OR_THROW_OOM(vm, Unicode::to_unicode_lowercase_full(string));
return PrimitiveString::create(vm, move(lowercase));
}
@ -978,7 +978,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_string)
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
{
auto string = TRY(ak_string_from(vm));
auto uppercase = Unicode::to_unicode_uppercase_full(string);
auto uppercase = TRY_OR_THROW_OOM(vm, Unicode::to_unicode_uppercase_full(string));
return PrimitiveString::create(vm, move(uppercase));
}

View file

@ -221,7 +221,7 @@ u32 __attribute__((weak)) to_unicode_uppercase(u32 code_point)
return to_ascii_uppercase(code_point);
}
DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
ErrorOr<DeprecatedString> to_unicode_lowercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
{
#if ENABLE_UNICODE_DATA
Utf8View view { string };
@ -236,12 +236,12 @@ DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] O
auto const* special_casing = find_matching_special_case(code_point, view, locale, index, byte_length);
if (!special_casing) {
builder.append_code_point(to_unicode_lowercase(code_point));
TRY(builder.try_append_code_point(to_unicode_lowercase(code_point)));
continue;
}
for (size_t i = 0; i < special_casing->lowercase_mapping_size; ++i)
builder.append_code_point(special_casing->lowercase_mapping[i]);
TRY(builder.try_append_code_point(special_casing->lowercase_mapping[i]));
}
return builder.build();
@ -250,7 +250,7 @@ DeprecatedString to_unicode_lowercase_full(StringView string, [[maybe_unused]] O
#endif
}
DeprecatedString to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
ErrorOr<DeprecatedString> to_unicode_uppercase_full(StringView string, [[maybe_unused]] Optional<StringView> locale)
{
#if ENABLE_UNICODE_DATA
Utf8View view { string };
@ -265,12 +265,12 @@ DeprecatedString to_unicode_uppercase_full(StringView string, [[maybe_unused]] O
auto const* special_casing = find_matching_special_case(code_point, view, locale, index, byte_length);
if (!special_casing) {
builder.append_code_point(to_unicode_uppercase(code_point));
TRY(builder.try_append_code_point(to_unicode_uppercase(code_point)));
continue;
}
for (size_t i = 0; i < special_casing->uppercase_mapping_size; ++i)
builder.append_code_point(special_casing->uppercase_mapping[i]);
TRY(builder.try_append_code_point(special_casing->uppercase_mapping[i]));
}
return builder.build();

View file

@ -39,8 +39,8 @@ Span<SpecialCasing const* const> special_case_mapping(u32 code_point);
u32 to_unicode_lowercase(u32 code_point);
u32 to_unicode_uppercase(u32 code_point);
DeprecatedString to_unicode_lowercase_full(StringView, Optional<StringView> locale = {});
DeprecatedString to_unicode_uppercase_full(StringView, Optional<StringView> locale = {});
ErrorOr<DeprecatedString> to_unicode_lowercase_full(StringView, Optional<StringView> locale = {});
ErrorOr<DeprecatedString> to_unicode_uppercase_full(StringView, Optional<StringView> locale = {});
Optional<GeneralCategory> general_category_from_string(StringView);
bool code_point_has_general_category(u32 code_point, GeneralCategory general_category);

View file

@ -32,7 +32,7 @@ static bool is_all_whitespace(StringView string)
return true;
}
static DeprecatedString apply_text_transform(DeprecatedString const& string, CSS::TextTransform text_transform)
static ErrorOr<DeprecatedString> apply_text_transform(DeprecatedString const& string, CSS::TextTransform text_transform)
{
if (text_transform == CSS::TextTransform::Uppercase)
return Unicode::to_unicode_uppercase_full(string);
@ -44,7 +44,7 @@ static DeprecatedString apply_text_transform(DeprecatedString const& string, CSS
// NOTE: This collapses whitespace into a single ASCII space if collapse is true.
void TextNode::compute_text_for_rendering(bool collapse)
{
auto data = apply_text_transform(dom_node().data(), computed_values().text_transform());
auto data = apply_text_transform(dom_node().data(), computed_values().text_transform()).release_value_but_fixme_should_propagate_errors();
if (dom_node().is_password_input()) {
m_text_for_rendering = DeprecatedString::repeated('*', data.length());