summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-09-30 16:02:17 +0000
committerMoonchild <moonchild@palemoon.org>2020-09-30 16:02:17 +0000
commitbc531bfbbaf0da9069b87b02d55190c80275e21b (patch)
tree66a277419c6cd4f2f14df61263c719f9c290c85d /dom
parentfb086631d910323c04361fa30ac8004f6209ca30 (diff)
downloadUXP-bc531bfbbaf0da9069b87b02d55190c80275e21b.tar
UXP-bc531bfbbaf0da9069b87b02d55190c80275e21b.tar.gz
UXP-bc531bfbbaf0da9069b87b02d55190c80275e21b.tar.lz
UXP-bc531bfbbaf0da9069b87b02d55190c80275e21b.tar.xz
UXP-bc531bfbbaf0da9069b87b02d55190c80275e21b.zip
Issue #1643 - Follow-up: Make sure things aren't changed while iterating.
This fixes some crashing scenarios.
Diffstat (limited to 'dom')
-rw-r--r--dom/base/ResizeObserverController.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/dom/base/ResizeObserverController.cpp b/dom/base/ResizeObserverController.cpp
index 117e67fbf..acc401a5e 100644
--- a/dom/base/ResizeObserverController.cpp
+++ b/dom/base/ResizeObserverController.cpp
@@ -118,6 +118,10 @@ ResizeObserverController::Notify()
return;
}
+ // Hold a strong reference to the document, because otherwise calling
+ // all active observers on it might yank it out from under us.
+ RefPtr<nsIDocument> document(mDocument);
+
uint32_t shallowestTargetDepth = 0;
GatherAllActiveObservations(shallowestTargetDepth);
@@ -152,7 +156,7 @@ ResizeObserverController::Notify()
nsEventStatus status = nsEventStatus_eIgnore;
nsCOMPtr<nsPIDOMWindowInner> window =
- mDocument->GetWindow()->GetCurrentInnerWindow();
+ document->GetWindow()->GetCurrentInnerWindow();
if (window) {
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
@@ -184,7 +188,11 @@ ResizeObserverController::BroadcastAllActiveObservations()
{
uint32_t shallowestTargetDepth = UINT32_MAX;
- for (auto observer : mResizeObservers) {
+ // Use a copy of the observers as this invokes the callbacks of the observers
+ // which could register/unregister observers at will.
+ nsTArray<RefPtr<ResizeObserver>> tempObservers(mResizeObservers);
+
+ for (auto observer : tempObservers) {
uint32_t targetDepth = observer->BroadcastActiveObservations();