diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cpp index 602b643c45f..59b8700304d 100644 --- a/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Libraries/LibWeb/CSS/FontFace.cpp @@ -477,9 +477,8 @@ GC::Ref FontFace::load() // 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); - if (is(global)) { - auto& window = static_cast(global); - auto& style_computer = const_cast(window.document()->style_computer()); + if (auto* window = as_if(global)) { + auto& style_computer = const_cast(window->document()->style_computer()); // FIXME: The ParsedFontFace is kind of expensive to create. We should be using a shared sub-object for the data ParsedFontFace parsed_font_face { diff --git a/Libraries/LibWeb/CSS/Interpolation.cpp b/Libraries/LibWeb/CSS/Interpolation.cpp index 6a2fed7b530..d3fe112c4d4 100644 --- a/Libraries/LibWeb/CSS/Interpolation.cpp +++ b/Libraries/LibWeb/CSS/Interpolation.cpp @@ -638,8 +638,8 @@ RefPtr interpolate_transform(DOM::Element& element, StyleValue return {}; Optional paintable_box; if (auto layout_node = element.layout_node()) { - if (auto paintable = layout_node->first_paintable(); paintable && is(paintable)) - paintable_box = *static_cast(paintable); + if (auto* paintable = as_if(layout_node->first_paintable())) + paintable_box = *paintable; } if (auto matrix = transformation->to_matrix(paintable_box); !matrix.is_error()) return matrix.value(); diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 9009a9fd04b..d9c1843fa6f 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -508,7 +508,7 @@ bool StyleComputer::invalidation_property_used_in_has_selector(InvalidationSet:: Vector StyleComputer::collect_matching_rules(DOM::Element const& element, CascadeOrigin cascade_origin, Optional pseudo_element, PseudoClassBitmap& attempted_pseudo_class_matches, Optional qualified_layer_name) const { auto const& root_node = element.root(); - auto shadow_root = is(root_node) ? static_cast(&root_node) : nullptr; + auto shadow_root = as_if(root_node); auto element_shadow_root = element.shadow_root(); auto const& element_namespace_uri = element.namespace_uri(); diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp index 56ffd16e321..1fb4fa44122 100644 --- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp @@ -897,9 +897,8 @@ MatchResult does_element_match_source_list_for_type_and_source(GC::Ptr(element.ptr()) || is(element.ptr())); String element_nonce; - if (is(element.ptr())) { - auto const& html_element = static_cast(*element); - element_nonce = html_element.nonce(); + if (auto* html_element = as_if(element.ptr())) { + element_nonce = html_element->nonce(); } else { auto const& svg_element = as(*element); element_nonce = svg_element.nonce(); diff --git a/Libraries/LibWeb/Crypto/CryptoKey.cpp b/Libraries/LibWeb/Crypto/CryptoKey.cpp index dd3e1c17239..029608369c4 100644 --- a/Libraries/LibWeb/Crypto/CryptoKey.cpp +++ b/Libraries/LibWeb/Crypto/CryptoKey.cpp @@ -117,9 +117,10 @@ static JS::ThrowCompletionOr impl_from(JS::VM& vm) else this_object = TRY(this_value.to_object(vm)); - if (!is(this_object)) + auto* crypto_key_pair = as_if(this_object); + if (!crypto_key_pair) return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "CryptoKeyPair"); - return static_cast(this_object); + return crypto_key_pair; } JS_DEFINE_NATIVE_FUNCTION(CryptoKeyPair::public_key_getter) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index dac48eccf2b..7d826d2a563 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -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. auto* html = document_element(); - if (is(html)) - return as(html); - return nullptr; + return as_if(html); } // https://html.spec.whatwg.org/multipage/dom.html#the-head-element-2 diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 1da3797f549..ea2a05fbc85 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -1049,14 +1049,15 @@ WebIDL::ExceptionOr Element::set_inner_html(StringView value) auto fragment = TRY(as(*context).parse_fragment(value)); // 4. If context is a template element, then set context to the template element's template contents (a DocumentFragment). - if (is(*context)) - context = as(*context).content(); + auto* template_element = as_if(*context); + if (template_element) + context = template_element->content(); // 5. Replace all with fragment within context. context->replace_all(fragment); // NOTE: We don't invalidate style & layout for