Skip to content
Permalink
Browse files
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):



Canonical link: https://commits.webkit.org/246089@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jan 16, 2022
1 parent 15ac489 commit 004e58312247d20e944ce7d639599329c5cbdaa7
Showing 65 changed files with 375 additions and 201 deletions.
@@ -1,3 +1,16 @@
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.

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):

2022-01-14 Yusuke Suzuki <ysuzuki@apple.com>

Fix WTF::UUID's potential collision with empty and deleted values
@@ -88,6 +88,21 @@ inline match_constness_t<Source, Target>* downcast(Source* source)
return static_cast<match_constness_t<Source, Target>*>(source);
}

template<typename Target, typename Source>
inline match_constness_t<Source, Target>* dynamicDowncast(Source& source)
{
static_assert(!std::is_same_v<Source, Target>, "Unnecessary cast to same type");
static_assert(std::is_base_of_v<Source, Target>, "Should be a downcast");
return is<Target>(source) ? &static_cast<match_constness_t<Source, Target>&>(source) : nullptr;
}
template<typename Target, typename Source>
inline match_constness_t<Source, Target>* dynamicDowncast(Source* source)
{
static_assert(!std::is_same_v<Source, Target>, "Unnecessary cast to same type");
static_assert(std::is_base_of_v<Source, Target>, "Should be a downcast");
return is<Target>(source) ? static_cast<match_constness_t<Source, Target>*>(source) : nullptr;
}

// Add support for type checking / casting using is<>() / downcast<>() helpers for a specific class.
#define SPECIALIZE_TYPE_TRAITS_BEGIN(ClassName) \
namespace WTF { \
@@ -120,3 +135,4 @@ inline bool is(const std::unique_ptr<ArgType, Deleter>& source)
using WTF::TypeCastTraits;
using WTF::is;
using WTF::downcast;
using WTF::dynamicDowncast;
@@ -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
@@ -244,8 +244,8 @@ void WebAnimation::setTimeline(RefPtr<AnimationTimeline>&& timeline)
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::cancel()

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 @@ void WebAnimation::timingDidChange(DidSeek didSeek, SynchronouslyNotify synchron
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::timingDidChange(DidSeek didSeek, SynchronouslyNotify synchron

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 @@ void WebAnimation::finishNotificationSteps()
// 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 @@ void WebAnimation::resolve(RenderStyle& targetStyle, const Style::ResolutionCont
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 @@ void WebAnimation::persist()
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 @@ ExceptionOr<void> WebAnimation::commitStyles()
// 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:
@@ -151,7 +151,7 @@ void JSEventListener::handleEvent(ScriptExecutionContext& scriptExecutionContext
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;
}
@@ -84,19 +84,12 @@ JSLazyEventListener::JSLazyEventListener(CreationArguments&& arguments, const UR
#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 @@ JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext& exec
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;

@@ -355,7 +355,7 @@ FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription& fontDescr

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())
@@ -268,7 +268,7 @@ ExceptionOr<unsigned> CSSStyleSheet::insertRule(const String& ruleString, unsign
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)
@@ -112,10 +112,11 @@ CSSStyleDeclaration* Attr::style()
{
// 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();
}

@@ -108,8 +108,8 @@ void BroadcastChannel::MainThreadBridge::ensureOnMainThread(Function<void(Docume
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 @@ bool BroadcastChannel::isEligibleForMessaging() const
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();
}

0 comments on commit 004e583

Please sign in to comment.