Bug 1332322 part 1. Add an nsWrapperCache function to mark the wrapper as 'live' for GC purposes. r=mccr8

This commit is contained in:
Boris Zbarsky 2017-01-24 20:33:54 -05:00
parent 0cf16aa823
commit b39cdf67a8
7 changed files with 18 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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___ */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}