diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-06 13:19:34 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-08 12:13:15 +0100 |
commit | 1edb96376b51519fe9a7aff2d281f243ca19fd45 (patch) | |
tree | 6c1cafa408e6640a02f64d1c626c796a42bc95ea /Userland/Libraries/LibWeb/SVG | |
parent | d8044c5358ab8440286f39c3d1efe2c5f39bc115 (diff) | |
download | serenity-1edb96376b51519fe9a7aff2d281f243ca19fd45.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/SVG')
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp index c5eb5e7155..11086090b7 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp @@ -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()); } } diff --git a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h index ed9f4fedbd..74ded56554 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h @@ -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); |