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

AK+Everywhere: Make UTF-16 to UTF-8 converter fallible

This could fail to allocate the underlying storage needed to store the
UTF-8 data. Propagate this error.
This commit is contained in:
Timothy Flynn 2023-01-07 13:59:10 -05:00 committed by Linus Groh
parent 1edb96376b
commit d793262beb
10 changed files with 25 additions and 22 deletions

View file

@ -6,6 +6,7 @@
#include <AK/StringView.h>
#include <LibJS/Runtime/Utf16String.h>
#include <LibJS/Runtime/VM.h>
namespace JS {
namespace Detail {
@ -96,9 +97,9 @@ Utf16View Utf16String::substring_view(size_t code_unit_offset) const
return view().substring_view(code_unit_offset);
}
DeprecatedString Utf16String::to_utf8() const
ThrowCompletionOr<DeprecatedString> Utf16String::to_utf8(VM& vm) const
{
return view().to_utf8(Utf16View::AllowInvalidCodeUnits::Yes);
return TRY_OR_THROW_OOM(vm, view().to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
}
u16 Utf16String::code_unit_at(size_t index) const