summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-04-12 16:05:44 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-12 23:03:46 +0200
commitf235da27d99d537ae4945d4e2d1b3c313dd9318d (patch)
treec5fd8eb0fe58d210c1b9c841011d1e27cfb65555
parent7128e8e2e6cbe4793260c65f2ba8e150a117f529 (diff)
downloadserenity-f235da27d99d537ae4945d4e2d1b3c313dd9318d.zip
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.
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Block.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Block.h10
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp11
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp2
4 files changed, 14 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Block.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Block.cpp
index 87fba27fc1..b408c98970 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Block.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Block.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Block.h b/Userland/Libraries/LibWeb/CSS/Parser/Block.h
index 2ea17f0d9d..729b86f4a2 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Block.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Block.h
@@ -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;
};
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 624f2b8723..efebe42283 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -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));
}
}
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index a65e94cb4b..590d38032d 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -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;
}