diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp index 9b9a4adca4..2505db04e7 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp @@ -31,7 +31,7 @@ DeprecatedString ComponentValue::to_deprecated_string() const return m_value.visit( [](Token const& token) { return token.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }, [](NonnullRefPtr const& block) { return block->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }, - [](NonnullRefPtr const& function) { return function->to_deprecated_string(); }); + [](NonnullRefPtr const& function) { return function->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }); } ErrorOr ComponentValue::to_debug_string() const @@ -44,7 +44,7 @@ ErrorOr ComponentValue::to_debug_string() const return String::formatted("Block: {}", TRY(block->to_string())); }, [](NonnullRefPtr const& function) -> ErrorOr { - return String::formatted("Function: {}", function->to_deprecated_string()); + return String::formatted("Function: {}", TRY(function->to_string())); }); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp index 8d4a06c139..e5e8a935ab 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2022, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,7 +10,7 @@ namespace Web::CSS::Parser { -Function::Function(DeprecatedFlyString name, Vector&& values) +Function::Function(FlyString name, Vector&& values) : m_name(move(name)) , m_values(move(values)) { @@ -18,16 +18,16 @@ Function::Function(DeprecatedFlyString name, Vector&& values) Function::~Function() = default; -DeprecatedString Function::to_deprecated_string() const +ErrorOr Function::to_string() const { StringBuilder builder; serialize_an_identifier(builder, m_name); - builder.append('('); - builder.join(' ', m_values); - builder.append(')'); + TRY(builder.try_append('(')); + TRY(builder.try_join(' ', m_values)); + TRY(builder.try_append(')')); - return builder.to_deprecated_string(); + return builder.to_string(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.h b/Userland/Libraries/LibWeb/CSS/Parser/Function.h index 6eb161bbc8..88928b7b49 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.h @@ -1,15 +1,15 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2022, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include -#include +#include #include +#include #include #include #include @@ -18,7 +18,7 @@ namespace Web::CSS::Parser { class Function : public RefCounted { public: - static NonnullRefPtr create(DeprecatedFlyString name, Vector&& values) + static NonnullRefPtr create(FlyString name, Vector&& values) { return adopt_ref(*new Function(move(name), move(values))); } @@ -28,12 +28,12 @@ public: StringView name() const { return m_name; } Vector const& values() const { return m_values; } - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; private: - Function(DeprecatedFlyString name, Vector&& values); + Function(FlyString name, Vector&& values); - DeprecatedFlyString m_name; + FlyString m_name; Vector m_values; }; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index f264d30c24..e433e50ad2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1801,7 +1801,7 @@ NonnullRefPtr Parser::consume_a_function(TokenStream& tokens) // Create a function with its name equal to the value of the current input token // and with its value initially set to an empty list. // NOTE: We create the Function fully initialized when we return it instead. - DeprecatedFlyString function_name = ((Token)name_ident).function(); + auto function_name = FlyString::from_utf8(((Token)name_ident).function()).release_value_but_fixme_should_propagate_errors(); Vector function_values; // Repeatedly consume the next input token and process it as follows: diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index a672475399..4dbb41256a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -628,7 +628,7 @@ bool StyleComputer::expand_variables(DOM::Element& element, StringView property_ Parser::TokenStream source_function_contents { source_function.values() }; if (!expand_variables(element, property_name, dependencies, source_function_contents, function_values)) return false; - NonnullRefPtr function = Parser::Function::create(source_function.name(), move(function_values)); + NonnullRefPtr function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); dest.empend(function); continue; } @@ -750,7 +750,8 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p Parser::TokenStream source_function_contents { source_function.values() }; if (!expand_unresolved_values(element, property_name, source_function_contents, function_values)) return false; - NonnullRefPtr function = Parser::Function::create(source_function.name(), move(function_values)); + // FIXME: This would be much nicer if we could access the source_function's FlyString value directly. + NonnullRefPtr function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); dest.empend(function); continue; }