summaryrefslogtreecommitdiffstats
path: root/dom/base/DOMIntersectionObserver.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/DOMIntersectionObserver.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/DOMIntersectionObserver.cpp')
-rw-r--r--dom/base/DOMIntersectionObserver.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp
index 0264a105e..e671b7da9 100644
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -162,6 +162,11 @@ DOMIntersectionObserver::Observe(Element& aTarget)
void
DOMIntersectionObserver::Unobserve(Element& aTarget)
{
+ if (!mObservationTargets.Contains(&aTarget)) {
+ // You're not on the list, buddy!
+ return;
+ }
+
if (mObservationTargets.Length() == 1) {
Disconnect();
return;
@@ -188,7 +193,7 @@ DOMIntersectionObserver::Connect()
}
mConnected = true;
- if(mDocument) {
+ if (mDocument) {
mDocument->AddIntersectionObserver(this);
}
}
@@ -293,12 +298,25 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time
if (rootFrame) {
nsPresContext* presContext = rootFrame->PresContext();
while (!presContext->IsRootContentDocument()) {
- presContext = rootFrame->PresContext()->GetParentPresContext();
- rootFrame = presContext->PresShell()->GetRootScrollFrame();
+ // Walk up the tree
+ presContext = presContext->GetParentPresContext();
+ if (!presContext) {
+ break;
+ }
+ nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
+ if (rootScrollFrame) {
+ rootFrame = rootScrollFrame;
+ } else {
+ break;
+ }
}
root = rootFrame->GetContent()->AsElement();
nsIScrollableFrame* scrollFrame = do_QueryFrame(rootFrame);
- rootRect = scrollFrame->GetScrollPortRect();
+ // If we end up with a null root frame for some reason, we'll proceed
+ // with an empty root intersection rect.
+ if (scrollFrame) {
+ rootRect = scrollFrame->GetScrollPortRect();
+ }
}
}
}