From b26b8d8eef0a86673c5a2b73af42ba4ab21336ae Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 6 Nov 2023 23:57:41 +0000 Subject: [PATCH] Bug 1849230 - End ShutdownChildrenInSubtree if accessibility was shut down. r=Jamie Unbinding an accessible from a document can cause accessibility to shut down if the accessible is the last remaining one with an xpcom wrapper. In that case we need to return early from ShutdownChildrenInSubtree. Differential Revision: https://phabricator.services.mozilla.com/D192382 --- accessible/generic/DocAccessible.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 248e08dec9ac..4d368ad5c9c1 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -2644,6 +2644,7 @@ void DocAccessible::UncacheChildrenInSubtree(LocalAccessible* aRoot) { } void DocAccessible::ShutdownChildrenInSubtree(LocalAccessible* aAccessible) { + MOZ_ASSERT(!nsAccessibilityService::IsShutdown()); // Traverse through children and shutdown them before this accessible. When // child gets shutdown then it removes itself from children array of its // parent. Use jdx index to process the cases if child is not attached to the @@ -2658,7 +2659,16 @@ void DocAccessible::ShutdownChildrenInSubtree(LocalAccessible* aAccessible) { // Don't cross document boundaries. The outerdoc shutdown takes care about // its subdocument. - if (!child->IsDoc()) ShutdownChildrenInSubtree(child); + if (!child->IsDoc()) { + ShutdownChildrenInSubtree(child); + if (nsAccessibilityService::IsShutdown()) { + // If XPCOM is the only consumer (devtools & mochitests), shutting down + // the child's subtree can cause a11y to shut down because the last + // xpcom accessibles will be removed. In that case, return early, our + // work is done. + return; + } + } } UnbindFromDocument(aAccessible);