Bug 1827856 - Speed up GetClosestAnonymousSubtreeRoot for UA widgets. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D175353
This commit is contained in:
Emilio Cobos Álvarez 2023-04-14 19:25:24 +00:00
Родитель 11349941a9
Коммит 339529a536
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -61,6 +61,11 @@ ShadowRoot::ShadowRoot(Element* aElement, ShadowRootMode aMode,
mSlotAssignment(aSlotAssignment),
mIsDetailsShadowTree(aElement->IsHTMLElement(nsGkAtoms::details)),
mIsAvailableToElementInternals(false) {
// nsINode.h relies on this.
MOZ_ASSERT(static_cast<nsINode*>(this) == reinterpret_cast<nsINode*>(this));
MOZ_ASSERT(static_cast<nsIContent*>(this) ==
reinterpret_cast<nsIContent*>(this));
SetHost(aElement);
// Nodes in a shadow tree should never store a value

Просмотреть файл

@ -1410,9 +1410,15 @@ class nsINode : public mozilla::dom::EventTarget {
*/
nsIContent* GetClosestNativeAnonymousSubtreeRoot() const {
if (!IsInNativeAnonymousSubtree()) {
MOZ_ASSERT(!HasBeenInUAWidget(), "UA widget implies anonymous");
return nullptr;
}
MOZ_ASSERT(IsContent(), "How did non-content end up in NAC?");
if (HasBeenInUAWidget()) {
// reinterpret_cast because in this header we don't know ShadowRoot is an
// nsIContent. ShadowRoot constructor asserts this is correct.
return reinterpret_cast<nsIContent*>(GetContainingShadow());
}
for (const nsINode* node = this; node; node = node->GetParentNode()) {
if (node->IsRootOfNativeAnonymousSubtree()) {
return const_cast<nsINode*>(node)->AsContent();