mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:47:42 +00:00
LibWeb: Break friendship between CSS Block and Parser
This means deviating a little from the spec, so that we create a complete Block in one go instead of creating an empty one and then poking at its internals.
This commit is contained in:
parent
7128e8e2e6
commit
f235da27d9
4 changed files with 14 additions and 11 deletions
|
@ -9,12 +9,12 @@
|
|||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
Block::Block() = default;
|
||||
Block::Block(Token token, Vector<ComponentValue>&& values)
|
||||
: m_token(move(token))
|
||||
, m_values(move(values))
|
||||
{
|
||||
}
|
||||
|
||||
Block::~Block() = default;
|
||||
|
||||
String Block::to_string() const
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
namespace Web::CSS::Parser {
|
||||
|
||||
class Block : public RefCounted<Block> {
|
||||
friend class Parser;
|
||||
|
||||
public:
|
||||
Block();
|
||||
Block(Token, Vector<ComponentValue>&&);
|
||||
static NonnullRefPtr<Block> create(Token token, Vector<ComponentValue>&& values)
|
||||
{
|
||||
return adopt_ref(*new Block(move(token), move(values)));
|
||||
}
|
||||
|
||||
~Block();
|
||||
|
||||
bool is_curly() const { return m_token.is(Token::Type::OpenCurly); }
|
||||
|
@ -34,6 +35,7 @@ public:
|
|||
String to_string() const;
|
||||
|
||||
private:
|
||||
Block(Token, Vector<ComponentValue>&&);
|
||||
Token m_token;
|
||||
Vector<ComponentValue> m_values;
|
||||
};
|
||||
|
|
|
@ -1834,8 +1834,9 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
|||
|
||||
// Create a simple block with its associated token set to the current input token
|
||||
// and with its value initially set to an empty list.
|
||||
auto block = make_ref_counted<Block>();
|
||||
block->m_token = tokens.current_token();
|
||||
// NOTE: We create the Block fully initialized when we return it instead.
|
||||
Token block_token = tokens.current_token();
|
||||
Vector<ComponentValue> block_values;
|
||||
|
||||
// Repeatedly consume the next input token and process it as follows:
|
||||
for (;;) {
|
||||
|
@ -1844,13 +1845,13 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
|||
// ending token
|
||||
if (token.is(ending_token)) {
|
||||
// Return the block.
|
||||
return block;
|
||||
return Block::create(move(block_token), move(block_values));
|
||||
}
|
||||
// <EOF-token>
|
||||
if (token.is(Token::Type::EndOfFile)) {
|
||||
// This is a parse error. Return the block.
|
||||
log_parse_error();
|
||||
return block;
|
||||
return Block::create(move(block_token), move(block_values));
|
||||
}
|
||||
|
||||
// anything else
|
||||
|
@ -1859,7 +1860,7 @@ NonnullRefPtr<Block> Parser::consume_a_simple_block(TokenStream<T>& tokens)
|
|||
tokens.reconsume_current_input_token();
|
||||
|
||||
// Consume a component value and append it to the value of the block.
|
||||
block->m_values.append(consume_a_component_value(tokens));
|
||||
block_values.empend(consume_a_component_value(tokens));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -631,7 +631,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
|
|||
Vector<Parser::ComponentValue> block_values;
|
||||
if (!expand_unresolved_values(element, property_name, dependencies, source_block.values(), block_values, 0))
|
||||
return false;
|
||||
NonnullRefPtr<Parser::Block> block = adopt_ref(*new Parser::Block(source_block.token(), move(block_values)));
|
||||
NonnullRefPtr<Parser::Block> block = Parser::Block::create(source_block.token(), move(block_values));
|
||||
dest.empend(move(block));
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue