@@ -2329,7 +2329,7 @@ ExplicitlySetAttrElementsMap* Element::explicitlySetAttrElementsMapIfExists() co
23292329
23302330static RefPtr<Element> getElementByIdInternalIncludingDisconnected (const Element& startElement, const AtomString& id)
23312331{
2332- if (id.isNull () || id. isEmpty ())
2332+ if (id.isEmpty ())
23332333 return nullptr ;
23342334
23352335 if (LIKELY (startElement.isInTreeScope ()))
@@ -2366,7 +2366,7 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
23662366 }
23672367
23682368 if (!hasExplicitlySetElement) {
2369- const AtomString& id = getAttribute (attributeName);
2369+ const AtomString& id = getAttribute (attributeName);
23702370 element = getElementByIdInternalIncludingDisconnected (*this , id);
23712371 }
23722372
@@ -2379,16 +2379,13 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
23792379RefPtr<Element> Element::getElementAttributeForBindings (const QualifiedName& attributeName) const
23802380{
23812381 ASSERT (isElementReflectionAttribute (document ().settings (), attributeName));
2382- RefPtr<Element> element = getElementForAttributeInternal (attributeName);
2382+ RefPtr element = getElementForAttributeInternal (attributeName);
23832383
23842384 if (!element)
23852385 return nullptr ;
23862386
2387- if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2388- Ref<Node> retargeted = treeScope ().retargetToScope (*element);
2389- ASSERT (retargeted->isElementNode ());
2390- return dynamicDowncast<Element>(retargeted);
2391- }
2387+ if (document ().settings ().shadowRootReferenceTargetEnabled ())
2388+ return downcast<Element>(treeScope ().retargetToScope (*element));
23922389
23932390 return element;
23942391}
@@ -2446,10 +2443,9 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayForAttributeInterna
24462443
24472444 if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
24482445 elements = compactMap (elements.value (), [&](Ref<Element>& element) -> std::optional<Ref<Element>> {
2449- RefPtr<Element> deepReferenceTarget = element->deepShadowRootReferenceTargetOrSelf ();
2450- if (!deepReferenceTarget)
2451- return std::nullopt ;
2452- return *deepReferenceTarget;
2446+ if (RefPtr deepReferenceTarget = element->deepShadowRootReferenceTargetOrSelf ())
2447+ return *deepReferenceTarget;
2448+ return std::nullopt ;
24532449 });
24542450 }
24552451
@@ -2466,9 +2462,7 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttributeForBinding
24662462
24672463 if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
24682464 elements = compactMap (elements.value (), [&](Ref<Element>& element) -> std::optional<Ref<Element>> {
2469- Ref<Node> retargeted = treeScope ().retargetToScope (element);
2470- ASSERT (retargeted->isElementNode ());
2471- return *dynamicDowncast<Element>(retargeted);
2465+ return downcast<Element>(treeScope ().retargetToScope (element));
24722466 });
24732467 }
24742468
@@ -3261,8 +3255,7 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
32613255 init.serializable ? ShadowRoot::Serializable::Yes : ShadowRoot::Serializable::No,
32623256 isPrecustomizedOrDefinedCustomElement () ? ShadowRoot::AvailableToElementInternals::Yes : ShadowRoot::AvailableToElementInternals::No,
32633257 WTFMove (registry), init.registry ? ShadowRoot::ScopedCustomElementRegistry::Yes : ShadowRoot::ScopedCustomElementRegistry::No);
3264- if (document ().settings ().shadowRootReferenceTargetEnabled ())
3265- shadow->setReferenceTarget (AtomString (init.referenceTarget ));
3258+ shadow->setReferenceTarget (AtomString (init.referenceTarget ));
32663259 addShadowRoot (shadow.copyRef ());
32673260 return shadow.get ();
32683261}
@@ -3310,12 +3303,10 @@ RefPtr<const Element> Element::deepShadowRootReferenceTargetOrSelf() const {
33103303
33113304 RefPtr<const Element> element = this ;
33123305
3313- ShadowRoot* shadow = shadowRoot ();
3306+ RefPtr shadow = shadowRoot ();
33143307 while (shadow && shadow->hasReferenceTarget ()) {
33153308 element = shadow->referenceTargetElementOrHost ();
3316- if (!element)
3317- return nullptr ;
3318- shadow = element->shadowRoot ();
3309+ shadow = element ? element->shadowRoot () : nullptr ;
33193310 }
33203311 return element;
33213312}
0 commit comments