Bug 1710283 - Null-check lazyload intersection observers on unregistration. r=sefeng
It seems plausible for the doc to be unlinked, or for the element to be moved to another document, in between the time observer notification is scheduled and the time it runs. In that case, we'd be unregistered already anyways, so there's nothing else to do. Differential Revision: https://phabricator.services.mozilla.com/D114740
This commit is contained in:
@@ -1293,13 +1293,17 @@ void HTMLImageElement::StopLazyLoading(
|
||||
}
|
||||
mLazyLoading = false;
|
||||
Document* doc = OwnerDoc();
|
||||
doc->GetLazyLoadImageObserver()->Unobserve(*this);
|
||||
if (auto* obs = doc->GetLazyLoadImageObserver()) {
|
||||
obs->Unobserve(*this);
|
||||
}
|
||||
|
||||
if (bool(aFromIntersectionObserver)) {
|
||||
doc->IncLazyLoadImageStarted();
|
||||
} else {
|
||||
doc->DecLazyLoadImageCount();
|
||||
doc->GetLazyLoadImageObserverViewport()->Unobserve(*this);
|
||||
if (auto* obs = doc->GetLazyLoadImageObserverViewport()) {
|
||||
obs->Unobserve(*this);
|
||||
}
|
||||
}
|
||||
|
||||
if (bool(aStartLoading)) {
|
||||
@@ -1309,7 +1313,9 @@ void HTMLImageElement::StopLazyLoading(
|
||||
|
||||
void HTMLImageElement::LazyLoadImageReachedViewport() {
|
||||
Document* doc = OwnerDoc();
|
||||
doc->GetLazyLoadImageObserverViewport()->Unobserve(*this);
|
||||
if (auto* obs = doc->GetLazyLoadImageObserverViewport()) {
|
||||
obs->Unobserve(*this);
|
||||
}
|
||||
doc->IncLazyLoadImageReachViewport(!Complete());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user