From a2961d74e77e702d5ab1ba1199352f9db9570e83 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Mon, 6 Apr 2020 18:21:59 +0000 Subject: [PATCH] Bug 1625789, optimize CustomElement constructors out from cycle collection graph, r=mccr8 Using the method name GetExistingCustomElements() to match CustomElements(), even though they both return CustomElementRegistry. Differential Revision: https://phabricator.services.mozilla.com/D69853 --HG-- extra : moz-landing-system : lando --- dom/base/CustomElementRegistry.cpp | 9 +++++++++ dom/base/CustomElementRegistry.h | 2 ++ dom/base/nsCCUncollectableMarker.cpp | 5 +++++ dom/base/nsGlobalWindowInner.cpp | 4 ++++ dom/base/nsGlobalWindowInner.h | 1 + 5 files changed, 21 insertions(+) diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index b03154ede0be..066b7b8ebe40 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -1244,6 +1244,15 @@ already_AddRefed CustomElementRegistry::CallGetCustomInterface( return wrapper.forget(); } +void CustomElementRegistry::TraceDefinitions(JSTracer* aTrc) { + for (auto iter = mCustomDefinitions.Iter(); !iter.Done(); iter.Next()) { + RefPtr& definition = iter.Data(); + if (definition && definition->mConstructor) { + mozilla::TraceScriptHolder(definition->mConstructor, aTrc); + } + } +} + //----------------------------------------------------- // CustomElementReactionsStack diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index cce28249b879..fd300feffa90 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -466,6 +466,8 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache { elements->PutEntry(elem); } + void TraceDefinitions(JSTracer* aTrc); + private: ~CustomElementRegistry(); diff --git a/dom/base/nsCCUncollectableMarker.cpp b/dom/base/nsCCUncollectableMarker.cpp index 076f4179abce..cd142977bccb 100644 --- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -31,6 +31,7 @@ #include "mozilla/dom/ChromeMessageBroadcaster.h" #include "mozilla/dom/ContentFrameMessageManager.h" #include "mozilla/dom/ContentProcessMessageManager.h" +#include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/ParentProcessMessageManager.h" #include "mozilla/dom/BrowserChild.h" @@ -467,6 +468,10 @@ void mozilla::dom::TraceBlackJS(JSTracer* aTrc, bool aIsShutdownGC) { if (elm) { elm->TraceListeners(aTrc); } + CustomElementRegistry* cer = inner->GetExistingCustomElements(); + if (cer) { + cer->TraceDefinitions(aTrc); + } } } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 4b1d2a30034b..496f249f78be 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -2163,6 +2163,10 @@ CustomElementRegistry* nsGlobalWindowInner::CustomElements() { return mCustomElements; } +CustomElementRegistry* nsGlobalWindowInner::GetExistingCustomElements() { + return mCustomElements; +} + Performance* nsPIDOMWindowInner::GetPerformance() { CreatePerformanceObjectIfNeeded(); return mPerformance; diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 6167d8b5e2b5..81e7fa1124f0 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -587,6 +587,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, mozilla::dom::Location* Location() override; nsHistory* GetHistory(mozilla::ErrorResult& aError); mozilla::dom::CustomElementRegistry* CustomElements() override; + mozilla::dom::CustomElementRegistry* GetExistingCustomElements(); mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError); mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError); mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);