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

AK+Everywhere: Make UTF-8 and UTF-32 to UTF-16 converters fallible

These could fail to allocate the underlying storage needed to store the
UTF-16 data. Propagate these errors.
This commit is contained in:
Timothy Flynn 2023-01-06 13:19:34 -05:00 committed by Linus Groh
parent d8044c5358
commit 1edb96376b
13 changed files with 46 additions and 35 deletions

View file

@ -34,8 +34,8 @@ DeprecatedString strip_and_collapse_whitespace(StringView string)
// https://infra.spec.whatwg.org/#code-unit-prefix
bool is_code_unit_prefix(StringView potential_prefix, StringView input)
{
auto potential_prefix_utf16 = utf8_to_utf16(potential_prefix);
auto input_utf16 = utf8_to_utf16(input);
auto potential_prefix_utf16 = utf8_to_utf16(potential_prefix).release_value_but_fixme_should_propagate_errors();
auto input_utf16 = utf8_to_utf16(input).release_value_but_fixme_should_propagate_errors();
// 1. Let i be 0.
size_t i = 0;

View file

@ -5,6 +5,8 @@
*/
#include <AK/Utf16View.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Utf16String.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/SVG/SVGTextContentElement.h>
@ -17,9 +19,10 @@ SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::Quali
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars
int SVGTextContentElement::get_number_of_chars() const
WebIDL::ExceptionOr<int> SVGTextContentElement::get_number_of_chars() const
{
return AK::utf8_to_utf16(child_text_content()).size();
auto chars = TRY_OR_THROW_OOM(vm(), utf8_to_utf16(child_text_content()));
return static_cast<int>(chars.size());
}
}

View file

@ -7,6 +7,7 @@
#pragma once
#include <LibWeb/SVG/SVGGraphicsElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::SVG {
@ -15,7 +16,7 @@ class SVGTextContentElement : public SVGGraphicsElement {
WEB_PLATFORM_OBJECT(SVGTextContentElement, SVGGraphicsElement);
public:
int get_number_of_chars() const;
WebIDL::ExceptionOr<int> get_number_of_chars() const;
protected:
SVGTextContentElement(DOM::Document&, DOM::QualifiedName);