From b39cdf67a8b52f0086e04d04ba0ddbba5aa3fe13 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 24 Jan 2017 20:33:54 -0500 Subject: [PATCH] Bug 1332322 part 1. Add an nsWrapperCache function to mark the wrapper as 'live' for GC purposes. r=mccr8 --- dom/base/EventSource.cpp | 3 +-- dom/base/WebSocket.cpp | 3 +-- dom/base/nsWrapperCache.h | 5 +++++ dom/base/nsWrapperCacheInlines.h | 8 ++++++++ dom/events/DOMEventTargetHelper.cpp | 3 +-- dom/xhr/XMLHttpRequestMainThread.cpp | 3 +-- layout/style/nsDOMCSSAttrDeclaration.cpp | 3 +-- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 06de2947d810..86f297d81e92 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -2058,8 +2058,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(EventSource) tmp->mListenerManager->MarkForCC(); } if (!isBlack && tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); + tmp->MarkWrapperLive(); } return true; } diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index c5f7952c7839..4c4883d201bf 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -1436,8 +1436,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(WebSocket) tmp->mListenerManager->MarkForCC(); } if (!isBlack && tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); + tmp->MarkWrapperLive(); } return true; } diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index c477d7e100b4..15dccf1c7ae9 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -174,6 +174,11 @@ public: bool HasNothingToTrace(nsISupports* aThis); + /** + * Mark our wrapper, if any, as live as far as the CC is concerned. + */ + void MarkWrapperLive(); + // Only meant to be called by code that preserves a wrapper. void SetPreservingWrapper(bool aPreserve) { diff --git a/dom/base/nsWrapperCacheInlines.h b/dom/base/nsWrapperCacheInlines.h index 5519e20f0a61..9ead4c2c2177 100644 --- a/dom/base/nsWrapperCacheInlines.h +++ b/dom/base/nsWrapperCacheInlines.h @@ -53,4 +53,12 @@ nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports* aThis) return IsBlack() && HasNothingToTrace(aThis); } +inline void +nsWrapperCache::MarkWrapperLive() +{ + // Just call GetWrapper and ignore the return value. It will do the + // gray-unmarking for us. + GetWrapper(); +} + #endif /* nsWrapperCache_h___ */ diff --git a/dom/events/DOMEventTargetHelper.cpp b/dom/events/DOMEventTargetHelper.cpp index 4b4795bdef5c..f110a627f4e6 100644 --- a/dom/events/DOMEventTargetHelper.cpp +++ b/dom/events/DOMEventTargetHelper.cpp @@ -57,8 +57,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(DOMEventTargetHelper) tmp->mListenerManager->MarkForCC(); } if (!tmp->IsBlack() && tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); + tmp->MarkWrapperLive(); } return true; } diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index e72e5f9cb5e1..31cd729e535c 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -321,8 +321,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(XMLHttpRequestMainThread) tmp->mListenerManager->MarkForCC(); } if (!isBlack && tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); + tmp->MarkWrapperLive(); } return true; } diff --git a/layout/style/nsDOMCSSAttrDeclaration.cpp b/layout/style/nsDOMCSSAttrDeclaration.cpp index dd9f0b3ae60e..2ec5208afd0c 100644 --- a/layout/style/nsDOMCSSAttrDeclaration.cpp +++ b/layout/style/nsDOMCSSAttrDeclaration.cpp @@ -43,8 +43,7 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCSSAttributeDeclaration, mElement) NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDOMCSSAttributeDeclaration) if (tmp->mElement && Element::CanSkip(tmp->mElement, true)) { if (tmp->PreservingWrapper()) { - // This marks the wrapper black. - tmp->GetWrapper(); + tmp->MarkWrapperLive(); } return true; }