1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 03:52:12 +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:
Sam Atkins 2022-04-12 16:05:44 +01:00 committed by Andreas Kling
parent 7128e8e2e6
commit f235da27d9
4 changed files with 14 additions and 11 deletions

View file

@ -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));
}
}
}