summaryrefslogtreecommitdiffstats
path: root/dom/base/nsDocument.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-01-18 19:09:30 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-01-18 19:09:30 +0100
commitef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa (patch)
treea7b3a29171ddabcb3f06d86b835f13e84c715d84 /dom/base/nsDocument.cpp
parentf6ef8d8ca7ed96d699c28914fc590b0604520fd0 (diff)
downloadUXP-ef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa.tar
UXP-ef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa.tar.gz
UXP-ef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa.tar.lz
UXP-ef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa.tar.xz
UXP-ef8a5dca4f49f859c5b5a7fa9e079b2b7b9bf8fa.zip
Rewrite IntersectionObserver list handling to be more robust.
Tag #935.
Diffstat (limited to 'dom/base/nsDocument.cpp')
-rw-r--r--dom/base/nsDocument.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp
index 14de65cbd..d4d488379 100644
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12313,6 +12313,10 @@ nsDocument::RemoveIntersectionObserver(DOMIntersectionObserver* aObserver)
void
nsDocument::UpdateIntersectionObservations()
{
+ if (mIntersectionObservers.IsEmpty()) {
+ return;
+ }
+
DOMHighResTimeStamp time = 0;
if (nsPIDOMWindowInner* window = GetInnerWindow()) {
Performance* perf = window->GetPerformance();
@@ -12320,9 +12324,15 @@ nsDocument::UpdateIntersectionObservations()
time = perf->Now();
}
}
+ nsTArray<RefPtr<DOMIntersectionObserver>> observers(mIntersectionObservers.Count());
for (auto iter = mIntersectionObservers.Iter(); !iter.Done(); iter.Next()) {
DOMIntersectionObserver* observer = iter.Get()->GetKey();
- observer->Update(this, time);
+ observers.AppendElement(observer);
+ }
+ for (const auto& observer : observers) {
+ if (observer) {
+ observer->Update(this, time);
+ }
}
}
@@ -12335,7 +12345,7 @@ nsDocument::ScheduleIntersectionObserverNotification()
nsCOMPtr<nsIRunnable> notification = NewRunnableMethod(this,
&nsDocument::NotifyIntersectionObservers);
- NS_DispatchToCurrentThread(notification);
+ NS_DispatchToCurrentThread(notification.forget());
}
void
@@ -12347,7 +12357,9 @@ nsDocument::NotifyIntersectionObservers()
observers.AppendElement(observer);
}
for (const auto& observer : observers) {
- observer->Notify();
+ if (observer) {
+ observer->Notify();
+ }
}
}