@@ -2332,7 +2332,7 @@ ExplicitlySetAttrElementsMap* Element::explicitlySetAttrElementsMapIfExists() co
2332
2332
2333
2333
static RefPtr<Element> getElementByIdInternalIncludingDisconnected (const Element& startElement, const AtomString& id)
2334
2334
{
2335
- if (id.isNull () || id. isEmpty ())
2335
+ if (id.isEmpty ())
2336
2336
return nullptr ;
2337
2337
2338
2338
if (LIKELY (startElement.isInTreeScope ()))
@@ -2369,7 +2369,7 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
2369
2369
}
2370
2370
2371
2371
if (!hasExplicitlySetElement) {
2372
- const AtomString& id = getAttribute (attributeName);
2372
+ const AtomString& id = getAttribute (attributeName);
2373
2373
element = getElementByIdInternalIncludingDisconnected (*this , id);
2374
2374
}
2375
2375
@@ -2382,16 +2382,13 @@ RefPtr<Element> Element::getElementForAttributeInternal(const QualifiedName& att
2382
2382
RefPtr<Element> Element::getElementAttributeForBindings (const QualifiedName& attributeName) const
2383
2383
{
2384
2384
ASSERT (isElementReflectionAttribute (document ().settings (), attributeName));
2385
- RefPtr<Element> element = getElementForAttributeInternal (attributeName);
2385
+ RefPtr element = getElementForAttributeInternal (attributeName);
2386
2386
2387
2387
if (!element)
2388
2388
return nullptr ;
2389
2389
2390
- if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2391
- Ref<Node> retargeted = treeScope ().retargetToScope (*element);
2392
- ASSERT (retargeted->isElementNode ());
2393
- return dynamicDowncast<Element>(retargeted);
2394
- }
2390
+ if (document ().settings ().shadowRootReferenceTargetEnabled ())
2391
+ return downcast<Element>(treeScope ().retargetToScope (*element));
2395
2392
2396
2393
return element;
2397
2394
}
@@ -2449,10 +2446,9 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayForAttributeInterna
2449
2446
2450
2447
if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2451
2448
elements = compactMap (elements.value (), [&](Ref<Element>& element) -> std::optional<Ref<Element>> {
2452
- RefPtr<Element> deepReferenceTarget = element->deepShadowRootReferenceTargetOrSelf ();
2453
- if (!deepReferenceTarget)
2454
- return std::nullopt;
2455
- return *deepReferenceTarget;
2449
+ if (RefPtr deepReferenceTarget = element->deepShadowRootReferenceTargetOrSelf ())
2450
+ return *deepReferenceTarget;
2451
+ return std::nullopt;
2456
2452
});
2457
2453
}
2458
2454
@@ -2469,9 +2465,7 @@ std::optional<Vector<Ref<Element>>> Element::getElementsArrayAttributeForBinding
2469
2465
2470
2466
if (document ().settings ().shadowRootReferenceTargetEnabled ()) {
2471
2467
elements = compactMap (elements.value (), [&](Ref<Element>& element) -> std::optional<Ref<Element>> {
2472
- Ref<Node> retargeted = treeScope ().retargetToScope (element);
2473
- ASSERT (retargeted->isElementNode ());
2474
- return *dynamicDowncast<Element>(retargeted);
2468
+ return downcast<Element>(treeScope ().retargetToScope (element));
2475
2469
});
2476
2470
}
2477
2471
@@ -3259,8 +3253,7 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
3259
3253
init.serializable ? ShadowRoot::Serializable::Yes : ShadowRoot::Serializable::No,
3260
3254
isPrecustomizedOrDefinedCustomElement () ? ShadowRoot::AvailableToElementInternals::Yes : ShadowRoot::AvailableToElementInternals::No,
3261
3255
WTFMove (registry), init.registry ? ShadowRoot::ScopedCustomElementRegistry::Yes : ShadowRoot::ScopedCustomElementRegistry::No);
3262
- if (document ().settings ().shadowRootReferenceTargetEnabled ())
3263
- shadow ->setReferenceTarget (AtomString (init.referenceTarget ));
3256
+ shadow ->setReferenceTarget (AtomString (init.referenceTarget ));
3264
3257
addShadowRoot (shadow .copyRef ());
3265
3258
return shadow .get ();
3266
3259
}
@@ -3308,12 +3301,10 @@ RefPtr<const Element> Element::deepShadowRootReferenceTargetOrSelf() const {
3308
3301
3309
3302
RefPtr<const Element> element = this ;
3310
3303
3311
- ShadowRoot* shadow = shadowRoot ();
3304
+ RefPtr shadow = shadowRoot ();
3312
3305
while (shadow && shadow ->hasReferenceTarget ()) {
3313
3306
element = shadow ->referenceTargetElementOrHost ();
3314
- if (!element)
3315
- return nullptr ;
3316
- shadow = element->shadowRoot ();
3307
+ shadow = element ? element->shadowRoot () : nullptr ;
3317
3308
}
3318
3309
return element;
3319
3310
}
0 commit comments