Bug 1428053: Fix ShadowRoot::ContentAppended. r=jessica

MozReview-Commit-ID: iUhaP8VVIO
This commit is contained in:
Emilio Cobos Álvarez
2018-01-05 11:15:32 +01:00
parent 404271fceb
commit c16d3d8193
4 changed files with 35 additions and 3 deletions

View File

@@ -179,6 +179,7 @@ HTMLSlotElement::AssignedNodes() const
void
HTMLSlotElement::InsertAssignedNode(uint32_t aIndex, nsINode* aNode)
{
MOZ_ASSERT(!aNode->AsContent()->GetAssignedSlot(), "Losing track of a slot");
mAssignedNodes.InsertElementAt(aIndex, aNode);
aNode->AsContent()->SetAssignedSlot(this);
}
@@ -186,6 +187,7 @@ HTMLSlotElement::InsertAssignedNode(uint32_t aIndex, nsINode* aNode)
void
HTMLSlotElement::AppendAssignedNode(nsINode* aNode)
{
MOZ_ASSERT(!aNode->AsContent()->GetAssignedSlot(), "Losing track of a slot");
mAssignedNodes.AppendElement(aNode);
aNode->AsContent()->SetAssignedSlot(this);
}
@@ -193,6 +195,10 @@ HTMLSlotElement::AppendAssignedNode(nsINode* aNode)
void
HTMLSlotElement::RemoveAssignedNode(nsINode* aNode)
{
// This one runs from unlinking, so we can't guarantee that the slot pointer
// hasn't been cleared.
MOZ_ASSERT(!aNode->AsContent()->GetAssignedSlot() ||
aNode->AsContent()->GetAssignedSlot() == this, "How exactly?");
mAssignedNodes.RemoveElement(aNode);
aNode->AsContent()->SetAssignedSlot(nullptr);
}
@@ -200,8 +206,10 @@ HTMLSlotElement::RemoveAssignedNode(nsINode* aNode)
void
HTMLSlotElement::ClearAssignedNodes()
{
for (uint32_t i = 0; i < mAssignedNodes.Length(); i++) {
mAssignedNodes[i]->AsContent()->SetAssignedSlot(nullptr);
for (RefPtr<nsINode>& node : mAssignedNodes) {
MOZ_ASSERT(!node->AsContent()->GetAssignedSlot() ||
node->AsContent()->GetAssignedSlot() == this, "How exactly?");
node->AsContent()->SetAssignedSlot(nullptr);
}
mAssignedNodes.Clear();