LibWeb: Break friendship between CSS Function and Parser

Again, this means deviating from the spec by creating a complete
Function in one go instead of creating it empty and then poking at its
internals.
This commit is contained in:
Sam Atkins 2022-04-12 16:44:02 +01:00 committed by Andreas Kling
parent 7d67e428a6
commit d67e817d8e
Notes: sideshowbarker 2024-07-17 11:51:39 +09:00
4 changed files with 14 additions and 14 deletions

View file

@ -10,11 +10,6 @@
namespace Web::CSS::Parser {
Function::Function(FlyString name)
: m_name(move(name))
{
}
Function::Function(FlyString name, Vector<ComponentValue>&& values)
: m_name(move(name))
, m_values(move(values))

View file

@ -17,11 +17,12 @@
namespace Web::CSS::Parser {
class Function : public RefCounted<Function> {
friend class Parser;
public:
explicit Function(FlyString name);
Function(FlyString name, Vector<ComponentValue>&& values);
static NonnullRefPtr<Function> create(FlyString name, Vector<ComponentValue>&& values)
{
return adopt_ref(*new Function(move(name), move(values)));
}
~Function();
StringView name() const { return m_name; }
@ -30,6 +31,8 @@ public:
String to_string() const;
private:
Function(FlyString name, Vector<ComponentValue>&& values);
FlyString m_name;
Vector<ComponentValue> m_values;
};

View file

@ -1878,7 +1878,9 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& 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.
auto function = make_ref_counted<Function>(((Token)name_ident).function());
// NOTE: We create the Function fully initialized when we return it instead.
FlyString function_name = ((Token)name_ident).function();
Vector<ComponentValue> function_values;
// Repeatedly consume the next input token and process it as follows:
for (;;) {
@ -1887,14 +1889,14 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
// <)-token>
if (token.is(Token::Type::CloseParen)) {
// Return the function.
return function;
return Function::create(move(function_name), move(function_values));
}
// <EOF-token>
if (token.is(Token::Type::EndOfFile)) {
// This is a parse error. Return the function.
log_parse_error();
return function;
return Function::create(move(function_name), move(function_values));
}
// anything else
@ -1903,7 +1905,7 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
tokens.reconsume_current_input_token();
// Consume a component value and append the returned value to the functions value.
function->m_values.append(consume_a_component_value(tokens));
function_values.append(consume_a_component_value(tokens));
}
}
}

View file

@ -622,7 +622,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
Vector<Parser::ComponentValue> function_values;
if (!expand_unresolved_values(element, property_name, dependencies, source_function.values(), function_values, 0))
return false;
NonnullRefPtr<Parser::Function> function = adopt_ref(*new Parser::Function(source_function.name(), move(function_values)));
NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values));
dest.empend(function);
continue;
}