Introduce dynamicDowncast<>() for convenience
https://bugs.webkit.org/show_bug.cgi?id=235259

Reviewed by Darin Adler.

Source/WebCore:

Start adopting dynamicDowncast<>().

* animation/WebAnimation.cpp:
(WebCore::WebAnimation::setTimeline):
(WebCore::WebAnimation::willChangeRenderer):
(WebCore::WebAnimation::timingDidChange):
(WebCore::WebAnimation::invalidateEffect):
(WebCore::WebAnimation::finishNotificationSteps):
(WebCore::WebAnimation::resolve):
(WebCore::WebAnimation::persist):
(WebCore::WebAnimation::commitStyles):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* bindings/js/JSLazyEventListener.cpp:
(WebCore::isCloneInShadowTreeOfSVGUseElement):
(WebCore::JSLazyEventListener::initializeJSFunction const):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::fontRangesForFamily):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::insertRule):
* dom/Attr.cpp:
(WebCore::Attr::style):
* dom/BroadcastChannel.cpp:
(WebCore::BroadcastChannel::MainThreadBridge::ensureOnMainThread):
(WebCore::BroadcastChannel::isEligibleForMessaging const):
* dom/CharacterData.cpp:
(WebCore::CharacterData::parserAppendData):
(WebCore::CharacterData::setDataAndUpdate):
* dom/CharacterData.h:
(WebCore::Node::length const):
* dom/ComposedTreeAncestorIterator.h:
(WebCore::ComposedTreeAncestorIterator::traverseParent):
(WebCore::ComposedTreeAncestorAdapter::begin):
* dom/ComposedTreeIterator.h:
(WebCore::firstChildInComposedTreeIgnoringUserAgentShadow):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::removeNodeWithScriptAssertion):
(WebCore::ContainerNode::removeSelfOrChildNodesForInsertion):
(WebCore::destroyRenderTreeIfNeeded):
(WebCore::containsIncludingHostElements):
(WebCore::checkAcceptChild):
* dom/ContainerNode.h:
(WebCore::Node::countChildNodes const):
(WebCore::Node::traverseToChildAt const):
(WebCore::Node::firstChild const):
(WebCore::Node::lastChild const):
* dom/Document.cpp:
(WebCore::widgetForElement):
(WebCore::Document::buildAccessKeyCache):
(WebCore::Document::adjustFocusedNodeOnNodeRemoval):
* dom/Element.cpp:
(WebCore::Element::insertedIntoAncestor):
(WebCore::Element::removedFromAncestor):
* dom/ElementInlines.h:
(WebCore::Node::parentElement const):
* dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::dispatchEvent):
* dom/MouseEvent.cpp:
(WebCore::MouseEvent::toElement const):
(WebCore::MouseEvent::fromElement const):
* dom/Node.cpp:
(WebCore::Node::renderBox const):
(WebCore::Node::renderBoxModelObject const):
(WebCore::Node::containingShadowRoot const):
(WebCore::Node::compareDocumentPosition):
* dom/Position.cpp:
(WebCore::Position::containerText const):
* dom/TextNodeTraversal.cpp:
(WebCore::TextNodeTraversal::contentsAsString):
* dom/TreeScope.cpp:
(WebCore::TreeScope::elementsFromPoint):
* dom/TypedElementDescendantIterator.h:
(WebCore::ElementDescendantRange<ElementType>::from const):
(WebCore::InclusiveElementDescendantRange<ElementType>::from const):
* dom/VisitedLinkState.cpp:
(WebCore::linkHashForElement):
* dom/messageports/MessagePortChannelProvider.cpp:
(WebCore::MessagePortChannelProvider::fromContext):
* editing/Editing.cpp:
(WebCore::enclosingBlock):
* html/HTMLOptGroupElement.cpp:
(WebCore::HTMLOptGroupElement::ownerSelectElement const):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::renderEmbeddedObject const):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* layout/Verification.cpp:
(WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):
* page/AutoscrollController.cpp:
(WebCore::AutoscrollController::updateAutoscrollRenderer):
* page/DOMTimer.cpp:
(WebCore::DOMTimer::fired):
* page/DragController.cpp:
(WebCore::asFileInput):
(WebCore::DragController::operationForLoad):
* platform/DragImage.cpp:
(WebCore::ScopedNodeDragEnabler::ScopedNodeDragEnabler):
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::setCDMInstance):
* rendering/LegacyInlineFlowBox.cpp:
(WebCore::LegacyInlineFlowBox::computeLogicalBoxHeights):
(WebCore::placeChildInlineBoxesInBlockDirection):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutBlockChild):
(WebCore::RenderBlockFlow::marginValuesForChild const):
(WebCore::RenderBlockFlow::adjustBlockChildForPagination):
(WebCore::RenderBlockFlow::positionNewFloats):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::findAutoscrollable):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::imageOrientation const):
* rendering/RenderFileUploadControl.cpp:
(WebCore::RenderFileUploadControl::uploadButton const):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::updateInnerContentRect):
(WebCore::RenderImage::paintIntoRect):
* rendering/RenderInline.cpp:
(WebCore::RenderInline::mayAffectLayout const):
* rendering/RenderLayer.h:
(WebCore::RenderLayer::renderBox const):
* rendering/RenderLineBoxList.cpp:
(WebCore::RenderLineBoxList::dirtyLinesFromChangedChild):
* rendering/RenderListItem.cpp:
(WebCore::RenderListItem::updateValueNow const):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::offsetParent const):
* rendering/RenderTableCol.cpp:
(WebCore::RenderTableCol::table const):
* rendering/RenderTreeAsText.cpp:
(WebCore::writeDebugInfo):
* rendering/RenderView.cpp:
(WebCore::RenderView::paintBoxDecorations):
* rendering/SelectionRangeData.cpp:
(WebCore::containingBlockBelowView):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::normalizeTreeAfterStyleChange):
* rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::Parent::Parent):
* style/ChildChangeInvalidation.h:
(WebCore::Style::ChildChangeInvalidation::ChildChangeInvalidation):
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::findViewAnchor const):
(WebCore::SVGSVGElement::findRootAnchor const):
* testing/Internals.cpp:
(WebCore::bitmapImageFromImageElement):
(WebCore::pdfDocumentImageFromImageElement):

Source/WebKit:

Start adopting dynamicDowncast<>().

* WebProcess/FullScreen/WebFullScreenManager.cpp:
(WebKit::WebFullScreenManager::didEnterFullScreen):
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::paymentCoordinator):

Source/WebKitLegacy/mac:

Start adopting dynamicDowncast<>().

* DOM/DOMUIKitExtensions.mm:
(-[DOMHTMLElement structuralComplexityContribution]):
* WebView/WebHTMLRepresentation.mm:
(inputElementFromDOMElement):

Source/WTF:

Introduce dynamicDowncast<>() for convenience. It can result in more concise code for the common pattern
where we call `is<T>(x)` and then `downcast<T>(x)`.

* wtf/TypeCasts.h:
(WTF::dynamicDowncast):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index e76f379..d7285ed0 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,157 @@
+2022-01-15  Chris Dumez  <cdumez@apple.com>
+
+        Introduce dynamicDowncast<>() for convenience
+        https://bugs.webkit.org/show_bug.cgi?id=235259
+
+        Reviewed by Darin Adler.
+
+        Start adopting dynamicDowncast<>().
+
+        * animation/WebAnimation.cpp:
+        (WebCore::WebAnimation::setTimeline):
+        (WebCore::WebAnimation::willChangeRenderer):
+        (WebCore::WebAnimation::timingDidChange):
+        (WebCore::WebAnimation::invalidateEffect):
+        (WebCore::WebAnimation::finishNotificationSteps):
+        (WebCore::WebAnimation::resolve):
+        (WebCore::WebAnimation::persist):
+        (WebCore::WebAnimation::commitStyles):
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::handleEvent):
+        * bindings/js/JSLazyEventListener.cpp:
+        (WebCore::isCloneInShadowTreeOfSVGUseElement):
+        (WebCore::JSLazyEventListener::initializeJSFunction const):
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::fontRangesForFamily):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::insertRule):
+        * dom/Attr.cpp:
+        (WebCore::Attr::style):
+        * dom/BroadcastChannel.cpp:
+        (WebCore::BroadcastChannel::MainThreadBridge::ensureOnMainThread):
+        (WebCore::BroadcastChannel::isEligibleForMessaging const):
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::parserAppendData):
+        (WebCore::CharacterData::setDataAndUpdate):
+        * dom/CharacterData.h:
+        (WebCore::Node::length const):
+        * dom/ComposedTreeAncestorIterator.h:
+        (WebCore::ComposedTreeAncestorIterator::traverseParent):
+        (WebCore::ComposedTreeAncestorAdapter::begin):
+        * dom/ComposedTreeIterator.h:
+        (WebCore::firstChildInComposedTreeIgnoringUserAgentShadow):
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::removeNodeWithScriptAssertion):
+        (WebCore::ContainerNode::removeSelfOrChildNodesForInsertion):
+        (WebCore::destroyRenderTreeIfNeeded):
+        (WebCore::containsIncludingHostElements):
+        (WebCore::checkAcceptChild):
+        * dom/ContainerNode.h:
+        (WebCore::Node::countChildNodes const):
+        (WebCore::Node::traverseToChildAt const):
+        (WebCore::Node::firstChild const):
+        (WebCore::Node::lastChild const):
+        * dom/Document.cpp:
+        (WebCore::widgetForElement):
+        (WebCore::Document::buildAccessKeyCache):
+        (WebCore::Document::adjustFocusedNodeOnNodeRemoval):
+        * dom/Element.cpp:
+        (WebCore::Element::insertedIntoAncestor):
+        (WebCore::Element::removedFromAncestor):
+        * dom/ElementInlines.h:
+        (WebCore::Node::parentElement const):
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventDispatcher::dispatchEvent):
+        * dom/MouseEvent.cpp:
+        (WebCore::MouseEvent::toElement const):
+        (WebCore::MouseEvent::fromElement const):
+        * dom/Node.cpp:
+        (WebCore::Node::renderBox const):
+        (WebCore::Node::renderBoxModelObject const):
+        (WebCore::Node::containingShadowRoot const):
+        (WebCore::Node::compareDocumentPosition):
+        * dom/Position.cpp:
+        (WebCore::Position::containerText const):
+        * dom/TextNodeTraversal.cpp:
+        (WebCore::TextNodeTraversal::contentsAsString):
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::elementsFromPoint):
+        * dom/TypedElementDescendantIterator.h:
+        (WebCore::ElementDescendantRange<ElementType>::from const):
+        (WebCore::InclusiveElementDescendantRange<ElementType>::from const):
+        * dom/VisitedLinkState.cpp:
+        (WebCore::linkHashForElement):
+        * dom/messageports/MessagePortChannelProvider.cpp:
+        (WebCore::MessagePortChannelProvider::fromContext):
+        * editing/Editing.cpp:
+        (WebCore::enclosingBlock):
+        * html/HTMLOptGroupElement.cpp:
+        (WebCore::HTMLOptGroupElement::ownerSelectElement const):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::renderEmbeddedObject const):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * layout/Verification.cpp:
+        (WebCore::Layout::outputMismatchingComplexLineInformationIfNeeded):
+        * page/AutoscrollController.cpp:
+        (WebCore::AutoscrollController::updateAutoscrollRenderer):
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::fired):
+        * page/DragController.cpp:
+        (WebCore::asFileInput):
+        (WebCore::DragController::operationForLoad):
+        * platform/DragImage.cpp:
+        (WebCore::ScopedNodeDragEnabler::ScopedNodeDragEnabler):
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::setCDMInstance):
+        * rendering/LegacyInlineFlowBox.cpp:
+        (WebCore::LegacyInlineFlowBox::computeLogicalBoxHeights):
+        (WebCore::placeChildInlineBoxesInBlockDirection):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::layoutBlockChild):
+        (WebCore::RenderBlockFlow::marginValuesForChild const):
+        (WebCore::RenderBlockFlow::adjustBlockChildForPagination):
+        (WebCore::RenderBlockFlow::positionNewFloats):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::findAutoscrollable):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::imageOrientation const):
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::uploadButton const):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::updateInnerContentRect):
+        (WebCore::RenderImage::paintIntoRect):
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::mayAffectLayout const):
+        * rendering/RenderLayer.h:
+        (WebCore::RenderLayer::renderBox const):
+        * rendering/RenderLineBoxList.cpp:
+        (WebCore::RenderLineBoxList::dirtyLinesFromChangedChild):
+        * rendering/RenderListItem.cpp:
+        (WebCore::RenderListItem::updateValueNow const):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::offsetParent const):
+        * rendering/RenderTableCol.cpp:
+        (WebCore::RenderTableCol::table const):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::writeDebugInfo):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::paintBoxDecorations):
+        * rendering/SelectionRangeData.cpp:
+        (WebCore::containingBlockBelowView):
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::normalizeTreeAfterStyleChange):
+        * rendering/updating/RenderTreeUpdater.cpp:
+        (WebCore::RenderTreeUpdater::Parent::Parent):
+        * style/ChildChangeInvalidation.h:
+        (WebCore::Style::ChildChangeInvalidation::ChildChangeInvalidation):
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::findViewAnchor const):
+        (WebCore::SVGSVGElement::findRootAnchor const):
+        * testing/Internals.cpp:
+        (WebCore::bitmapImageFromImageElement):
+        (WebCore::pdfDocumentImageFromImageElement):
+
 2022-01-15  Darin Adler  <darin@apple.com>
 
         First step to fix hacked isReplaced: Rename isReplaced functions to isReplacedOrInlineBlock
diff --git a/Source/WebCore/animation/WebAnimation.cpp b/Source/WebCore/animation/WebAnimation.cpp
index 05e4ae0..f20bbcf 100644
--- a/Source/WebCore/animation/WebAnimation.cpp
+++ b/Source/WebCore/animation/WebAnimation.cpp
@@ -244,8 +244,8 @@
     if (m_startTime)
         m_holdTime = std::nullopt;
 
-    if (is<KeyframeEffect>(m_effect)) {
-        if (auto target = downcast<KeyframeEffect>(m_effect.get())->targetStyleable()) {
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get())) {
+        if (auto target = keyframeEffect->targetStyleable()) {
             // In the case of a declarative animation, we don't want to remove the animation from the relevant maps because
             // while the timeline was set via the API, the element still has a transition or animation set up and we must
             // not break the relationship.
@@ -725,8 +725,8 @@
 
 void WebAnimation::willChangeRenderer()
 {
-    if (is<KeyframeEffect>(m_effect))
-        downcast<KeyframeEffect>(*m_effect).willChangeRenderer();
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get()))
+        keyframeEffect->willChangeRenderer();
 }
 
 void WebAnimation::enqueueAnimationPlaybackEvent(const AtomString& type, std::optional<Seconds> currentTime, std::optional<Seconds> timelineTime)
@@ -838,9 +838,9 @@
     m_shouldSkipUpdatingFinishedStateWhenResolving = false;
     updateFinishedState(didSeek, synchronouslyNotify);
 
-    if (is<KeyframeEffect>(m_effect)) {
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get())) {
         updateRelevance();
-        downcast<KeyframeEffect>(*m_effect).animationTimingDidChange();
+        keyframeEffect->animationTimingDidChange();
     }
 
     if (silently == Silently::No && m_timeline)
@@ -849,8 +849,8 @@
 
 void WebAnimation::invalidateEffect()
 {
-    if (!isEffectInvalidationSuspended() && is<KeyframeEffect>(m_effect))
-        downcast<KeyframeEffect>(*m_effect).invalidate();
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get()); !isEffectInvalidationSuspended() && keyframeEffect)
+        keyframeEffect->invalidate();
 }
 
 void WebAnimation::updateFinishedState(DidSeek didSeek, SynchronouslyNotify synchronouslyNotify)
@@ -962,8 +962,8 @@
     //    Otherwise, queue a task to dispatch finishEvent at animation. The task source for this task is the DOM manipulation task source.
     enqueueAnimationPlaybackEvent(eventNames().finishEvent, currentTime(), m_timeline ? m_timeline->currentTime() : std::nullopt);
 
-    if (is<KeyframeEffect>(m_effect)) {
-        if (RefPtr target = downcast<KeyframeEffect>(*m_effect).target()) {
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get())) {
+        if (RefPtr target = keyframeEffect->target()) {
             if (auto* page = target->document().page())
                 page->chrome().client().animationDidFinishForElement(*target);
         }
@@ -1287,8 +1287,8 @@
         updateFinishedState(DidSeek::No, SynchronouslyNotify::Yes);
     m_shouldSkipUpdatingFinishedStateWhenResolving = false;
 
-    if (is<KeyframeEffect>(m_effect))
-        downcast<KeyframeEffect>(*m_effect).apply(targetStyle, resolutionContext, startTime);
+    if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get()))
+        keyframeEffect->apply(targetStyle, resolutionContext, startTime);
 }
 
 void WebAnimation::setSuspended(bool isSuspended)
@@ -1417,11 +1417,10 @@
     auto previousReplaceState = std::exchange(m_replaceState, ReplaceState::Persisted);
 
     if (previousReplaceState == ReplaceState::Removed && m_timeline) {
-        if (is<KeyframeEffect>(m_effect)) {
-            auto& keyframeEffect = downcast<KeyframeEffect>(*m_effect);
-            auto styleable = keyframeEffect.targetStyleable();
+        if (auto keyframeEffect = dynamicDowncast<KeyframeEffect>(m_effect.get())) {
+            auto styleable = keyframeEffect->targetStyleable();
             styleable->animationWasAdded(*this);
-            styleable->ensureKeyframeEffectStack().addEffect(keyframeEffect);
+            styleable->ensureKeyframeEffectStack().addEffect(*keyframeEffect);
         }
     }
 }
@@ -1431,7 +1430,7 @@
     // https://drafts.csswg.org/web-animations-1/#commit-computed-styles
 
     // 1. Let targets be the set of all effect targets for animation effects associated with animation.
-    auto* effect = is<KeyframeEffect>(m_effect) ? downcast<KeyframeEffect>(m_effect.get()) : nullptr;
+    auto* effect = dynamicDowncast<KeyframeEffect>(m_effect.get());
     auto* target = effect ? effect->target() : nullptr;
 
     // 2. For each target in targets:
diff --git a/Source/WebCore/bindings/js/JSEventListener.cpp b/Source/WebCore/bindings/js/JSEventListener.cpp
index c877d27..059dfea 100644
--- a/Source/WebCore/bindings/js/JSEventListener.cpp
+++ b/Source/WebCore/bindings/js/JSEventListener.cpp
@@ -151,7 +151,7 @@
         if (!window->wrapped().isCurrentlyDisplayedInFrame())
             return;
         if (wasCreatedFromMarkup()) {
-            Element* element = event.target()->isNode() && !downcast<Node>(*event.target()).isDocumentNode() && is<Element>(*event.target()) ? downcast<Element>(event.target()) : nullptr;
+            Element* element = event.target()->isNode() && !downcast<Node>(*event.target()).isDocumentNode() ? dynamicDowncast<Element>(*event.target()) : nullptr;
             if (!scriptExecutionContext.contentSecurityPolicy()->allowInlineEventHandlers(sourceURL().string(), sourcePosition().m_line, code(), element))
                 return;
         }
diff --git a/Source/WebCore/bindings/js/JSLazyEventListener.cpp b/Source/WebCore/bindings/js/JSLazyEventListener.cpp
index abf18d8..6928556 100644
--- a/Source/WebCore/bindings/js/JSLazyEventListener.cpp
+++ b/Source/WebCore/bindings/js/JSLazyEventListener.cpp
@@ -84,19 +84,12 @@
 #if ASSERT_ENABLED
 static inline bool isCloneInShadowTreeOfSVGUseElement(Node& originalNode, EventTarget& eventTarget)
 {
-    if (!eventTarget.isNode())
+    auto* element = dynamicDowncast<SVGElement>(eventTarget);
+    if (!element || !element->correspondingElement())
         return false;
 
-    auto& node = downcast<Node>(eventTarget);
-    if (!is<SVGElement>(node))
-        return false;
-
-    auto& element = downcast<SVGElement>(node);
-    if (!element.correspondingElement())
-        return false;
-
-    ASSERT(element.isInShadowTree());
-    return &originalNode == element.correspondingElement();
+    ASSERT(element->isInShadowTree());
+    return &originalNode == element->correspondingElement();
 }
 
 // This is to help find the underlying cause of <rdar://problem/24314027>.
@@ -131,7 +124,7 @@
     if (!document.frame())
         return nullptr;
 
-    Element* element = m_originalNode && !m_originalNode->isDocumentNode() && is<Element>(*m_originalNode) ? downcast<Element>(m_originalNode.get()) : nullptr;
+    auto* element =  dynamicDowncast<Element>(m_originalNode.get());
     if (!document.contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL.string(), m_sourcePosition.m_line, m_code, element))
         return nullptr;
 
diff --git a/Source/WebCore/css/CSSFontSelector.cpp b/Source/WebCore/css/CSSFontSelector.cpp
index bb249c8..f8a9187 100644
--- a/Source/WebCore/css/CSSFontSelector.cpp
+++ b/Source/WebCore/css/CSSFontSelector.cpp
@@ -355,7 +355,7 @@
 
     if (resolveGenericFamilyFirst)
         resolveAndAssignGenericFamily();
-    Document* document = is<Document>(m_context) ? &downcast<Document>(*m_context) : nullptr;
+    auto* document = dynamicDowncast<Document>(m_context.get());
     auto* face = m_cssFontFaceSet->fontFace(fontDescriptionForLookup->fontSelectionRequest(), familyForLookup);
     if (face) {
         if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
diff --git a/Source/WebCore/css/CSSStyleSheet.cpp b/Source/WebCore/css/CSSStyleSheet.cpp
index dbc67d7..f4618ef 100644
--- a/Source/WebCore/css/CSSStyleSheet.cpp
+++ b/Source/WebCore/css/CSSStyleSheet.cpp
@@ -268,7 +268,7 @@
     if (!rule)
         return Exception { SyntaxError };
 
-    RuleMutationScope mutationScope(this, RuleInsertion, is<StyleRuleKeyframes>(*rule) ? downcast<StyleRuleKeyframes>(rule.get()) : nullptr);
+    RuleMutationScope mutationScope(this, RuleInsertion, dynamicDowncast<StyleRuleKeyframes>(*rule));
 
     bool success = m_contents.get().wrapperInsertRule(rule.releaseNonNull(), index);
     if (!success)
diff --git a/Source/WebCore/dom/Attr.cpp b/Source/WebCore/dom/Attr.cpp
index b7d0e1d..12c4026 100644
--- a/Source/WebCore/dom/Attr.cpp
+++ b/Source/WebCore/dom/Attr.cpp
@@ -112,10 +112,11 @@
 {
     // This is not part of the DOM API, and therefore not available to webpages. However, WebKit SPI
     // lets clients use this via the Objective-C and JavaScript bindings.
-    if (!is<StyledElement>(m_element))
+    auto styledElement = dynamicDowncast<StyledElement>(m_element);
+    if (!styledElement)
         return nullptr;
     m_style = MutableStyleProperties::create();
-    downcast<StyledElement>(*m_element).collectPresentationalHintsForAttribute(qualifiedName(), value(), *m_style);
+    styledElement->collectPresentationalHintsForAttribute(qualifiedName(), value(), *m_style);
     return &m_style->ensureCSSStyleDeclaration();
 }
 
diff --git a/Source/WebCore/dom/BroadcastChannel.cpp b/Source/WebCore/dom/BroadcastChannel.cpp
index 6329dea..e76253c 100644
--- a/Source/WebCore/dom/BroadcastChannel.cpp
+++ b/Source/WebCore/dom/BroadcastChannel.cpp
@@ -108,8 +108,8 @@
     ASSERT(context->isContextThread());
 
     Ref protectedThis { *this };
-    if (is<Document>(*context))
-        task(downcast<Document>(*context));
+    if (auto document = dynamicDowncast<Document>(*context))
+        task(*document);
     else {
         downcast<WorkerGlobalScope>(*context).thread().workerLoaderProxy().postTaskToLoader([protectedThis = WTFMove(protectedThis), task = WTFMove(task)](auto& context) {
             task(downcast<Document>(context));
@@ -265,8 +265,8 @@
     if (!context)
         return false;
 
-    if (is<Document>(*context))
-        return downcast<Document>(*context).isFullyActive();
+    if (auto document = dynamicDowncast<Document>(*context))
+        return document->isFullyActive();
 
     return !downcast<WorkerGlobalScope>(*context).isClosing();
 }
diff --git a/Source/WebCore/dom/CharacterData.cpp b/Source/WebCore/dom/CharacterData.cpp
index fd2454f..6157f33 100644
--- a/Source/WebCore/dom/CharacterData.cpp
+++ b/Source/WebCore/dom/CharacterData.cpp
@@ -118,8 +118,8 @@
         m_data.append(string.characters16() + offset, characterLengthLimit);
 
     ASSERT(!renderer() || is<Text>(*this));
-    if (is<Text>(*this))
-        downcast<Text>(*this).updateRendererAfterContentChange(oldLength, 0);
+    if (auto text = dynamicDowncast<Text>(*this))
+        text->updateRendererAfterContentChange(oldLength, 0);
 
     notifyParentAfterChange(childChange);
 
@@ -206,11 +206,11 @@
         document().textInserted(*this, offsetOfReplacedData, newLength);
 
     ASSERT(!renderer() || is<Text>(*this));
-    if (is<Text>(*this))
-        downcast<Text>(*this).updateRendererAfterContentChange(offsetOfReplacedData, oldLength);
+    if (auto text = dynamicDowncast<Text>(*this))
+        text->updateRendererAfterContentChange(offsetOfReplacedData, oldLength);
 
-    if (is<ProcessingInstruction>(*this))
-        downcast<ProcessingInstruction>(*this).checkStyleSheet();
+    if (auto processingIntruction = dynamicDowncast<ProcessingInstruction>(*this))
+        processingIntruction->checkStyleSheet();
 
     if (document().frame())
         document().frame()->selection().textWasReplaced(this, offsetOfReplacedData, oldLength, newLength);
diff --git a/Source/WebCore/dom/CharacterData.h b/Source/WebCore/dom/CharacterData.h
index 36a4925..52003d7 100644
--- a/Source/WebCore/dom/CharacterData.h
+++ b/Source/WebCore/dom/CharacterData.h
@@ -72,8 +72,8 @@
 
 inline unsigned Node::length() const
 {
-    if (is<CharacterData>(*this))
-        return downcast<CharacterData>(*this).length();
+    if (auto characterData = dynamicDowncast<CharacterData>(*this))
+        return characterData->length();
     return countChildNodes();
 }
 
diff --git a/Source/WebCore/dom/ComposedTreeAncestorIterator.h b/Source/WebCore/dom/ComposedTreeAncestorIterator.h
index c661bce..89a68e0 100644
--- a/Source/WebCore/dom/ComposedTreeAncestorIterator.h
+++ b/Source/WebCore/dom/ComposedTreeAncestorIterator.h
@@ -72,8 +72,8 @@
         m_current = nullptr;
         return *this;
     }
-    if (is<ShadowRoot>(*parent)) {
-        m_current = downcast<ShadowRoot>(*parent).host();
+    if (auto shadowRoot = dynamicDowncast<ShadowRoot>(*parent)) {
+        m_current = shadowRoot->host();
         return *this;
     }
     if (!is<Element>(*parent)) {
@@ -100,10 +100,10 @@
 
     iterator begin()
     {
-        if (is<ShadowRoot>(m_node))
-            return iterator(*downcast<ShadowRoot>(m_node).host());
-        if (is<PseudoElement>(m_node))
-            return iterator(*downcast<PseudoElement>(m_node).hostElement());
+        if (auto shadowRoot = dynamicDowncast<ShadowRoot>(m_node))
+            return iterator(*shadowRoot->host());
+        if (auto pseudoElement = dynamicDowncast<PseudoElement>(m_node))
+            return iterator(*pseudoElement->hostElement());
         return iterator(m_node).traverseParent();
     }
     iterator end()
diff --git a/Source/WebCore/dom/ComposedTreeIterator.h b/Source/WebCore/dom/ComposedTreeIterator.h
index cc4f202..622061f 100644
--- a/Source/WebCore/dom/ComposedTreeIterator.h
+++ b/Source/WebCore/dom/ComposedTreeIterator.h
@@ -224,8 +224,8 @@
 {
     if (auto* shadowRoot = shadowRootIgnoringUserAgentShadow(node))
         return shadowRoot->firstChild();
-    if (is<HTMLSlotElement>(node)) {
-        if (auto* assignedNodes = downcast<HTMLSlotElement>(node).assignedNodes())
+    if (auto slot = dynamicDowncast<HTMLSlotElement>(node)) {
+        if (auto* assignedNodes = slot->assignedNodes())
             return assignedNodes->at(0).get();
     }
     return node.firstChild();
diff --git a/Source/WebCore/dom/ContainerNode.cpp b/Source/WebCore/dom/ContainerNode.cpp
index 649b21a..3c17156a1 100644
--- a/Source/WebCore/dom/ContainerNode.cpp
+++ b/Source/WebCore/dom/ContainerNode.cpp
@@ -179,8 +179,8 @@
         // FIXME: Merge these two code paths. It's a bug in the parser not to update connectedSubframeCount in time.
         disconnectSubframesIfNeeded(*this, DescendantsOnly);
     } else {
-        if (is<ContainerNode>(childToRemove))
-            disconnectSubframesIfNeeded(downcast<ContainerNode>(childToRemove), RootAndDescendants);
+        if (auto containerChild = dynamicDowncast<ContainerNode>(childToRemove))
+            disconnectSubframesIfNeeded(*containerChild, RootAndDescendants);
     }
 
     if (childToRemove.parentNode() != this)
@@ -276,25 +276,24 @@
 
 ExceptionOr<void> ContainerNode::removeSelfOrChildNodesForInsertion(Node& child, NodeVector& nodesForInsertion)
 {
-    if (!is<DocumentFragment>(child)) {
-        nodesForInsertion.append(child);
-        RefPtr oldParent = child.parentNode();
-        if (!oldParent)
+    if (auto fragment = dynamicDowncast<DocumentFragment>(child)) {
+        if (!fragment->hasChildNodes())
             return { };
-        return oldParent->removeChild(child);
+
+        auto removedChildNodes = fragment->removeAllChildrenWithScriptAssertion(ContainerNode::ChildChange::Source::API);
+        nodesForInsertion.swap(removedChildNodes);
+
+        fragment->rebuildSVGExtensionsElementsIfNecessary();
+        fragment->dispatchSubtreeModifiedEvent();
+
+        return { };
     }
 
-    auto& fragment = downcast<DocumentFragment>(child);
-    if (!fragment.hasChildNodes())
+    nodesForInsertion.append(child);
+    RefPtr oldParent = child.parentNode();
+    if (!oldParent)
         return { };
-
-    auto removedChildNodes = fragment.removeAllChildrenWithScriptAssertion(ContainerNode::ChildChange::Source::API);
-    nodesForInsertion.swap(removedChildNodes);
-
-    fragment.rebuildSVGExtensionsElementsIfNecessary();
-    fragment.dispatchSubtreeModifiedEvent();
-
-    return { };
+    return oldParent->removeChild(child);
 }
 
 // FIXME: This function must get a new name.
@@ -313,14 +312,14 @@
 
 static inline void destroyRenderTreeIfNeeded(Node& child)
 {
-    bool isElement = is<Element>(child);
-    auto hasDisplayContents = isElement && downcast<Element>(child).hasDisplayContents();
+    auto childAsElement = dynamicDowncast<Element>(child);
+    auto hasDisplayContents = childAsElement && childAsElement->hasDisplayContents();
     if (!child.renderer() && !hasDisplayContents)
         return;
-    if (isElement)
-        RenderTreeUpdater::tearDownRenderers(downcast<Element>(child));
-    else if (is<Text>(child))
-        RenderTreeUpdater::tearDownRenderer(downcast<Text>(child));
+    if (childAsElement)
+        RenderTreeUpdater::tearDownRenderers(*childAsElement);
+    else if (auto text = dynamicDowncast<Text>(child))
+        RenderTreeUpdater::tearDownRenderer(*text);
 }
 
 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
@@ -365,8 +364,8 @@
             return true;
         const ContainerNode* parent = currentNode->parentNode();
         if (!parent) {
-            if (is<ShadowRoot>(currentNode))
-                parent = downcast<ShadowRoot>(currentNode)->host();
+            if (auto shadowRoot = dynamicDowncast<ShadowRoot>(currentNode))
+                parent = shadowRoot->host();
             else if (is<DocumentFragment>(*currentNode) && downcast<DocumentFragment>(*currentNode).isTemplateContent())
                 parent = static_cast<const TemplateContentDocumentFragment*>(currentNode)->host();
         }
@@ -399,8 +398,8 @@
     if (shouldValidateChildParent == ShouldValidateChildParent::Yes && refChild && refChild->parentNode() != &newParent)
         return Exception { NotFoundError };
 
-    if (is<Document>(newParent)) {
-        if (!downcast<Document>(newParent).canAcceptChild(newChild, refChild, operation))
+    if (auto newParentDocument = dynamicDowncast<Document>(newParent)) {
+        if (!newParentDocument->canAcceptChild(newChild, refChild, operation))
             return Exception { HierarchyRequestError };
     } else if (!isChildTypeAllowed(newParent, newChild))
         return Exception { HierarchyRequestError };
diff --git a/Source/WebCore/dom/ContainerNode.h b/Source/WebCore/dom/ContainerNode.h
index d390fe7..23e8870 100644
--- a/Source/WebCore/dom/ContainerNode.h
+++ b/Source/WebCore/dom/ContainerNode.h
@@ -174,30 +174,26 @@
 
 inline unsigned Node::countChildNodes() const
 {
-    if (!is<ContainerNode>(*this))
-        return 0;
-    return downcast<ContainerNode>(*this).countChildNodes();
+    auto* containerNode = dynamicDowncast<ContainerNode>(*this);
+    return containerNode ? containerNode->countChildNodes() : 0;
 }
 
 inline Node* Node::traverseToChildAt(unsigned index) const
 {
-    if (!is<ContainerNode>(*this))
-        return nullptr;
-    return downcast<ContainerNode>(*this).traverseToChildAt(index);
+    auto* containerNode = dynamicDowncast<ContainerNode>(*this);
+    return containerNode ? containerNode->traverseToChildAt(index) : nullptr;
 }
 
 inline Node* Node::firstChild() const
 {
-    if (!is<ContainerNode>(*this))
-        return nullptr;
-    return downcast<ContainerNode>(*this).firstChild();
+    auto* containerNode = dynamicDowncast<ContainerNode>(*this);
+    return containerNode ? containerNode->firstChild() : nullptr;
 }
 
 inline Node* Node::lastChild() const
 {
-    if (!is<ContainerNode>(*this))
-        return nullptr;
-    return downcast<ContainerNode>(*this).lastChild();
+    auto* containerNode = dynamicDowncast<ContainerNode>(*this);
+    return containerNode ? containerNode->lastChild() : nullptr;
 }
 
 inline Node& Node::rootNode() const
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index a70263b..78caaae 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -470,12 +470,8 @@
 
 static Widget* widgetForElement(Element* focusedElement)
 {
-    if (!focusedElement)
-        return nullptr;
-    auto* renderer = focusedElement->renderer();
-    if (!is<RenderWidget>(renderer))
-        return nullptr;
-    return downcast<RenderWidget>(*renderer).widget();
+    auto* renderer = focusedElement ? dynamicDowncast<RenderWidget>(focusedElement->renderer()) : nullptr;
+    return renderer ? renderer->widget() : nullptr;
 }
 
 static bool acceptsEditingFocus(const Element& element)
@@ -895,13 +891,13 @@
     m_accessKeyCache = makeUnique<HashMap<String, WeakPtr<Element>, ASCIICaseInsensitiveHash>>([this] {
         HashMap<String, WeakPtr<Element>, ASCIICaseInsensitiveHash> map;
         for (auto& node : composedTreeDescendants(*this)) {
-            if (!is<Element>(node))
+            auto element = dynamicDowncast<Element>(node);
+            if (!element)
                 continue;
-            auto& element = downcast<Element>(node);
-            auto& key = element.attributeWithoutSynchronization(accesskeyAttr);
+            auto& key = element->attributeWithoutSynchronization(accesskeyAttr);
             if (key.isEmpty())
                 continue;
-            map.add(key, element);
+            map.add(key, *element);
         }
         return map;
     }());
@@ -4499,7 +4495,7 @@
     if (isNodeInSubtree(*focusedElement, node, nodeRemoval)) {
         // FIXME: We should avoid synchronously updating the style inside setFocusedElement.
         // FIXME: Object elements should avoid loading a frame synchronously in a post style recalc callback.
-        SubframeLoadingDisabler disabler(is<ContainerNode>(node) ? &downcast<ContainerNode>(node) : nullptr);
+        SubframeLoadingDisabler disabler(dynamicDowncast<ContainerNode>(node));
         setFocusedElement(nullptr, { { }, { }, FocusRemovalEventsMode::DoNotDispatch, { }, { } });
         // Set the focus navigation starting node to the previous focused element so that
         // we can fallback to the siblings or parent node for the next search.
diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp
index 5d25077..5130485 100644
--- a/Source/WebCore/dom/Element.cpp
+++ b/Source/WebCore/dom/Element.cpp
@@ -2296,7 +2296,7 @@
 
     bool becomeConnected = insertionType.connectedToDocument;
     TreeScope* newScope = &parentOfInsertedTree.treeScope();
-    HTMLDocument* newDocument = becomeConnected && is<HTMLDocument>(newScope->documentScope()) ? &downcast<HTMLDocument>(newScope->documentScope()) : nullptr;
+    auto* newDocument = becomeConnected ? dynamicDowncast<HTMLDocument>(newScope->documentScope()) : nullptr;
     if (!insertionType.treeScopeChanged)
         newScope = nullptr;
 
@@ -2358,7 +2358,7 @@
     if (oldParentOfRemovedTree.isInTreeScope()) {
         TreeScope* oldScope = &oldParentOfRemovedTree.treeScope();
         Document* oldDocument = removalType.disconnectedFromDocument ? &oldScope->documentScope() : nullptr;
-        HTMLDocument* oldHTMLDocument = oldDocument && is<HTMLDocument>(*oldDocument) ? &downcast<HTMLDocument>(*oldDocument) : nullptr;
+        auto* oldHTMLDocument = dynamicDowncast<HTMLDocument>(oldDocument);
         if (!removalType.treeScopeChanged)
             oldScope = nullptr;
 
diff --git a/Source/WebCore/dom/ElementInlines.h b/Source/WebCore/dom/ElementInlines.h
index 860c049..3f857a6 100644
--- a/Source/WebCore/dom/ElementInlines.h
+++ b/Source/WebCore/dom/ElementInlines.h
@@ -61,8 +61,7 @@
 
 inline Element* Node::parentElement() const
 {
-    ContainerNode* parent = parentNode();
-    return is<Element>(parent) ? downcast<Element>(parent) : nullptr;
+    return dynamicDowncast<Element>(parentNode());
 }
 
 inline const Element* Element::rootElement() const
diff --git a/Source/WebCore/dom/EventDispatcher.cpp b/Source/WebCore/dom/EventDispatcher.cpp
index 3991214..0effe06 100644
--- a/Source/WebCore/dom/EventDispatcher.cpp
+++ b/Source/WebCore/dom/EventDispatcher.cpp
@@ -174,7 +174,7 @@
     InputElementClickState clickHandlingState;
 
     bool isActivationEvent = event.type() == eventNames().clickEvent;
-    RefPtr<HTMLInputElement> inputForLegacyPreActivationBehavior = is<HTMLInputElement>(node) ? &downcast<HTMLInputElement>(node) : nullptr;
+    RefPtr inputForLegacyPreActivationBehavior = dynamicDowncast<HTMLInputElement>(node);
     if (!inputForLegacyPreActivationBehavior && isActivationEvent && event.bubbles())
         inputForLegacyPreActivationBehavior = findInputElementInEventPath(eventPath);
     if (inputForLegacyPreActivationBehavior)
diff --git a/Source/WebCore/dom/MouseEvent.cpp b/Source/WebCore/dom/MouseEvent.cpp
index dac3e08..59d39ab 100644
--- a/Source/WebCore/dom/MouseEvent.cpp
+++ b/Source/WebCore/dom/MouseEvent.cpp
@@ -203,7 +203,7 @@
         target = relatedTarget();
     else
         target = this->target();
-    return is<Node>(target) ? &downcast<Node>(*target) : nullptr;
+    return dynamicDowncast<Node>(target);
 }
 
 RefPtr<Node> MouseEvent::fromElement() const
@@ -214,7 +214,7 @@
         target = this->target();
     else
         target = relatedTarget();
-    return is<Node>(target) ? &downcast<Node>(*target) : nullptr;
+    return dynamicDowncast<Node>(target);
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index 3b77754..65e6ab24 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -801,14 +801,12 @@
 
 RenderBox* Node::renderBox() const
 {
-    RenderObject* renderer = this->renderer();
-    return is<RenderBox>(renderer) ? downcast<RenderBox>(renderer) : nullptr;
+    return dynamicDowncast<RenderBox>(renderer());
 }
 
 RenderBoxModelObject* Node::renderBoxModelObject() const
 {
-    RenderObject* renderer = this->renderer();
-    return is<RenderBoxModelObject>(renderer) ? downcast<RenderBoxModelObject>(renderer) : nullptr;
+    return dynamicDowncast<RenderBoxModelObject>(renderer());
 }
     
 LayoutRect Node::renderRect(bool* isReplaced)
@@ -1149,8 +1147,7 @@
 
 ShadowRoot* Node::containingShadowRoot() const
 {
-    ContainerNode& root = treeScope().rootNode();
-    return is<ShadowRoot>(root) ? downcast<ShadowRoot>(&root) : nullptr;
+    return dynamicDowncast<ShadowRoot>(treeScope().rootNode());
 }
 
 #if ASSERT_ENABLED
@@ -1644,8 +1641,8 @@
     if (&otherNode == this)
         return DOCUMENT_POSITION_EQUIVALENT;
     
-    Attr* attr1 = is<Attr>(*this) ? downcast<Attr>(this) : nullptr;
-    Attr* attr2 = is<Attr>(otherNode) ? &downcast<Attr>(otherNode) : nullptr;
+    auto* attr1 = dynamicDowncast<Attr>(*this);
+    auto* attr2 = dynamicDowncast<Attr>(otherNode);
     
     Node* start1 = attr1 ? attr1->ownerElement() : this;
     Node* start2 = attr2 ? attr2->ownerElement() : &otherNode;
diff --git a/Source/WebCore/dom/Position.cpp b/Source/WebCore/dom/Position.cpp
index 7def162..37766e0 100644
--- a/Source/WebCore/dom/Position.cpp
+++ b/Source/WebCore/dom/Position.cpp
@@ -185,7 +185,7 @@
 {
     switch (anchorType()) {
     case PositionIsOffsetInAnchor:
-        return m_anchorNode && is<Text>(*m_anchorNode) ? downcast<Text>(m_anchorNode.get()) : nullptr;
+        return dynamicDowncast<Text>(m_anchorNode.get());
     case PositionIsBeforeAnchor:
     case PositionIsAfterAnchor:
         return nullptr;
diff --git a/Source/WebCore/dom/TextNodeTraversal.cpp b/Source/WebCore/dom/TextNodeTraversal.cpp
index b78ca79..776c2cb 100644
--- a/Source/WebCore/dom/TextNodeTraversal.cpp
+++ b/Source/WebCore/dom/TextNodeTraversal.cpp
@@ -47,10 +47,10 @@
 
 String contentsAsString(const Node& root)
 {
-    if (is<Text>(root))
-        return downcast<Text>(root).data();
-    if (is<ContainerNode>(root))
-        return contentsAsString(downcast<ContainerNode>(root));
+    if (auto text = dynamicDowncast<Text>(root))
+        return text->data();
+    if (auto containerNode = dynamicDowncast<ContainerNode>(root))
+        return contentsAsString(*containerNode);
     return String();
 }
 
diff --git a/Source/WebCore/dom/TreeScope.cpp b/Source/WebCore/dom/TreeScope.cpp
index 8f6c47f..e296761 100644
--- a/Source/WebCore/dom/TreeScope.cpp
+++ b/Source/WebCore/dom/TreeScope.cpp
@@ -414,8 +414,8 @@
         if (!node)
             continue;
 
-        if (is<PseudoElement>(node))
-            node = downcast<PseudoElement>(*node).hostElement();
+        if (auto pseudoElement = dynamicDowncast<PseudoElement>(*node))
+            node = pseudoElement->hostElement();
 
         // Prune duplicate entries. A pseudo ::before content above its parent
         // node should only result in one entry.
diff --git a/Source/WebCore/dom/TypedElementDescendantIterator.h b/Source/WebCore/dom/TypedElementDescendantIterator.h
index 6bcd5c4..c313c2c 100644
--- a/Source/WebCore/dom/TypedElementDescendantIterator.h
+++ b/Source/WebCore/dom/TypedElementDescendantIterator.h
@@ -170,8 +170,8 @@
 template<typename ElementType> ElementDescendantIterator<ElementType> ElementDescendantRange<ElementType>::from(Element& descendant) const
 {
     ASSERT(descendant.isDescendantOf(m_root));
-    if (is<ElementType>(descendant))
-        return ElementDescendantIterator<ElementType>(m_root, downcast<ElementType>(&descendant));
+    if (auto descendantElement = dynamicDowncast<ElementType>(descendant))
+        return ElementDescendantIterator<ElementType>(m_root, descendantElement);
     ElementType* next = Traversal<ElementType>::next(descendant, &m_root);
     return ElementDescendantIterator<ElementType>(m_root, next);
 }
@@ -207,8 +207,8 @@
 template<typename ElementType> ElementDescendantIterator<ElementType> InclusiveElementDescendantRange<ElementType>::from(Element& descendant) const
 {
     ASSERT(&m_root == &descendant || descendant.isDescendantOf(m_root));
-    if (is<ElementType>(descendant))
-        return ElementDescendantIterator<ElementType>(m_root, downcast<ElementType>(&descendant));
+    if (auto descendantElement = dynamicDowncast<ElementType>(descendant))
+        return ElementDescendantIterator<ElementType>(m_root, descendantElement);
     ElementType* next = Traversal<ElementType>::next(descendant, &m_root);
     return ElementDescendantIterator<ElementType>(m_root, next);
 }
diff --git a/Source/WebCore/dom/VisitedLinkState.cpp b/Source/WebCore/dom/VisitedLinkState.cpp
index 131591b..c587c4e 100644
--- a/Source/WebCore/dom/VisitedLinkState.cpp
+++ b/Source/WebCore/dom/VisitedLinkState.cpp
@@ -71,10 +71,10 @@
 
 inline static std::optional<SharedStringHash> linkHashForElement(const Element& element)
 {
-    if (is<HTMLAnchorElement>(element))
-        return downcast<HTMLAnchorElement>(element).visitedLinkHash();
-    if (is<SVGAElement>(element))
-        return downcast<SVGAElement>(element).visitedLinkHash();
+    if (auto anchor = dynamicDowncast<HTMLAnchorElement>(element))
+        return anchor->visitedLinkHash();
+    if (auto anchor = dynamicDowncast<SVGAElement>(element))
+        return anchor->visitedLinkHash();
     return std::nullopt;
 }
 
diff --git a/Source/WebCore/dom/messageports/MessagePortChannelProvider.cpp b/Source/WebCore/dom/messageports/MessagePortChannelProvider.cpp
index fc513ee..341c03c 100644
--- a/Source/WebCore/dom/messageports/MessagePortChannelProvider.cpp
+++ b/Source/WebCore/dom/messageports/MessagePortChannelProvider.cpp
@@ -57,11 +57,11 @@
 
 MessagePortChannelProvider& MessagePortChannelProvider::fromContext(ScriptExecutionContext& context)
 {
-    if (is<Document>(context))
-        return downcast<Document>(context).messagePortChannelProvider();
+    if (auto document = dynamicDowncast<Document>(context))
+        return document->messagePortChannelProvider();
 
-    if (is<WorkletGlobalScope>(context))
-        return downcast<WorkletGlobalScope>(context).messagePortChannelProvider();
+    if (auto workletScope = dynamicDowncast<WorkletGlobalScope>(context))
+        return workletScope->messagePortChannelProvider();
 
     return downcast<WorkerGlobalScope>(context).messagePortChannelProvider();
 }
diff --git a/Source/WebCore/editing/Editing.cpp b/Source/WebCore/editing/Editing.cpp
index 980dde8..7d9d59b 100644
--- a/Source/WebCore/editing/Editing.cpp
+++ b/Source/WebCore/editing/Editing.cpp
@@ -321,8 +321,7 @@
 // knowing about these kinds of special cases.
 Element* enclosingBlock(Node* node, EditingBoundaryCrossingRule rule)
 {
-    Node* enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule);
-    return is<Element>(enclosingNode) ? downcast<Element>(enclosingNode) : nullptr;
+    return dynamicDowncast<Element>(enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule));
 }
 
 TextDirection directionOfEnclosingBlock(const Position& position)
diff --git a/Source/WebCore/html/HTMLOptGroupElement.cpp b/Source/WebCore/html/HTMLOptGroupElement.cpp
index 8c749c6..ee9fe1f 100644
--- a/Source/WebCore/html/HTMLOptGroupElement.cpp
+++ b/Source/WebCore/html/HTMLOptGroupElement.cpp
@@ -122,8 +122,7 @@
     
 HTMLSelectElement* HTMLOptGroupElement::ownerSelectElement() const
 {
-    auto* parent = parentNode();
-    return is<HTMLSelectElement>(parent) ? downcast<HTMLSelectElement>(parent) : nullptr;
+    return dynamicDowncast<HTMLSelectElement>(parentNode());
 }
 
 bool HTMLOptGroupElement::accessKeyAction(bool)
diff --git a/Source/WebCore/html/HTMLPlugInImageElement.cpp b/Source/WebCore/html/HTMLPlugInImageElement.cpp
index 82c389e..91dd90f 100644
--- a/Source/WebCore/html/HTMLPlugInImageElement.cpp
+++ b/Source/WebCore/html/HTMLPlugInImageElement.cpp
@@ -74,7 +74,7 @@
 RenderEmbeddedObject* HTMLPlugInImageElement::renderEmbeddedObject() const
 {
     // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers when using fallback content.
-    return is<RenderEmbeddedObject>(renderer()) ? downcast<RenderEmbeddedObject>(renderer()) : nullptr;
+    return dynamicDowncast<RenderEmbeddedObject>(renderer());
 }
 
 bool HTMLPlugInImageElement::isImageType()
diff --git a/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp b/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
index a1be115..b8b5fb6 100644
--- a/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
+++ b/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
@@ -794,7 +794,7 @@
     bool isPendingPolicyResolution = false;
     HostWindow* hostWindow = nullptr;
 
-    auto* canvasElement = is<HTMLCanvasElement>(canvas) ? &downcast<HTMLCanvasElement>(canvas) : nullptr;
+    auto* canvasElement = dynamicDowncast<HTMLCanvasElement>(canvas);
 
     if (canvasElement) {
         Document& document = canvasElement->document();
diff --git a/Source/WebCore/layout/Verification.cpp b/Source/WebCore/layout/Verification.cpp
index 3c19715..531d24c 100644
--- a/Source/WebCore/layout/Verification.cpp
+++ b/Source/WebCore/layout/Verification.cpp
@@ -134,7 +134,7 @@
     for (unsigned inlineBoxIndex = 0; inlineBoxIndex < inlineBoxes.size() && boxIndex < boxes.size(); ++inlineBoxIndex) {
         auto& box = boxes[boxIndex];
         auto* inlineBox = inlineBoxes[inlineBoxIndex];
-        auto* inlineTextBox = is<WebCore::LegacyInlineTextBox>(inlineBox) ? downcast<WebCore::LegacyInlineTextBox>(inlineBox) : nullptr;
+        auto* inlineTextBox = dynamicDowncast<WebCore::LegacyInlineTextBox>(inlineBox);
         bool matchingRuns = inlineTextBox ? checkForMatchingTextRuns(box, *inlineTextBox) : checkForMatchingNonTextRuns(box, *inlineBox);
 
         if (!matchingRuns) {
diff --git a/Source/WebCore/page/AutoscrollController.cpp b/Source/WebCore/page/AutoscrollController.cpp
index b00c518..344cdfb 100644
--- a/Source/WebCore/page/AutoscrollController.cpp
+++ b/Source/WebCore/page/AutoscrollController.cpp
@@ -136,7 +136,7 @@
 
     while (renderer && !(is<RenderBox>(*renderer) && downcast<RenderBox>(*renderer).canAutoscroll()))
         renderer = renderer->parent();
-    m_autoscrollRenderer = is<RenderBox>(renderer) ? downcast<RenderBox>(renderer) : nullptr;
+    m_autoscrollRenderer = dynamicDowncast<RenderBox>(renderer);
 }
 
 void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoint& eventPosition, WallTime eventTime)
diff --git a/Source/WebCore/page/DOMTimer.cpp b/Source/WebCore/page/DOMTimer.cpp
index 889052e..645b699 100644
--- a/Source/WebCore/page/DOMTimer.cpp
+++ b/Source/WebCore/page/DOMTimer.cpp
@@ -332,7 +332,7 @@
         nestedTimers->startTracking();
 
 #if ENABLE(CONTENT_CHANGE_OBSERVER)
-    ContentChangeObserver::DOMTimerScope observingScope(is<Document>(context) ? &downcast<Document>(context) : nullptr, *this);
+    ContentChangeObserver::DOMTimerScope observingScope(dynamicDowncast<Document>(context), *this);
 #endif
     m_action->execute(context);
 
diff --git a/Source/WebCore/page/DragController.cpp b/Source/WebCore/page/DragController.cpp
index 1399568..f4b8c87 100644
--- a/Source/WebCore/page/DragController.cpp
+++ b/Source/WebCore/page/DragController.cpp
@@ -343,10 +343,8 @@
     auto* inputElement = &downcast<HTMLInputElement>(node);
 
     // If this is a button inside of the a file input, move up to the file input.
-    if (inputElement->isTextButton() && is<ShadowRoot>(inputElement->treeScope().rootNode())) {
-        auto& host = *downcast<ShadowRoot>(inputElement->treeScope().rootNode()).host();
-        inputElement = is<HTMLInputElement>(host) ? &downcast<HTMLInputElement>(host) : nullptr;
-    }
+    if (inputElement->isTextButton())
+        inputElement = dynamicDowncast<HTMLInputElement>(inputElement->shadowHost());
 
     return inputElement && inputElement->isFileUpload() ? inputElement : nullptr;
 }
@@ -502,12 +500,8 @@
     Document* document = m_page.mainFrame().documentAtPoint(dragData.clientPosition());
 
     bool pluginDocumentAcceptsDrags = false;
-
-    if (is<PluginDocument>(document)) {
-        const Widget* widget = downcast<PluginDocument>(*document).pluginWidget();
-        const PluginViewBase* pluginView = is<PluginViewBase>(widget) ? downcast<PluginViewBase>(widget) : nullptr;
-
-        if (pluginView)
+    if (auto* pluginDocument = dynamicDowncast<PluginDocument>(document)) {
+        if (auto* pluginView = dynamicDowncast<PluginViewBase>(pluginDocument->pluginWidget()))
             pluginDocumentAcceptsDrags = pluginView->shouldAllowNavigationFromDrags();
     }
 
diff --git a/Source/WebCore/platform/DragImage.cpp b/Source/WebCore/platform/DragImage.cpp
index 6dfe0dd..9e97dd5 100644
--- a/Source/WebCore/platform/DragImage.cpp
+++ b/Source/WebCore/platform/DragImage.cpp
@@ -80,7 +80,7 @@
 
 struct ScopedNodeDragEnabler {
     ScopedNodeDragEnabler(Frame& frame, Node& node)
-        : element(is<Element>(node) ? &downcast<Element>(node) : nullptr)
+        : element(dynamicDowncast<Element>(node))
     {
         if (element)
             element->setBeingDragged(true);
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
index 2a4c91b..e61a3a7 100644
--- a/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
+++ b/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
@@ -903,7 +903,7 @@
 void SourceBufferPrivateAVFObjC::setCDMInstance(CDMInstance* instance)
 {
 #if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
-    auto* fpsInstance = is<CDMInstanceFairPlayStreamingAVFObjC>(instance) ? downcast<CDMInstanceFairPlayStreamingAVFObjC>(instance) : nullptr;
+    auto* fpsInstance = dynamicDowncast<CDMInstanceFairPlayStreamingAVFObjC>(instance);
     if (fpsInstance == m_cdmInstance)
         return;
 
diff --git a/Source/WebCore/rendering/LegacyInlineFlowBox.cpp b/Source/WebCore/rendering/LegacyInlineFlowBox.cpp
index 595b55e..805752b 100644
--- a/Source/WebCore/rendering/LegacyInlineFlowBox.cpp
+++ b/Source/WebCore/rendering/LegacyInlineFlowBox.cpp
@@ -577,7 +577,7 @@
         if (child->renderer().isOutOfFlowPositioned())
             continue; // Positioned placeholders don't affect calculations.
         
-        LegacyInlineFlowBox* inlineFlowBox = is<LegacyInlineFlowBox>(*child) ? downcast<LegacyInlineFlowBox>(child) : nullptr;
+        auto* inlineFlowBox = dynamicDowncast<LegacyInlineFlowBox>(*child);
         
         bool affectsAscent = false;
         bool affectsDescent = false;
@@ -667,7 +667,7 @@
             continue;
         }
 
-        LegacyInlineFlowBox* inlineFlowBox = is<LegacyInlineFlowBox>(*child) ? downcast<LegacyInlineFlowBox>(child) : nullptr;
+        auto* inlineFlowBox = dynamicDowncast<LegacyInlineFlowBox>(*child);
         bool childAffectsTopBottomPos = true;
 
         if (child->verticalAlign() == VerticalAlign::Top && verticalAlignApplies(child->renderer()))
diff --git a/Source/WebCore/rendering/RenderBlockFlow.cpp b/Source/WebCore/rendering/RenderBlockFlow.cpp
index 4795db7..ab54ffb 100644
--- a/Source/WebCore/rendering/RenderBlockFlow.cpp
+++ b/Source/WebCore/rendering/RenderBlockFlow.cpp
@@ -739,7 +739,7 @@
     setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta);
     estimateFragmentRangeForBoxChild(child);
 
-    RenderBlockFlow* childBlockFlow = is<RenderBlockFlow>(child) ? &downcast<RenderBlockFlow>(child) : nullptr;
+    auto* childBlockFlow = dynamicDowncast<RenderBlockFlow>(child);
     bool markDescendantsWithFloats = false;
     if (logicalTopEstimate != oldLogicalTop && !child.avoidsFloats() && childBlockFlow && childBlockFlow->containsFloats())
         markDescendantsWithFloats = true;
@@ -993,7 +993,7 @@
     LayoutUnit beforeMargin;
     LayoutUnit afterMargin;
 
-    RenderBlockFlow* childRenderBlock = is<RenderBlockFlow>(child) ? &downcast<RenderBlockFlow>(child) : nullptr;
+    auto* childRenderBlock = dynamicDowncast<RenderBlockFlow>(child);
     
     // If the child has the same directionality as we do, then we can just return its
     // margins in the same direction.
@@ -1471,7 +1471,7 @@
 
 LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox& child, bool atBeforeSideOfBlock)
 {
-    RenderBlock* childRenderBlock = is<RenderBlock>(child) ? &downcast<RenderBlock>(child) : nullptr;
+    auto* childRenderBlock = dynamicDowncast<RenderBlock>(child);
 
     if (estimateWithoutPagination != logicalTopAfterClear) {
         // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new
@@ -2496,7 +2496,7 @@
             // See if we have a pagination strut that is making us move down further.
             // Note that an unsplittable child can't also have a pagination strut, so this
             // is exclusive with the case above.
-            RenderBlock* childBlock = is<RenderBlock>(childBox) ? &downcast<RenderBlock>(childBox) : nullptr;
+            auto* childBlock = dynamicDowncast<RenderBlock>(childBox);
             if (childBlock && childBlock->paginationStrut()) {
                 newLogicalTop += childBlock->paginationStrut();
                 childBlock->setPaginationStrut(0);
diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp
index cb4f494..07a30cb 100644
--- a/Source/WebCore/rendering/RenderBox.cpp
+++ b/Source/WebCore/rendering/RenderBox.cpp
@@ -1057,7 +1057,7 @@
             renderer = renderer->parent();
     }
 
-    return is<RenderBox>(renderer) ? downcast<RenderBox>(renderer) : nullptr;
+    return dynamicDowncast<RenderBox>(renderer);
 }
 
 void RenderBox::panScroll(const IntPoint& source)
diff --git a/Source/WebCore/rendering/RenderElement.cpp b/Source/WebCore/rendering/RenderElement.cpp
index e3ea576..1e8c505 100644
--- a/Source/WebCore/rendering/RenderElement.cpp
+++ b/Source/WebCore/rendering/RenderElement.cpp
@@ -2172,7 +2172,7 @@
 
 ImageOrientation RenderElement::imageOrientation() const
 {
-    auto* imageElement = is<HTMLImageElement>(element()) ? downcast<HTMLImageElement>(element()) : nullptr;
+    auto* imageElement = dynamicDowncast<HTMLImageElement>(element());
     return (imageElement && !imageElement->allowsOrientationOverride()) ? ImageOrientation(ImageOrientation::FromImage) : style().imageOrientation();
 }
 
diff --git a/Source/WebCore/rendering/RenderFileUploadControl.cpp b/Source/WebCore/rendering/RenderFileUploadControl.cpp
index 8785f22..8750693 100644
--- a/Source/WebCore/rendering/RenderFileUploadControl.cpp
+++ b/Source/WebCore/rendering/RenderFileUploadControl.cpp
@@ -243,8 +243,7 @@
 HTMLInputElement* RenderFileUploadControl::uploadButton() const
 {
     ASSERT(inputElement().shadowRoot());
-    Node* buttonNode = inputElement().shadowRoot()->firstChild();
-    return is<HTMLInputElement>(buttonNode) ? downcast<HTMLInputElement>(buttonNode) : nullptr;
+    return dynamicDowncast<HTMLInputElement>(inputElement().shadowRoot()->firstChild());
 }
 
 String RenderFileUploadControl::buttonValue()
diff --git a/Source/WebCore/rendering/RenderImage.cpp b/Source/WebCore/rendering/RenderImage.cpp
index f9213e2..0500f895 100644
--- a/Source/WebCore/rendering/RenderImage.cpp
+++ b/Source/WebCore/rendering/RenderImage.cpp
@@ -331,7 +331,7 @@
     IntSize containerSize(replacedContentRect().size());
     if (!containerSize.isEmpty()) {
         URL imageSourceURL;
-        if (HTMLImageElement* imageElement = is<HTMLImageElement>(element()) ? downcast<HTMLImageElement>(element()) : nullptr)
+        if (auto* imageElement = dynamicDowncast<HTMLImageElement>(element()))
             imageSourceURL = document().completeURL(imageElement->imageSourceURL());
         imageResource().setContainerContext(containerSize, imageSourceURL);
     }
@@ -666,7 +666,7 @@
     if (!img || img->isNull())
         return ImageDrawResult::DidNothing;
 
-    HTMLImageElement* imageElement = is<HTMLImageElement>(element()) ? downcast<HTMLImageElement>(element()) : nullptr;
+    auto* imageElement = dynamicDowncast<HTMLImageElement>(element());
 
     // FIXME: Document when image != img.get().
     Image* image = imageResource().image().get();
diff --git a/Source/WebCore/rendering/RenderInline.cpp b/Source/WebCore/rendering/RenderInline.cpp
index d4d7c5c..6a9a391 100644
--- a/Source/WebCore/rendering/RenderInline.cpp
+++ b/Source/WebCore/rendering/RenderInline.cpp
@@ -203,7 +203,7 @@
 bool RenderInline::mayAffectLayout() const
 {
     auto* parentStyle = &parent()->style();
-    RenderInline* parentRenderInline = is<RenderInline>(*parent()) ? downcast<RenderInline>(parent()) : nullptr;
+    auto* parentRenderInline = dynamicDowncast<RenderInline>(*parent());
     auto hasHardLineBreakChildOnly = firstChild() && firstChild() == lastChild() && firstChild()->isBR();
     bool checkFonts = document().inNoQuirksMode();
     auto mayAffectLayout = (parentRenderInline && parentRenderInline->mayAffectLayout())
diff --git a/Source/WebCore/rendering/RenderLayer.h b/Source/WebCore/rendering/RenderLayer.h
index d3f5d1e..e5e5ec9 100644
--- a/Source/WebCore/rendering/RenderLayer.h
+++ b/Source/WebCore/rendering/RenderLayer.h
@@ -169,7 +169,7 @@
 
     Page& page() const { return renderer().page(); }
     RenderLayerModelObject& renderer() const { return m_renderer; }
-    RenderBox* renderBox() const { return is<RenderBox>(renderer()) ? &downcast<RenderBox>(renderer()) : nullptr; }
+    RenderBox* renderBox() const { return dynamicDowncast<RenderBox>(renderer()); }
 
     RenderLayer* parent() const { return m_parent; }
     RenderLayer* previousSibling() const { return m_previous; }
diff --git a/Source/WebCore/rendering/RenderLineBoxList.cpp b/Source/WebCore/rendering/RenderLineBoxList.cpp
index 389d5a3..e4a1d53 100644
--- a/Source/WebCore/rendering/RenderLineBoxList.cpp
+++ b/Source/WebCore/rendering/RenderLineBoxList.cpp
@@ -310,7 +310,7 @@
     if (!container.parent() || (is<RenderBlockFlow>(container) && container.selfNeedsLayout()))
         return;
 
-    RenderInline* inlineContainer = is<RenderInline>(container) ? &downcast<RenderInline>(container) : nullptr;
+    auto* inlineContainer = dynamicDowncast<RenderInline>(container);
     LegacyInlineBox* firstBox = inlineContainer ? inlineContainer->firstLineBox() : firstLineBox();
 
     // If we have no first line box, then just bail early.
diff --git a/Source/WebCore/rendering/RenderListItem.cpp b/Source/WebCore/rendering/RenderListItem.cpp
index ae2822c..5bdde22 100644
--- a/Source/WebCore/rendering/RenderListItem.cpp
+++ b/Source/WebCore/rendering/RenderListItem.cpp
@@ -210,7 +210,7 @@
 void RenderListItem::updateValueNow() const
 {
     auto* list = enclosingList(*this);
-    auto* orderedList = is<HTMLOListElement>(list) ? downcast<HTMLOListElement>(list) : nullptr;
+    auto* orderedList = dynamicDowncast<HTMLOListElement>(list);
 
     // The start item is either the closest item before this one in the list that already has a value,
     // or the first item in the list if none have before this have values yet.
diff --git a/Source/WebCore/rendering/RenderObject.cpp b/Source/WebCore/rendering/RenderObject.cpp
index baab29d..72a6667 100644
--- a/Source/WebCore/rendering/RenderObject.cpp
+++ b/Source/WebCore/rendering/RenderObject.cpp
@@ -1781,7 +1781,7 @@
         current = current->parent();
     }
 
-    return is<RenderBoxModelObject>(current) ? downcast<RenderBoxModelObject>(current) : nullptr;
+    return dynamicDowncast<RenderBoxModelObject>(current);
 }
 
 VisiblePosition RenderObject::createVisiblePosition(int offset, Affinity affinity) const
diff --git a/Source/WebCore/rendering/RenderTableCol.cpp b/Source/WebCore/rendering/RenderTableCol.cpp
index 8257376..f3a3015 100644
--- a/Source/WebCore/rendering/RenderTableCol.cpp
+++ b/Source/WebCore/rendering/RenderTableCol.cpp
@@ -155,7 +155,7 @@
     auto table = parent();
     if (table && !is<RenderTable>(*table))
         table = table->parent();
-    return is<RenderTable>(table) ? downcast<RenderTable>(table) : nullptr;
+    return dynamicDowncast<RenderTable>(table);
 }
 
 RenderTableCol* RenderTableCol::enclosingColumnGroup() const
diff --git a/Source/WebCore/rendering/RenderTreeAsText.cpp b/Source/WebCore/rendering/RenderTreeAsText.cpp
index 00f5724..38677ef 100644
--- a/Source/WebCore/rendering/RenderTreeAsText.cpp
+++ b/Source/WebCore/rendering/RenderTreeAsText.cpp
@@ -473,7 +473,7 @@
 void writeDebugInfo(TextStream& ts, const RenderObject& object, OptionSet<RenderAsTextFlag> behavior)
 {
     if (behavior.contains(RenderAsTextFlag::ShowIDAndClass)) {
-        if (Element* element = is<Element>(object.node()) ? downcast<Element>(object.node()) : nullptr) {
+        if (auto* element = dynamicDowncast<Element>(object.node())) {
             if (element->hasID())
                 ts << " id=\"" << element->getIdAttribute() << "\"";
 
diff --git a/Source/WebCore/rendering/RenderView.cpp b/Source/WebCore/rendering/RenderView.cpp
index 60ffb17..17df91d 100644
--- a/Source/WebCore/rendering/RenderView.cpp
+++ b/Source/WebCore/rendering/RenderView.cpp
@@ -399,7 +399,7 @@
     Element* documentElement = document().documentElement();
     if (RenderElement* rootRenderer = documentElement ? documentElement->renderer() : nullptr) {
         // The document element's renderer is currently forced to be a block, but may not always be.
-        RenderBox* rootBox = is<RenderBox>(*rootRenderer) ? downcast<RenderBox>(rootRenderer) : nullptr;
+        auto* rootBox = dynamicDowncast<RenderBox>(*rootRenderer);
         rootFillsViewport = rootBox && !rootBox->x() && !rootBox->y() && rootBox->width() >= width() && rootBox->height() >= height();
         rootObscuresBackground = rendererObscuresBackground(*rootRenderer);
     }
diff --git a/Source/WebCore/rendering/SelectionRangeData.cpp b/Source/WebCore/rendering/SelectionRangeData.cpp
index 1afc1e0..fbe9620 100644
--- a/Source/WebCore/rendering/SelectionRangeData.cpp
+++ b/Source/WebCore/rendering/SelectionRangeData.cpp
@@ -74,8 +74,7 @@
 
 static RenderBlock* containingBlockBelowView(const RenderObject& renderer)
 {
-    auto* containingBlock = renderer.containingBlock();
-    return is<RenderView>(containingBlock) ? nullptr : containingBlock;
+    return dynamicDowncast<RenderView>(renderer.containingBlock());
 }
 
 static SelectionContext collectSelectionData(const RenderRange& selection, bool repaintDifference)
diff --git a/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp b/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
index 437c999..68c6279 100644
--- a/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
+++ b/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
@@ -625,7 +625,7 @@
                     ASSERT(is<RenderBox>(renderer) && downcast<RenderBlockFlow>(*newParent).multiColumnFlow()->spannerMap().contains(&downcast<RenderBox>(renderer)));
                     newEnclosingFragmentedFlow = downcast<RenderBlockFlow>(*newParent).multiColumnFlow();
                 }
-                return newEnclosingFragmentedFlow != currentEnclosingFragment && is<RenderMultiColumnFlow>(newEnclosingFragmentedFlow) ? downcast<RenderMultiColumnFlow>(newEnclosingFragmentedFlow) : nullptr;
+                return newEnclosingFragmentedFlow != currentEnclosingFragment ? dynamicDowncast<RenderMultiColumnFlow>(newEnclosingFragmentedFlow) : nullptr;
             };
             if (auto* newEnclosingMultiColumn = newMultiColumnForRenderer()) {
                 // Let the fragmented flow know that it has a new in-flow descendant.
diff --git a/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp b/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp
index e1bea0c..3904da4 100644
--- a/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp
+++ b/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp
@@ -65,7 +65,7 @@
 namespace WebCore {
 
 RenderTreeUpdater::Parent::Parent(ContainerNode& root)
-    : element(is<Document>(root) ? nullptr : downcast<Element>(&root))
+    : element(dynamicDowncast<Element>(root))
     , renderTreePosition(RenderTreePosition(*root.renderer()))
 {
 }
diff --git a/Source/WebCore/style/ChildChangeInvalidation.h b/Source/WebCore/style/ChildChangeInvalidation.h
index ac689bc..8671ffa 100644
--- a/Source/WebCore/style/ChildChangeInvalidation.h
+++ b/Source/WebCore/style/ChildChangeInvalidation.h
@@ -61,7 +61,7 @@
 };
 
 inline ChildChangeInvalidation::ChildChangeInvalidation(ContainerNode& container, const ContainerNode::ChildChange& childChange)
-    : m_parentElement(is<Element>(container) ? downcast<Element>(&container) : nullptr)
+    : m_parentElement(dynamicDowncast<Element>(container))
     , m_childChange(childChange)
     , m_isEnabled(m_parentElement ? m_parentElement->needsStyleInvalidation() : false)
     , m_needsHasInvalidation(m_isEnabled && Scope::forNode(*m_parentElement).usesHasPseudoClass())
diff --git a/Source/WebCore/svg/SVGElement.h b/Source/WebCore/svg/SVGElement.h
index 97e6086..2d3a331 100644
--- a/Source/WebCore/svg/SVGElement.h
+++ b/Source/WebCore/svg/SVGElement.h
@@ -245,6 +245,7 @@
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGElement)
+    static bool isType(const WebCore::EventTarget& eventTarget) { return eventTarget.isNode() && static_cast<const WebCore::Node&>(eventTarget).isSVGElement(); }
     static bool isType(const WebCore::Node& node) { return node.isSVGElement(); }
 SPECIALIZE_TYPE_TRAITS_END()
 
diff --git a/Source/WebCore/svg/SVGSVGElement.cpp b/Source/WebCore/svg/SVGSVGElement.cpp
index b3b6b5c..530ff1b 100644
--- a/Source/WebCore/svg/SVGSVGElement.cpp
+++ b/Source/WebCore/svg/SVGSVGElement.cpp
@@ -572,14 +572,12 @@
 
 SVGViewElement* SVGSVGElement::findViewAnchor(StringView fragmentIdentifier) const
 {
-    auto* anchorElement = document().findAnchor(fragmentIdentifier);
-    return is<SVGViewElement>(anchorElement) ? downcast<SVGViewElement>(anchorElement): nullptr;
+    return dynamicDowncast<SVGViewElement>(document().findAnchor(fragmentIdentifier));
 }
 
 SVGSVGElement* SVGSVGElement::findRootAnchor(const SVGViewElement* viewElement) const
 {
-    auto* viewportElement = SVGLocatable::nearestViewportElement(viewElement);
-    return is<SVGSVGElement>(viewportElement) ? downcast<SVGSVGElement>(viewportElement) : nullptr;
+    return dynamicDowncast<SVGSVGElement>(SVGLocatable::nearestViewportElement(viewElement));
 }
 
 SVGSVGElement* SVGSVGElement::findRootAnchor(StringView fragmentIdentifier) const
diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp
index 35a66e0..7d8ad79 100644
--- a/Source/WebCore/testing/Internals.cpp
+++ b/Source/WebCore/testing/Internals.cpp
@@ -957,15 +957,13 @@
 
 static BitmapImage* bitmapImageFromImageElement(HTMLImageElement& element)
 {
-    auto* image = imageFromImageElement(element);
-    return image && is<BitmapImage>(image) ? &downcast<BitmapImage>(*image) : nullptr;
+    return dynamicDowncast<BitmapImage>(imageFromImageElement(element));
 }
 
 #if USE(CG)
 static PDFDocumentImage* pdfDocumentImageFromImageElement(HTMLImageElement& element)
 {
-    auto* image = imageFromImageElement(element);
-    return image && is<PDFDocumentImage>(image) ? &downcast<PDFDocumentImage>(*image) : nullptr;
+    return dynamicDowncast<PDFDocumentImage>(imageFromImageElement(element));
 }
 #endif