From aee876626a79cfc92948af134a825feba980dded Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Thu, 7 Feb 2019 14:37:26 +0000 Subject: [PATCH] Bug 1524106 - Disconnect l10n root when destroying the document. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D18774 --HG-- extra : moz-landing-system : lando --- dom/base/Document.cpp | 4 ++++ intl/l10n/DocumentL10n.cpp | 9 +++++++++ intl/l10n/DocumentL10n.h | 1 + intl/l10n/mozIDOMLocalization.idl | 1 + 4 files changed, 15 insertions(+) diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 12d627beec87..ecd50a4924aa 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -7498,6 +7498,10 @@ void Document::Destroy() { mIsGoingAway = true; + if (mDocumentL10n) { + mDocumentL10n->Destroy(); + } + ScriptLoader()->Destroy(); SetScriptGlobalObject(nullptr); RemovedFromDocShell(); diff --git a/intl/l10n/DocumentL10n.cpp b/intl/l10n/DocumentL10n.cpp index 674c171bd4dd..837a56434e28 100644 --- a/intl/l10n/DocumentL10n.cpp +++ b/intl/l10n/DocumentL10n.cpp @@ -112,6 +112,15 @@ bool DocumentL10n::Init(nsTArray& aResourceIds) { return true; } +void DocumentL10n::Destroy() { + if (mDOMLocalization) { + Element* elem = mDocument->GetDocumentElement(); + if (elem) { + mDOMLocalization->DisconnectRoot(elem); + } + } +} + JSObject* DocumentL10n::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { return DocumentL10n_Binding::Wrap(aCx, this, aGivenProto); diff --git a/intl/l10n/DocumentL10n.h b/intl/l10n/DocumentL10n.h index 3c4131cc7121..707b273952fd 100644 --- a/intl/l10n/DocumentL10n.h +++ b/intl/l10n/DocumentL10n.h @@ -65,6 +65,7 @@ class DocumentL10n final : public nsWrapperCache { public: explicit DocumentL10n(Document* aDocument); bool Init(nsTArray& aResourceIds); + void Destroy(); protected: virtual ~DocumentL10n(); diff --git a/intl/l10n/mozIDOMLocalization.idl b/intl/l10n/mozIDOMLocalization.idl index df74f4ffc0be..5823391efde0 100644 --- a/intl/l10n/mozIDOMLocalization.idl +++ b/intl/l10n/mozIDOMLocalization.idl @@ -24,6 +24,7 @@ interface mozIDOMLocalization : nsISupports Promise translateElements(in Array aElements); void connectRoot(in Element aElement); + void disconnectRoot(in Element aElement); Promise translateRoots(); readonly attribute Promise ready; };