Issue #1592 - Follow-up: Don't post a restyle event if restyleElement is null

This fixes a potential crash caused if restyleElement is null.
This commit is contained in:
FranklinDM 2023-03-22 17:29:00 +08:00 committed by roytam1
commit b29522749a

View file

@ -163,6 +163,7 @@ ShadowRoot::AddSlot(HTMLSlotElement* aSlot)
oldSlot->RemoveAssignedNode(assignedNode);
currentSlot->AppendAssignedNode(assignedNode);
Element* restyleElement;
if (assignedNode->IsElement()) {
restyleElement = assignedNode->AsElement();
@ -170,8 +171,10 @@ ShadowRoot::AddSlot(HTMLSlotElement* aSlot)
// This is likely a text node. Use the host instead.
restyleElement = GetHost();
}
nsLayoutUtils::PostRestyleEvent(
restyleElement, eRestyle_Subtree, nsChangeHint(0));
if (restyleElement) {
nsLayoutUtils::PostRestyleEvent(
restyleElement, eRestyle_Subtree, nsChangeHint(0));
}
doEnqueueSlotChange = true;
}