mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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:
parent
7d67e428a6
commit
d67e817d8e
Notes:
sideshowbarker
2024-07-17 11:51:39 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/d67e817d8e Pull-request: https://github.com/SerenityOS/serenity/pull/13643
4 changed files with 14 additions and 14 deletions
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 function’s value.
|
||||
function->m_values.append(consume_a_component_value(tokens));
|
||||
function_values.append(consume_a_component_value(tokens));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue