diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-07-14 23:32:18 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-17 16:24:57 +0430 |
commit | e8e9426b4fcf6042b7658a805eabe9b2012d6769 (patch) | |
tree | 949d63733e90bc553cdbc8d3f24241704725a287 /Userland/Libraries/LibWeb | |
parent | f886aa15b8665e0bb0e886506aa492c99347f1f7 (diff) | |
download | serenity-e8e9426b4fcf6042b7658a805eabe9b2012d6769.zip |
LibWeb: User getter and setter for Comment type HTMLTokens
Diffstat (limited to 'Userland/Libraries/LibWeb')
3 files changed, 25 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 22e27a3f43..67b6b499df 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -317,7 +317,7 @@ void HTMLDocumentParser::handle_initial(HTMLToken& token) } if (token.is_comment()) { - auto comment = adopt_ref(*new DOM::Comment(document(), token.m_comment_or_character.data)); + auto comment = adopt_ref(*new DOM::Comment(document(), token.comment())); document().append_child(move(comment)); return; } @@ -347,7 +347,7 @@ void HTMLDocumentParser::handle_before_html(HTMLToken& token) } if (token.is_comment()) { - auto comment = adopt_ref(*new DOM::Comment(document(), token.m_comment_or_character.data)); + auto comment = adopt_ref(*new DOM::Comment(document(), token.comment())); document().append_child(move(comment)); return; } @@ -520,9 +520,8 @@ AnythingElse: void HTMLDocumentParser::insert_comment(HTMLToken& token) { - auto data = token.m_comment_or_character.data; auto adjusted_insertion_location = find_appropriate_place_for_inserting_node(); - adjusted_insertion_location.parent->insert_before(adopt_ref(*new DOM::Comment(document(), data)), adjusted_insertion_location.insert_before_sibling); + adjusted_insertion_location.parent->insert_before(adopt_ref(*new DOM::Comment(document(), token.comment())), adjusted_insertion_location.insert_before_sibling); } void HTMLDocumentParser::handle_in_head(HTMLToken& token) @@ -832,9 +831,8 @@ void HTMLDocumentParser::handle_after_body(HTMLToken& token) } if (token.is_comment()) { - auto data = token.m_comment_or_character.data; auto& insertion_location = m_stack_of_open_elements.first(); - insertion_location.append_child(adopt_ref(*new DOM::Comment(document(), data))); + insertion_location.append_child(adopt_ref(*new DOM::Comment(document(), token.comment()))); return; } @@ -870,7 +868,7 @@ void HTMLDocumentParser::handle_after_body(HTMLToken& token) void HTMLDocumentParser::handle_after_after_body(HTMLToken& token) { if (token.is_comment()) { - auto comment = adopt_ref(*new DOM::Comment(document(), token.m_comment_or_character.data)); + auto comment = adopt_ref(*new DOM::Comment(document(), token.comment())); document().append_child(move(comment)); return; } @@ -2751,7 +2749,7 @@ void HTMLDocumentParser::handle_after_frameset(HTMLToken& token) void HTMLDocumentParser::handle_after_after_frameset(HTMLToken& token) { if (token.is_comment()) { - auto comment = adopt_ref(*new DOM::Comment(document(), token.m_comment_or_character.data)); + auto comment = adopt_ref(*new DOM::Comment(document(), token.comment())); document().append_child(move(comment)); return; } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h index 568bf25035..74cf4bb359 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h @@ -97,6 +97,18 @@ public: } } + String const& comment() const + { + VERIFY(is_comment()); + return m_comment_or_character.data; + } + + void set_comment(String comment) + { + VERIFY(is_comment()); + m_comment_or_character.data = move(comment); + } + String tag_name() const { VERIFY(is_start_tag() || is_end_tag()); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index c69d6c6259..2644c9dd3c 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -406,7 +406,7 @@ _StartOfFunction: { ON('>') { - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); } ON_EOF @@ -1392,7 +1392,7 @@ _StartOfFunction: ON_EOF { log_parse_error(); - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); EMIT_CURRENT_TOKEN; EMIT_EOF; } @@ -1408,7 +1408,7 @@ _StartOfFunction: { ON('>') { - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); } ON('!') @@ -1423,7 +1423,7 @@ _StartOfFunction: ON_EOF { log_parse_error(); - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); EMIT_CURRENT_TOKEN; EMIT_EOF; } @@ -1445,13 +1445,13 @@ _StartOfFunction: ON('>') { log_parse_error(); - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); } ON_EOF { log_parse_error(); - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); EMIT_CURRENT_TOKEN; EMIT_EOF; } @@ -1472,7 +1472,7 @@ _StartOfFunction: ON_EOF { log_parse_error(); - m_current_token.m_comment_or_character.data = consume_current_builder(); + m_current_token.set_comment(consume_current_builder()); EMIT_CURRENT_TOKEN; EMIT_EOF; } |