LibWeb: Replace is<T>() with as_if<T>() where possible
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This commit is contained in:
Tim Ledbetter 2025-08-25 07:22:57 +01:00 committed by Jelle Raaijmakers
commit cb1a1a5cb5
Notes: github-actions[bot] 2025-08-25 16:46:19 +00:00
26 changed files with 92 additions and 109 deletions

View file

@ -215,11 +215,12 @@ static void merge_with_the_next_text_node(DOM::Text& node)
auto next = node.next_sibling();
// 2. If next is not a Text node, then return.
if (!is<DOM::Text>(next))
auto* text = as_if<DOM::Text>(next);
if (!text)
return;
// 3. Replace data with node, node's data's length, 0, and next's data.
MUST(node.replace_data(node.length_in_utf16_code_units(), 0, static_cast<DOM::Text const&>(*next).data()));
MUST(node.replace_data(node.length_in_utf16_code_units(), 0, text->data()));
// 4. Remove next.
next->remove();
@ -253,8 +254,8 @@ WebIDL::ExceptionOr<void> HTMLElement::set_outer_text(Utf16View const& value)
merge_with_the_next_text_node(static_cast<DOM::Text&>(*next->previous_sibling()));
// 8. If previous is a Text node, then merge with the next text node given previous.
if (is<DOM::Text>(previous))
merge_with_the_next_text_node(static_cast<DOM::Text&>(*previous));
if (auto* previous_text = as_if<DOM::Text>(previous))
merge_with_the_next_text_node(*previous_text);
set_needs_style_update(true);
return {};
@ -842,7 +843,8 @@ GC::Ptr<DOM::NodeList> HTMLElement::labels()
if (!m_labels) {
m_labels = DOM::LiveNodeList::create(realm(), root(), DOM::LiveNodeList::Scope::Descendants, [&](auto& node) {
return is<HTMLLabelElement>(node) && as<HTMLLabelElement>(node).control() == this;
auto* label_element = as_if<HTMLLabelElement>(node);
return label_element && label_element->control() == this;
});
}