Bug 1315837 - Fix crash in mozilla::dom::Element::UpdateIntersectionObservation. r=mrbkap

--HG--
extra : rebase_source : 77edac309414e61dd103bc60668351d6e3548890
This commit is contained in:
Tobias Schneider 2016-11-09 09:10:00 -05:00
Родитель 1381db9e9e
Коммит 0cb90d5992
3 изменённых файлов: 31 добавлений и 10 удалений

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

@ -159,15 +159,23 @@ DOMIntersectionObserver::Observe(Element& aTarget)
void
DOMIntersectionObserver::Unobserve(Element& aTarget)
{
if (!mObservationTargets.Contains(&aTarget)) {
return;
if (UnlinkTarget(aTarget)) {
aTarget.UnregisterIntersectionObserver(this);
}
if (mObservationTargets.Count() == 1) {
Disconnect();
return;
}
aTarget.UnregisterIntersectionObserver(this);
mObservationTargets.RemoveEntry(&aTarget);
}
bool
DOMIntersectionObserver::UnlinkTarget(Element& aTarget)
{
if (!mObservationTargets.Contains(&aTarget)) {
return false;
}
if (mObservationTargets.Count() == 1) {
Disconnect();
return false;
}
mObservationTargets.RemoveEntry(&aTarget);
return true;
}
void
@ -192,8 +200,10 @@ DOMIntersectionObserver::Disconnect()
target->UnregisterIntersectionObserver(this);
}
mObservationTargets.Clear();
nsIDocument* document = mOwner->GetExtantDoc();
document->RemoveIntersectionObserver(this);
if (mOwner) {
nsIDocument* document = mOwner->GetExtantDoc();
document->RemoveIntersectionObserver(this);
}
mConnected = false;
}

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

@ -142,7 +142,9 @@ public:
void Observe(Element& aTarget);
void Unobserve(Element& aTarget);
bool UnlinkTarget(Element& aTarget);
void Disconnect();
void TakeRecords(nsTArray<RefPtr<DOMIntersectionObserverEntry>>& aRetVal);
mozilla::dom::IntersectionCallback* IntersectionCallback() { return mCallback; }

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

@ -297,6 +297,15 @@ nsNodeUtils::LastRelease(nsINode* aNode)
NodeWillBeDestroyed, (aNode));
}
if (aNode->IsElement()) {
Element* elem = aNode->AsElement();
FragmentOrElement::nsDOMSlots* domSlots =
static_cast<FragmentOrElement::nsDOMSlots*>(slots);
for (auto& reg : domSlots->mRegisteredIntersectionObservers) {
reg.observer->UnlinkTarget(*elem);
}
}
delete slots;
aNode->mSlots = nullptr;
}