@@ -2329,7 +2329,7 @@ ExplicitlySetAttrElementsMap* Element::explicitlySetAttrElementsMapIfExists() co
2329
2329
2330
2330
static RefPtr<Element> getElementByIdInternalIncludingDisconnected (const Element& startElement, const AtomString& id)
2331
2331
{
2332
- if (id.isNull () || id. isEmpty ())
2332
+ if (id.isEmpty ())
2333
2333
return nullptr ;
2334
2334
2335
2335
if (LIKELY (startElement.isInTreeScope ()))
@@ -2366,7 +2366,7 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
2366
2366
}
2367
2367
2368
2368
if (!hasExplicitlySetElement) {
2369
- const AtomString& id = getAttribute (attributeName);
2369
+ const AtomString& id = getAttribute (attributeName);
2370
2370
element = getElementByIdInternalIncludingDisconnected (*this , id);
2371
2371
}
2372
2372
@@ -2379,16 +2379,13 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
2379
2379
RefPtr<Element> Element::getElementAttributeForBindings (const QualifiedName& attributeName) const
2380
2380
{
2381
2381
ASSERT (isElementReflectionAttribute (document ().settings (), attributeName));
2382
- RefPtr<Element> element = getElementForAttributeInternal (attributeName);
2382
+ RefPtr element = getElementForAttributeInternal (attributeName);
2383
2383
2384
2384
if (!element)
2385
2385
return nullptr ;
2386
2386
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));
2392
2389
2393
2390
return element;
2394
2391
}
@@ -2446,10 +2443,9 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayForAttributeInterna
2446
2443
2447
2444
if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2448
2445
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;
2453
2449
});
2454
2450
}
2455
2451
@@ -2466,9 +2462,7 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttributeForBinding
2466
2462
2467
2463
if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2468
2464
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));
2472
2466
});
2473
2467
}
2474
2468
@@ -3261,8 +3255,7 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
3261
3255
init.serializable ? ShadowRoot::Serializable::Yes : ShadowRoot::Serializable::No,
3262
3256
isPrecustomizedOrDefinedCustomElement () ? ShadowRoot::AvailableToElementInternals::Yes : ShadowRoot::AvailableToElementInternals::No,
3263
3257
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 ));
3266
3259
addShadowRoot (shadow .copyRef ());
3267
3260
return shadow .get ();
3268
3261
}
@@ -3310,12 +3303,10 @@ RefPtr<const Element> Element::deepShadowRootReferenceTargetOrSelf() const {
3310
3303
3311
3304
RefPtr<const Element> element = this ;
3312
3305
3313
- ShadowRoot* shadow = shadowRoot ();
3306
+ RefPtr shadow = shadowRoot ();
3314
3307
while (shadow && shadow ->hasReferenceTarget ()) {
3315
3308
element = shadow ->referenceTargetElementOrHost ();
3316
- if (!element)
3317
- return nullptr ;
3318
- shadow = element->shadowRoot ();
3309
+ shadow = element ? element->shadowRoot () : nullptr ;
3319
3310
}
3320
3311
return element;
3321
3312
}
0 commit comments