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

@ -477,9 +477,8 @@ GC::Ref<WebIDL::Promise> FontFace::load()
// FIXME: We should probably put the 'font cache' on the WindowOrWorkerGlobalScope instead of tying it to the document's style computer // FIXME: We should probably put the 'font cache' on the WindowOrWorkerGlobalScope instead of tying it to the document's style computer
auto& global = HTML::relevant_global_object(*font); auto& global = HTML::relevant_global_object(*font);
if (is<HTML::Window>(global)) { if (auto* window = as_if<HTML::Window>(global)) {
auto& window = static_cast<HTML::Window&>(global); auto& style_computer = const_cast<StyleComputer&>(window->document()->style_computer());
auto& style_computer = const_cast<StyleComputer&>(window.document()->style_computer());
// FIXME: The ParsedFontFace is kind of expensive to create. We should be using a shared sub-object for the data // FIXME: The ParsedFontFace is kind of expensive to create. We should be using a shared sub-object for the data
ParsedFontFace parsed_font_face { ParsedFontFace parsed_font_face {

View file

@ -638,8 +638,8 @@ RefPtr<StyleValue const> interpolate_transform(DOM::Element& element, StyleValue
return {}; return {};
Optional<Painting::PaintableBox const&> paintable_box; Optional<Painting::PaintableBox const&> paintable_box;
if (auto layout_node = element.layout_node()) { if (auto layout_node = element.layout_node()) {
if (auto paintable = layout_node->first_paintable(); paintable && is<Painting::PaintableBox>(paintable)) if (auto* paintable = as_if<Painting::PaintableBox>(layout_node->first_paintable()))
paintable_box = *static_cast<Painting::PaintableBox*>(paintable); paintable_box = *paintable;
} }
if (auto matrix = transformation->to_matrix(paintable_box); !matrix.is_error()) if (auto matrix = transformation->to_matrix(paintable_box); !matrix.is_error())
return matrix.value(); return matrix.value();

View file

@ -508,7 +508,7 @@ bool StyleComputer::invalidation_property_used_in_has_selector(InvalidationSet::
Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::Element const& element, CascadeOrigin cascade_origin, Optional<CSS::PseudoElement> pseudo_element, PseudoClassBitmap& attempted_pseudo_class_matches, Optional<FlyString const> qualified_layer_name) const Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::Element const& element, CascadeOrigin cascade_origin, Optional<CSS::PseudoElement> pseudo_element, PseudoClassBitmap& attempted_pseudo_class_matches, Optional<FlyString const> qualified_layer_name) const
{ {
auto const& root_node = element.root(); auto const& root_node = element.root();
auto shadow_root = is<DOM::ShadowRoot>(root_node) ? static_cast<DOM::ShadowRoot const*>(&root_node) : nullptr; auto shadow_root = as_if<DOM::ShadowRoot>(root_node);
auto element_shadow_root = element.shadow_root(); auto element_shadow_root = element.shadow_root();
auto const& element_namespace_uri = element.namespace_uri(); auto const& element_namespace_uri = element.namespace_uri();

View file

@ -897,9 +897,8 @@ MatchResult does_element_match_source_list_for_type_and_source(GC::Ptr<DOM::Elem
VERIFY(is<HTML::HTMLElement>(element.ptr()) || is<SVG::SVGElement>(element.ptr())); VERIFY(is<HTML::HTMLElement>(element.ptr()) || is<SVG::SVGElement>(element.ptr()));
String element_nonce; String element_nonce;
if (is<HTML::HTMLElement>(element.ptr())) { if (auto* html_element = as_if<HTML::HTMLElement>(element.ptr())) {
auto const& html_element = static_cast<HTML::HTMLElement const&>(*element); element_nonce = html_element->nonce();
element_nonce = html_element.nonce();
} else { } else {
auto const& svg_element = as<SVG::SVGElement>(*element); auto const& svg_element = as<SVG::SVGElement>(*element);
element_nonce = svg_element.nonce(); element_nonce = svg_element.nonce();

View file

@ -117,9 +117,10 @@ static JS::ThrowCompletionOr<CryptoKeyPair*> impl_from(JS::VM& vm)
else else
this_object = TRY(this_value.to_object(vm)); this_object = TRY(this_value.to_object(vm));
if (!is<CryptoKeyPair>(this_object)) auto* crypto_key_pair = as_if<CryptoKeyPair>(this_object);
if (!crypto_key_pair)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "CryptoKeyPair"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "CryptoKeyPair");
return static_cast<CryptoKeyPair*>(this_object); return crypto_key_pair;
} }
JS_DEFINE_NATIVE_FUNCTION(CryptoKeyPair::public_key_getter) JS_DEFINE_NATIVE_FUNCTION(CryptoKeyPair::public_key_getter)

View file

@ -904,9 +904,7 @@ HTML::HTMLHtmlElement* Document::html_element()
{ {
// The html element of a document is its document element, if it's an html element, and null otherwise. // The html element of a document is its document element, if it's an html element, and null otherwise.
auto* html = document_element(); auto* html = document_element();
if (is<HTML::HTMLHtmlElement>(html)) return as_if<HTML::HTMLHtmlElement>(html);
return as<HTML::HTMLHtmlElement>(html);
return nullptr;
} }
// https://html.spec.whatwg.org/multipage/dom.html#the-head-element-2 // https://html.spec.whatwg.org/multipage/dom.html#the-head-element-2

View file

@ -1049,14 +1049,15 @@ WebIDL::ExceptionOr<void> Element::set_inner_html(StringView value)
auto fragment = TRY(as<Element>(*context).parse_fragment(value)); auto fragment = TRY(as<Element>(*context).parse_fragment(value));
// 4. If context is a template element, then set context to the template element's template contents (a DocumentFragment). // 4. If context is a template element, then set context to the template element's template contents (a DocumentFragment).
if (is<HTML::HTMLTemplateElement>(*context)) auto* template_element = as_if<HTML::HTMLTemplateElement>(*context);
context = as<HTML::HTMLTemplateElement>(*context).content(); if (template_element)
context = template_element->content();
// 5. Replace all with fragment within context. // 5. Replace all with fragment within context.
context->replace_all(fragment); context->replace_all(fragment);
// NOTE: We don't invalidate style & layout for <template> elements since they don't affect rendering. // NOTE: We don't invalidate style & layout for <template> elements since they don't affect rendering.
if (!is<HTML::HTMLTemplateElement>(*context)) { if (!template_element) {
context->set_needs_style_update(true); context->set_needs_style_update(true);
if (context->is_connected()) { if (context->is_connected()) {

View file

@ -491,10 +491,11 @@ public:
void for_each_numbered_item_owned_by_list_owner(Callback callback) void for_each_numbered_item_owned_by_list_owner(Callback callback)
{ {
for (auto* node = this->first_child(); node != nullptr; node = node->next_in_pre_order(this)) { for (auto* node = this->first_child(); node != nullptr; node = node->next_in_pre_order(this)) {
if (!is<Element>(*node)) auto* element = as_if<Element>(node);
if (!element)
continue; continue;
static_cast<Element*>(node)->m_is_contained_in_list_subtree = true; element->m_is_contained_in_list_subtree = true;
if (node->is_html_ol_ul_menu_element()) { if (node->is_html_ol_ul_menu_element()) {
// Skip list nodes and their descendents. They have their own, unrelated ordinals. // Skip list nodes and their descendents. They have their own, unrelated ordinals.
@ -507,8 +508,6 @@ public:
if (!node->layout_node()) if (!node->layout_node())
continue; // Skip nodes that do not participate in the layout. continue; // Skip nodes that do not participate in the layout.
auto* element = static_cast<Element*>(node);
if (!element->computed_properties()->display().is_list_item()) if (!element->computed_properties()->display().is_list_item())
continue; // Skip nodes that are not list items. continue; // Skip nodes that are not list items.

View file

@ -164,8 +164,7 @@ static bool default_passive_value(FlyString const& type, EventTarget* event_targ
if (is<HTML::Window>(event_target)) if (is<HTML::Window>(event_target))
return true; return true;
if (is<Node>(event_target)) { if (auto* node = as_if<Node>(event_target)) {
auto* node = as<Node>(event_target);
if (&node->document() == event_target || node->document().document_element() == event_target || node->document().body() == event_target) if (&node->document() == event_target || node->document().document_element() == event_target || node->document().body() == event_target)
return true; return true;
} }
@ -400,8 +399,7 @@ WebIDL::CallbackType* EventTarget::get_current_value_of_event_handler(FlyString
GC::Ptr<Element> element; GC::Ptr<Element> element;
GC::Ptr<Document> document; GC::Ptr<Document> document;
if (is<Element>(this)) { if (auto* element_event_target = as_if<Element>(this)) {
auto* element_event_target = as<Element>(this);
element = element_event_target; element = element_event_target;
document = &element_event_target->document(); document = &element_event_target->document();
} else { } else {

View file

@ -136,11 +136,11 @@ String Node::base_uri() const
const HTML::HTMLAnchorElement* Node::enclosing_link_element() const const HTML::HTMLAnchorElement* Node::enclosing_link_element() const
{ {
for (auto* node = this; node; node = node->parent()) { for (auto* node = this; node; node = node->parent()) {
if (!is<HTML::HTMLAnchorElement>(*node)) auto const* anchor_element = as_if<HTML::HTMLAnchorElement>(*node);
if (!anchor_element)
continue; continue;
auto const& anchor_element = static_cast<HTML::HTMLAnchorElement const&>(*node); if (anchor_element->has_attribute(HTML::AttributeNames::href))
if (anchor_element.has_attribute(HTML::AttributeNames::href)) return anchor_element;
return &anchor_element;
} }
return nullptr; return nullptr;
} }
@ -153,8 +153,8 @@ const HTML::HTMLElement* Node::enclosing_html_element() const
const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(FlyString const& attribute) const const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(FlyString const& attribute) const
{ {
for (auto* node = this; node; node = node->parent()) { for (auto* node = this; node; node = node->parent()) {
if (is<HTML::HTMLElement>(*node) && as<HTML::HTMLElement>(*node).has_attribute(attribute)) if (auto* html_element = as_if<HTML::HTMLElement>(*node); html_element && html_element->has_attribute(attribute))
return as<HTML::HTMLElement>(node); return html_element;
} }
return nullptr; return nullptr;
} }
@ -354,13 +354,13 @@ Optional<String> Node::node_value() const
// The nodeValue getter steps are to return the following, switching on the interface this implements: // The nodeValue getter steps are to return the following, switching on the interface this implements:
// If Attr, return thiss value. // If Attr, return thiss value.
if (is<Attr>(this)) { if (auto* attr = as_if<Attr>(this)) {
return as<Attr>(this)->value(); return attr->value();
} }
// If CharacterData, return thiss data. // If CharacterData, return thiss data.
if (is<CharacterData>(this)) { if (auto* character_data = as_if<CharacterData>(this)) {
return as<CharacterData>(this)->data().to_utf8_but_should_be_ported_to_utf16(); return character_data->data().to_utf8_but_should_be_ported_to_utf16();
} }
// Otherwise, return null. // Otherwise, return null.
@ -375,11 +375,11 @@ void Node::set_node_value(Optional<String> const& maybe_value)
auto value = maybe_value.value_or(String {}); auto value = maybe_value.value_or(String {});
// If Attr, set an existing attribute value with this and the given value. // If Attr, set an existing attribute value with this and the given value.
if (is<Attr>(this)) { if (auto* attr = as_if<Attr>(this)) {
as<Attr>(this)->set_value(move(value)); attr->set_value(move(value));
} else if (is<CharacterData>(this)) { } else if (auto* character_data = as_if<CharacterData>(this)) {
// If CharacterData, replace data with node this, offset 0, count thiss length, and data the given value. // If CharacterData, replace data with node this, offset 0, count thiss length, and data the given value.
as<CharacterData>(this)->set_data(Utf16String::from_utf8(value)); character_data->set_data(Utf16String::from_utf8(value));
} }
// Otherwise, do nothing. // Otherwise, do nothing.
@ -545,8 +545,8 @@ Node& Node::shadow_including_root()
// The shadow-including root of an object is its roots hosts shadow-including root, // The shadow-including root of an object is its roots hosts shadow-including root,
// if the objects root is a shadow root; otherwise its root. // if the objects root is a shadow root; otherwise its root.
auto& node_root = root(); auto& node_root = root();
if (is<ShadowRoot>(node_root)) { if (auto* shadow_root = as_if<ShadowRoot>(node_root)) {
if (auto* host = static_cast<ShadowRoot&>(node_root).host(); host) if (auto* host = shadow_root->host(); host)
return host->shadow_including_root(); return host->shadow_including_root();
} }
return node_root; return node_root;

View file

@ -526,10 +526,8 @@ TaskID queue_global_task(HTML::Task::Source source, JS::Object& global_object, G
// 2. Let document be global's associated Document, if global is a Window object; otherwise null. // 2. Let document be global's associated Document, if global is a Window object; otherwise null.
DOM::Document* document { nullptr }; DOM::Document* document { nullptr };
if (is<HTML::Window>(global_object)) { if (auto* window_object = as_if<HTML::Window>(global_object))
auto& window_object = as<HTML::Window>(global_object); document = &window_object->associated_document();
document = &window_object.associated_document();
}
// 3. Queue a task given source, event loop, document, and steps. // 3. Queue a task given source, event loop, document, and steps.
return queue_a_task(source, *event_loop, document, steps); return queue_a_task(source, *event_loop, document, steps);

View file

@ -215,11 +215,12 @@ static void merge_with_the_next_text_node(DOM::Text& node)
auto next = node.next_sibling(); auto next = node.next_sibling();
// 2. If next is not a Text node, then return. // 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; return;
// 3. Replace data with node, node's data's length, 0, and next's data. // 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. // 4. Remove next.
next->remove(); 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())); 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. // 8. If previous is a Text node, then merge with the next text node given previous.
if (is<DOM::Text>(previous)) if (auto* previous_text = as_if<DOM::Text>(previous))
merge_with_the_next_text_node(static_cast<DOM::Text&>(*previous)); merge_with_the_next_text_node(*previous_text);
set_needs_style_update(true); set_needs_style_update(true);
return {}; return {};
@ -842,7 +843,8 @@ GC::Ptr<DOM::NodeList> HTMLElement::labels()
if (!m_labels) { if (!m_labels) {
m_labels = DOM::LiveNodeList::create(realm(), root(), DOM::LiveNodeList::Scope::Descendants, [&](auto& node) { 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;
}); });
} }

View file

@ -1087,8 +1087,8 @@ static void update_the_source_set(DOM::Element& element)
VERIFY(is<HTMLImageElement>(element) || is<HTMLLinkElement>(element)); VERIFY(is<HTMLImageElement>(element) || is<HTMLLinkElement>(element));
// 1. Set el's source set to an empty source set. // 1. Set el's source set to an empty source set.
if (is<HTMLImageElement>(element)) if (auto* image_element = as_if<HTMLImageElement>(element))
static_cast<HTMLImageElement&>(element).set_source_set(SourceSet {}); image_element->set_source_set(SourceSet {});
else if (is<HTMLLinkElement>(element)) else if (is<HTMLLinkElement>(element))
TODO(); TODO();

View file

@ -494,11 +494,9 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
// 3. If the user activated the control while explicitly selecting a coordinate, then set the element's selected // 3. If the user activated the control while explicitly selecting a coordinate, then set the element's selected
// coordinate to that coordinate. // coordinate to that coordinate.
if (event.is_trusted() && is<UIEvents::MouseEvent>(event)) { if (auto* mouse_event = as_if<UIEvents::MouseEvent>(event); mouse_event && event.is_trusted()) {
auto const& mouse_event = static_cast<UIEvents::MouseEvent const&>(event); CSSPixels x { mouse_event->offset_x() };
CSSPixels y { mouse_event->offset_y() };
CSSPixels x { mouse_event.offset_x() };
CSSPixels y { mouse_event.offset_y() };
m_selected_coordinate = { x.to_int(), y.to_int() }; m_selected_coordinate = { x.to_int(), y.to_int() };
} }

View file

@ -715,8 +715,8 @@ private:
} }
// 14. ⌛ If the node after pointer is a source element, let candidate be that element. // 14. ⌛ If the node after pointer is a source element, let candidate be that element.
if (is<HTMLSourceElement>(next_sibling)) if (auto* source_element = as_if<HTMLSourceElement>(next_sibling))
candidate = static_cast<HTMLSourceElement*>(next_sibling); candidate = source_element;
// 15. ⌛ Advance pointer so that the node before pointer is now the node that was after pointer, and the node // 15. ⌛ Advance pointer so that the node before pointer is now the node that was after pointer, and the node
// after pointer is the node after the node that used to be after pointer, if any. // after pointer is the node after the node that used to be after pointer, if any.

View file

@ -213,8 +213,7 @@ GC::Ptr<HTMLTableSectionElement> HTMLTableElement::t_head()
// The tHead IDL attribute must return, on getting, the first thead element child of the table element, // The tHead IDL attribute must return, on getting, the first thead element child of the table element,
// if any, or null otherwise. // if any, or null otherwise.
for (auto* child = first_child(); child; child = child->next_sibling()) { for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<HTMLTableSectionElement>(*child)) { if (auto* table_section_element = as_if<HTMLTableSectionElement>(*child)) {
auto table_section_element = &as<HTMLTableSectionElement>(*child);
if (table_section_element->local_name() == TagNames::thead) if (table_section_element->local_name() == TagNames::thead)
return table_section_element; return table_section_element;
} }
@ -248,8 +247,7 @@ WebIDL::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement*
continue; continue;
if (is<HTMLTableCaptionElement>(*child)) if (is<HTMLTableCaptionElement>(*child))
continue; continue;
if (is<HTMLTableColElement>(*child)) { if (auto* table_col_element = as_if<HTMLTableColElement>(*child)) {
auto table_col_element = &as<HTMLTableColElement>(*child);
if (table_col_element->local_name() == TagNames::colgroup) if (table_col_element->local_name() == TagNames::colgroup)
continue; continue;
} }
@ -280,8 +278,7 @@ GC::Ref<HTMLTableSectionElement> HTMLTableElement::create_t_head()
continue; continue;
if (is<HTMLTableCaptionElement>(*child)) if (is<HTMLTableCaptionElement>(*child))
continue; continue;
if (is<HTMLTableColElement>(*child)) { if (auto* table_col_element = as_if<HTMLTableColElement>(*child)) {
auto table_col_element = &as<HTMLTableColElement>(*child);
if (table_col_element->local_name() == TagNames::colgroup) if (table_col_element->local_name() == TagNames::colgroup)
continue; continue;
} }
@ -311,8 +308,7 @@ GC::Ptr<HTMLTableSectionElement> HTMLTableElement::t_foot()
// The tFoot IDL attribute must return, on getting, the first tfoot element child of the table element, // The tFoot IDL attribute must return, on getting, the first tfoot element child of the table element,
// if any, or null otherwise. // if any, or null otherwise.
for (auto* child = first_child(); child; child = child->next_sibling()) { for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<HTMLTableSectionElement>(*child)) { if (auto* table_section_element = as_if<HTMLTableSectionElement>(*child)) {
auto table_section_element = &as<HTMLTableSectionElement>(*child);
if (table_section_element->local_name() == TagNames::tfoot) if (table_section_element->local_name() == TagNames::tfoot)
return table_section_element; return table_section_element;
} }
@ -384,8 +380,7 @@ GC::Ref<HTMLTableSectionElement> HTMLTableElement::create_t_body()
for (auto* child = last_child(); child; child = child->previous_sibling()) { for (auto* child = last_child(); child; child = child->previous_sibling()) {
if (!is<HTMLElement>(*child)) if (!is<HTMLElement>(*child))
continue; continue;
if (is<HTMLTableSectionElement>(*child)) { if (auto* table_section_element = as_if<HTMLTableSectionElement>(*child)) {
auto table_section_element = &as<HTMLTableSectionElement>(*child);
if (table_section_element->local_name() == TagNames::tbody) { if (table_section_element->local_name() == TagNames::tbody) {
// We have found an element which is a <tbody> we'll insert after this // We have found an element which is a <tbody> we'll insert after this
child_to_insert_before = child->next_sibling(); child_to_insert_before = child->next_sibling();

View file

@ -1228,8 +1228,10 @@ static WebIDL::ExceptionOr<Navigable::NavigationParamsVariant> create_navigation
// 26. If navigable's container is an iframe, and response's timing allow passed flag is set, // 26. If navigable's container is an iframe, and response's timing allow passed flag is set,
// then set navigable's container's pending resource-timing start time to null. // then set navigable's container's pending resource-timing start time to null.
if (navigable->container() && is<HTML::HTMLIFrameElement>(*navigable->container()) && response_holder->response()->timing_allow_passed()) if (navigable->container() && response_holder->response()->timing_allow_passed()) {
static_cast<HTML::HTMLIFrameElement&>(*navigable->container()).set_pending_resource_start_time({}); if (auto* iframe_element = as_if<HTML::HTMLIFrameElement>(*navigable->container()))
iframe_element->set_pending_resource_start_time({});
}
// 27. Return a new navigation params, with // 27. Return a new navigation params, with
// id: navigationId // id: navigationId

View file

@ -766,8 +766,8 @@ HTMLParser::AdjustedInsertionLocation HTMLParser::find_appropriate_place_for_ins
// 3. If the adjusted insertion location is inside a template element, // 3. If the adjusted insertion location is inside a template element,
// let it instead be inside the template element's template contents, after its last child (if any). // let it instead be inside the template element's template contents, after its last child (if any).
if (is<HTMLTemplateElement>(*adjusted_insertion_location.parent)) if (auto* template_element = as_if<HTMLTemplateElement>(*adjusted_insertion_location.parent))
adjusted_insertion_location = { static_cast<HTMLTemplateElement const&>(*adjusted_insertion_location.parent).content().ptr(), nullptr }; adjusted_insertion_location = { template_element->content().ptr(), nullptr };
// 4. Return the adjusted insertion location. // 4. Return the adjusted insertion location.
return adjusted_insertion_location; return adjusted_insertion_location;

View file

@ -1238,8 +1238,8 @@ WebIDL::ExceptionOr<void> Window::window_post_message_steps(JS::Value message, W
// FIXME: Use a FrozenArray // FIXME: Use a FrozenArray
Vector<GC::Root<MessagePort>> new_ports; Vector<GC::Root<MessagePort>> new_ports;
for (auto const& object : deserialize_record.transferred_values) { for (auto const& object : deserialize_record.transferred_values) {
if (is<HTML::MessagePort>(*object)) { if (auto* message_port = as_if<HTML::MessagePort>(*object)) {
new_ports.append(as<MessagePort>(*object)); new_ports.append(*message_port);
} }
} }

View file

@ -81,9 +81,8 @@ void BlockFormattingContext::run(AvailableSpace const& available_space)
else else
layout_block_level_children(root(), available_space); layout_block_level_children(root(), available_space);
if (is<FieldSetBox>(root())) { if (auto* fieldset_box = as_if<FieldSetBox>(root())) {
auto const& fieldset_box = as<FieldSetBox>(root()); if (!fieldset_box->has_rendered_legend()) {
if (!(fieldset_box.has_rendered_legend())) {
return; return;
} }
@ -188,10 +187,9 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
if (box_is_sized_as_replaced_element(box, available_space)) { if (box_is_sized_as_replaced_element(box, available_space)) {
// FIXME: This should not be done *by* ReplacedBox // FIXME: This should not be done *by* ReplacedBox
if (is<ReplacedBox>(box)) { if (auto* replaced = as_if<ReplacedBox>(box)) {
auto& replaced = as<ReplacedBox>(box);
// FIXME: This const_cast is gross. // FIXME: This const_cast is gross.
const_cast<ReplacedBox&>(replaced).prepare_for_replaced_layout(); const_cast<ReplacedBox&>(*replaced).prepare_for_replaced_layout();
} }
compute_width_for_block_level_replaced_element_in_normal_flow(box, available_space); compute_width_for_block_level_replaced_element_in_normal_flow(box, available_space);
if (box.is_floating()) { if (box.is_floating()) {
@ -822,17 +820,15 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
// If we do not do this then left-floating elements inside the list item will push the marker to the right, // If we do not do this then left-floating elements inside the list item will push the marker to the right,
// in some cases even causing it to overlap with the non-floating content of the list. // in some cases even causing it to overlap with the non-floating content of the list.
CSSPixels left_space_before_children_formatted; CSSPixels left_space_before_children_formatted;
if (is<ListItemBox>(box)) { if (auto const* li_box = as_if<ListItemBox>(box)) {
auto const& li_box = static_cast<ListItemBox const&>(box);
// We need to ensure that our height and width are final before we calculate our left offset. // We need to ensure that our height and width are final before we calculate our left offset.
// Otherwise, the y at which we calculate the intrusion by floats might be incorrect. // Otherwise, the y at which we calculate the intrusion by floats might be incorrect.
ensure_sizes_correct_for_left_offset_calculation(li_box); ensure_sizes_correct_for_left_offset_calculation(*li_box);
auto const& list_item_state = m_state.get(li_box); auto const& list_item_state = m_state.get(*li_box);
auto const& marker_state = m_state.get(*li_box.marker()); auto const& marker_state = m_state.get(*li_box->marker());
auto offset_y = max(CSSPixels(0), (li_box.marker()->computed_values().line_height() - marker_state.content_height()) / 2); auto offset_y = max(CSSPixels(0), (li_box->marker()->computed_values().line_height() - marker_state.content_height()) / 2);
auto space_used_before_children_formatted = intrusion_by_floats_into_box(list_item_state, offset_y); auto space_used_before_children_formatted = intrusion_by_floats_into_box(list_item_state, offset_y);
left_space_before_children_formatted = space_used_before_children_formatted.left; left_space_before_children_formatted = space_used_before_children_formatted.left;
@ -884,8 +880,8 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
compute_inset(box, content_box_rect(block_container_state).size()); compute_inset(box, content_box_rect(block_container_state).size());
// Now that our children are formatted we place the ListItemBox with the left space we remembered. // Now that our children are formatted we place the ListItemBox with the left space we remembered.
if (is<ListItemBox>(box)) if (auto const* li_box = as_if<ListItemBox>(box))
layout_list_item_marker(static_cast<ListItemBox const&>(box), left_space_before_children_formatted); layout_list_item_marker(*li_box, left_space_before_children_formatted);
bottom_of_lowest_margin_box = max(bottom_of_lowest_margin_box, box_state.offset.y() + box_state.content_height() + box_state.margin_box_bottom()); bottom_of_lowest_margin_box = max(bottom_of_lowest_margin_box, box_state.offset.y() + box_state.content_height() + box_state.margin_box_bottom());

View file

@ -871,9 +871,9 @@ void FormattingContext::compute_width_for_absolutely_positioned_replaced_element
// but the rest of section 10.3.7 is replaced by the following rules: // but the rest of section 10.3.7 is replaced by the following rules:
// 1. The used value of 'width' is determined as for inline replaced elements. // 1. The used value of 'width' is determined as for inline replaced elements.
if (is<ReplacedBox>(box)) { if (auto const* replaced = as_if<ReplacedBox>(box)) {
// FIXME: This const_cast is gross. // FIXME: This const_cast is gross.
static_cast<ReplacedBox&>(const_cast<Box&>(box)).prepare_for_replaced_layout(); const_cast<ReplacedBox&>(*replaced).prepare_for_replaced_layout();
} }
auto width = compute_width_for_replaced_element(box, available_space); auto width = compute_width_for_replaced_element(box, available_space);

View file

@ -308,19 +308,18 @@ void InlineFormattingContext::generate_line_boxes()
break; break;
} }
case InlineLevelIterator::Item::Type::AbsolutelyPositionedElement: case InlineLevelIterator::Item::Type::AbsolutelyPositionedElement:
if (is<Box>(*item.node)) { if (auto const* box = as_if<Box>(*item.node)) {
auto const& box = static_cast<Layout::Box const&>(*item.node);
// Calculation of static position for absolute boxes is delayed until trailing whitespaces are removed. // Calculation of static position for absolute boxes is delayed until trailing whitespaces are removed.
absolute_boxes.append(&box); absolute_boxes.append(box);
} }
break; break;
case InlineLevelIterator::Item::Type::FloatingElement: case InlineLevelIterator::Item::Type::FloatingElement:
if (is<Box>(*item.node)) { if (auto* box = as_if<Box>(*item.node)) {
(void)parent().clear_floating_boxes(*item.node, *this); (void)parent().clear_floating_boxes(*item.node, *this);
// Even if this introduces clearance, we do NOT reset the margin state, because that is clearance // Even if this introduces clearance, we do NOT reset the margin state, because that is clearance
// between floats and does not contribute to the height of the Inline Formatting Context. // between floats and does not contribute to the height of the Inline Formatting Context.
parent().layout_floating_box(static_cast<Layout::Box const&>(*item.node), containing_block(), *m_available_space, 0, &line_builder); parent().layout_floating_box(*box, containing_block(), *m_available_space, 0, &line_builder);
} }
break; break;

View file

@ -61,9 +61,9 @@ bool LineBoxFragment::is_justifiable_whitespace() const
Utf16View LineBoxFragment::text() const Utf16View LineBoxFragment::text() const
{ {
if (!is<TextNode>(layout_node())) if (auto* text_node = as_if<TextNode>(layout_node()))
return text_node->text_for_rendering().substring_view(m_start, m_length);
return {}; return {};
return as<TextNode>(layout_node()).text_for_rendering().substring_view(m_start, m_length);
} }
bool LineBoxFragment::is_atomic_inline() const bool LineBoxFragment::is_atomic_inline() const

View file

@ -1056,10 +1056,9 @@ void NodeWithStyle::propagate_style_to_anonymous_wrappers()
// If this is a `display:table` box with an anonymous wrapper parent, // If this is a `display:table` box with an anonymous wrapper parent,
// the parent inherits style from *this* node, not the other way around. // the parent inherits style from *this* node, not the other way around.
if (display().is_table_inside() && is<TableWrapper>(parent())) { if (auto* table_wrapper = as_if<TableWrapper>(parent()); table_wrapper && display().is_table_inside()) {
auto& table_wrapper = *static_cast<TableWrapper*>(parent()); static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(table_wrapper->computed_values()))).inherit_from(computed_values());
static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(table_wrapper.computed_values()))).inherit_from(computed_values()); transfer_table_box_computed_values_to_wrapper_computed_values(table_wrapper->mutable_computed_values());
transfer_table_box_computed_values_to_wrapper_computed_values(table_wrapper.mutable_computed_values());
} }
// Propagate style to all anonymous children (except table wrappers!) // Propagate style to all anonymous children (except table wrappers!)

View file

@ -41,9 +41,8 @@ static RefPtr<DisplayList> compute_text_clip_paths(DisplayListRecordingContext&
}; };
paintable.for_each_in_inclusive_subtree([&](auto& paintable) { paintable.for_each_in_inclusive_subtree([&](auto& paintable) {
if (is<PaintableWithLines>(paintable)) { if (auto* paintable_lines = as_if<PaintableWithLines>(paintable)) {
auto const& paintable_lines = static_cast<PaintableWithLines const&>(paintable); for (auto const& fragment : paintable_lines->fragments()) {
for (auto const& fragment : paintable_lines.fragments()) {
if (is<Layout::TextNode>(fragment.layout_node())) if (is<Layout::TextNode>(fragment.layout_node()))
add_text_clip_path(fragment); add_text_clip_path(fragment);
} }

View file

@ -132,8 +132,8 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset)
auto& node = layout_node(); auto& node = layout_node();
if (auto pseudo_element = node.generated_for_pseudo_element(); pseudo_element.has_value()) { if (auto pseudo_element = node.generated_for_pseudo_element(); pseudo_element.has_value()) {
node.pseudo_element_generator()->set_scroll_offset(*pseudo_element, offset); node.pseudo_element_generator()->set_scroll_offset(*pseudo_element, offset);
} else if (is<DOM::Element>(*dom_node())) { } else if (auto* element = as_if<DOM::Element>(dom_node())) {
static_cast<DOM::Element*>(dom_node())->set_scroll_offset({}, offset); element->set_scroll_offset({}, offset);
} else { } else {
return; return;
} }