[parser] Account for some corner-case structural document issues.

This commit is contained in:
Moonchild 2026-02-26 09:48:23 +01:00 committed by OwnedByWuigi
commit c91765edda

View file

@ -200,6 +200,13 @@ nsHtml5TreeOperation::Append(nsIContent* aNode,
{
MOZ_ASSERT(aBuilder);
MOZ_ASSERT(aBuilder->IsInDocUpdate());
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
Detach(aNode, aBuilder);
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
// Can this happen? If it can, give up.
return NS_OK;
}
}
nsresult rv = NS_OK;
nsHtml5OtherDocUpdate update(aParent->OwnerDoc(),
aBuilder->GetDocument());
@ -219,6 +226,13 @@ nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
MOZ_ASSERT(aBuilder);
MOZ_ASSERT(aBuilder->GetDocument() == aNode->OwnerDoc());
MOZ_ASSERT(aBuilder->IsInDocUpdate());
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
Detach(aNode, aBuilder);
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
// Can this happen? If it can, give up.
return NS_OK;
}
}
nsresult rv = NS_OK;
nsIDocument* doc = aBuilder->GetDocument();
@ -308,6 +322,14 @@ nsHtml5TreeOperation::FosterParent(nsIContent* aNode,
{
MOZ_ASSERT(aBuilder);
MOZ_ASSERT(aBuilder->IsInDocUpdate());
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
Detach(aNode, aBuilder);
if (MOZ_UNLIKELY(aNode->GetParentNode())) {
// Can this happen? If it can, give up.
return NS_OK;
}
}
nsIContent* foster = aTable->GetParent();
if (IsElementOrTemplateContent(foster)) {