summaryrefslogtreecommitdiffstats
path: root/dom/base/DOMIntersectionObserver.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-12-24 01:58:16 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-12-24 01:58:16 +0100
commit3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46 (patch)
treef32ef71a8d6a2831ff3646665a2cecc8a8945d1c /dom/base/DOMIntersectionObserver.cpp
parentbfedd7d40c73ef0423251f6df74bc948a6f44a1e (diff)
downloadUXP-3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46.tar
UXP-3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46.tar.gz
UXP-3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46.tar.lz
UXP-3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46.tar.xz
UXP-3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46.zip
Fix crashiness of IntersectionObservers.
Mozilla hashtables -still- suck.
Diffstat (limited to 'dom/base/DOMIntersectionObserver.cpp')
-rw-r--r--dom/base/DOMIntersectionObserver.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp
index 2f3a341c5..e7b3cd0da 100644
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -155,30 +155,29 @@ DOMIntersectionObserver::Observe(Element& aTarget)
return;
}
aTarget.RegisterIntersectionObserver(this);
- mObservationTargets.PutEntry(&aTarget);
+ mObservationTargets.AppendElement(&aTarget);
Connect();
}
void
DOMIntersectionObserver::Unobserve(Element& aTarget)
{
- if (UnlinkTarget(aTarget)) {
- aTarget.UnregisterIntersectionObserver(this);
+ if (mObservationTargets.Length() == 1) {
+ Disconnect();
+ return;
}
+
+ mObservationTargets.RemoveElement(&aTarget);
+ aTarget.UnregisterIntersectionObserver(this);
}
-bool
+void
DOMIntersectionObserver::UnlinkTarget(Element& aTarget)
{
- if (!mObservationTargets.Contains(&aTarget)) {
- return false;
- }
- if (mObservationTargets.Count() == 1) {
- Disconnect();
- return false;
- }
- mObservationTargets.RemoveEntry(&aTarget);
- return true;
+ mObservationTargets.RemoveElement(&aTarget);
+ if (mObservationTargets.Length() == 0) {
+ Disconnect();
+ }
}
void
@@ -200,15 +199,17 @@ DOMIntersectionObserver::Disconnect()
if (!mConnected) {
return;
}
- for (auto iter = mObservationTargets.Iter(); !iter.Done(); iter.Next()) {
- Element* target = iter.Get()->GetKey();
+
+ mConnected = false;
+
+ for (size_t i = 0; i < mObservationTargets.Length(); ++i) {
+ Element* target = mObservationTargets.ElementAt(i);
target->UnregisterIntersectionObserver(this);
}
mObservationTargets.Clear();
if (mDocument) {
mDocument->RemoveIntersectionObserver(this);
}
- mConnected = false;
}
void
@@ -318,8 +319,8 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time
rootMargin.Side(side) = nsLayoutUtils::ComputeCBDependentValue(basis, coord);
}
- for (auto iter = mObservationTargets.Iter(); !iter.Done(); iter.Next()) {
- Element* target = iter.Get()->GetKey();
+ for (size_t i = 0; i < mObservationTargets.Length(); ++i) {
+ Element* target = mObservationTargets.ElementAt(i);
nsIFrame* targetFrame = target->GetPrimaryFrame();
nsRect targetRect;
Maybe<nsRect> intersectionRect;
@@ -493,7 +494,7 @@ DOMIntersectionObserver::Notify()
}
mozilla::dom::Sequence<mozilla::OwningNonNull<DOMIntersectionObserverEntry>> entries;
if (entries.SetCapacity(mQueuedEntries.Length(), mozilla::fallible)) {
- for (uint32_t i = 0; i < mQueuedEntries.Length(); ++i) {
+ for (size_t i = 0; i < mQueuedEntries.Length(); ++i) {
RefPtr<DOMIntersectionObserverEntry> next = mQueuedEntries[i];
*entries.AppendElement(mozilla::fallible) = next;
}