Bug 1412145 - Drop more backpointers of CSSOM objects in dtor and unlink. r=bz

MozReview-Commit-ID: Ftg3WMBBNlO
This commit is contained in:
Xidorn Quan 2017-10-24 12:20:50 +11:00
Родитель 741c01cd43
Коммит 80a94641e2
10 изменённых файлов: 82 добавлений и 16 удалений

Просмотреть файл

@ -198,6 +198,13 @@ GeckoGroupRuleRules::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
// ServoGroupRuleRules
//
ServoGroupRuleRules::~ServoGroupRuleRules()
{
if (mRuleList) {
mRuleList->DropReference();
}
}
#ifdef DEBUG
void
ServoGroupRuleRules::List(FILE* out, int32_t aIndent) const

Просмотреть файл

@ -87,6 +87,7 @@ struct ServoGroupRuleRules
// Do we ever clone Servo rules?
MOZ_ASSERT_UNREACHABLE("stylo: Cloning GroupRule not implemented");
}
~ServoGroupRuleRules();
void SetParentRule(GroupRule* aParentRule) {
if (mRuleList) {

Просмотреть файл

@ -84,7 +84,9 @@ protected:
virtual nsresult Delete(const nsAString& aOldMedium) = 0;
virtual nsresult Append(const nsAString& aNewMedium) = 0;
virtual ~MediaList() {}
virtual ~MediaList() {
MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared");
}
// not refcounted; sheet will let us know when it goes away
// mStyleSheet is the sheet that needs to be dirtied when this

Просмотреть файл

@ -234,6 +234,8 @@ ServoCSSRuleList::GetDOMCSSRuleType(uint32_t aIndex) const
ServoCSSRuleList::~ServoCSSRuleList()
{
MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared");
MOZ_ASSERT(!mParentRule, "Backpointer should have been cleared");
DropAllRules();
}

Просмотреть файл

@ -35,7 +35,10 @@ public:
return NS_OK;
}
void DropReference() { mRule = nullptr; }
void DropReference() {
mRule = nullptr;
mDecls->SetOwningRule(nullptr);
}
DeclarationBlock* GetCSSDeclaration(Operation aOperation) final
{
@ -83,7 +86,9 @@ public:
}
private:
virtual ~ServoKeyframeDeclaration() {}
virtual ~ServoKeyframeDeclaration() {
MOZ_ASSERT(!mRule, "Backpointer should have been cleared");
}
ServoKeyframeRule* mRule;
RefPtr<ServoDeclarationBlock> mDecls;
@ -104,6 +109,9 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
ServoKeyframeRule::~ServoKeyframeRule()
{
if (mDeclaration) {
mDeclaration->DropReference();
}
}
NS_IMPL_ADDREF_INHERITED(ServoKeyframeRule, dom::CSSKeyframeRule)

Просмотреть файл

@ -90,7 +90,10 @@ public:
{
mStyleSheet = nullptr;
mParentRule = nullptr;
DropAllRules();
for (css::Rule* rule : mRules) {
rule->SetStyleSheet(nullptr);
rule->SetParentRule(nullptr);
}
}
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
@ -103,15 +106,16 @@ public:
}
private:
virtual ~ServoKeyframeList() {}
virtual ~ServoKeyframeList() {
MOZ_ASSERT(!mParentRule, "Backpointer should have been cleared");
MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared");
DropAllRules();
}
void DropAllRules()
{
for (css::Rule* rule : mRules) {
if (rule) {
rule->SetStyleSheet(nullptr);
rule->SetParentRule(nullptr);
}
if (mParentRule || mStyleSheet) {
DropReference();
}
mRules.Clear();
mRawRule = nullptr;
@ -163,6 +167,9 @@ ServoKeyframesRule::ServoKeyframesRule(RefPtr<RawServoKeyframesRule> aRawRule,
ServoKeyframesRule::~ServoKeyframesRule()
{
if (mKeyframeList) {
mKeyframeList->DropReference();
}
}
NS_IMPL_ADDREF_INHERITED(ServoKeyframesRule, dom::CSSKeyframesRule)

Просмотреть файл

@ -24,6 +24,9 @@ ServoMediaRule::ServoMediaRule(RefPtr<RawServoMediaRule> aRawRule,
ServoMediaRule::~ServoMediaRule()
{
if (mMediaList) {
mMediaList->SetStyleSheet(nullptr);
}
}
NS_IMPL_ADDREF_INHERITED(ServoMediaRule, CSSMediaRule)
@ -33,8 +36,18 @@ NS_IMPL_RELEASE_INHERITED(ServoMediaRule, CSSMediaRule)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServoMediaRule)
NS_INTERFACE_MAP_END_INHERITING(CSSMediaRule)
NS_IMPL_CYCLE_COLLECTION_INHERITED(ServoMediaRule, CSSMediaRule,
mMediaList)
NS_IMPL_CYCLE_COLLECTION_CLASS(ServoMediaRule)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoMediaRule, CSSMediaRule)
if (tmp->mMediaList) {
tmp->mMediaList->SetStyleSheet(nullptr);
tmp->mMediaList = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoMediaRule, CSSMediaRule)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
/* virtual */ already_AddRefed<css::Rule>
ServoMediaRule::Clone() const

Просмотреть файл

@ -26,6 +26,7 @@ ServoPageRuleDeclaration::ServoPageRuleDeclaration(
ServoPageRuleDeclaration::~ServoPageRuleDeclaration()
{
mDecls->SetOwningRule(nullptr);
}
// QueryInterface implementation for ServoPageRuleDeclaration
@ -143,6 +144,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoPageRule, CSSPageRule)
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
// directly because the wrapper is on the declaration, not on us.
tmp->mDecls.ReleaseWrapper(static_cast<nsISupports*>(p));
tmp->mDecls.mDecls->SetOwningRule(nullptr);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoPageRule, CSSPageRule)

Просмотреть файл

@ -28,6 +28,7 @@ ServoStyleRuleDeclaration::ServoStyleRuleDeclaration(
ServoStyleRuleDeclaration::~ServoStyleRuleDeclaration()
{
mDecls->SetOwningRule(nullptr);
}
// QueryInterface implementation for ServoStyleRuleDeclaration

Просмотреть файл

@ -208,12 +208,25 @@ ImportRule::~ImportRule()
NS_IMPL_ADDREF_INHERITED(ImportRule, CSSImportRule)
NS_IMPL_RELEASE_INHERITED(ImportRule, CSSImportRule)
NS_IMPL_CYCLE_COLLECTION_INHERITED(ImportRule, CSSImportRule, mMedia, mChildSheet)
// QueryInterface implementation for ImportRule
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImportRule)
NS_INTERFACE_MAP_END_INHERITING(CSSImportRule)
NS_IMPL_CYCLE_COLLECTION_CLASS(ImportRule)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ImportRule, CSSImportRule)
if (tmp->mChildSheet) {
tmp->mChildSheet->SetOwnerRule(nullptr);
tmp->mChildSheet = nullptr;
}
tmp->mMedia = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ImportRule, CSSImportRule)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMedia)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildSheet)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
#ifdef DEBUG
/* virtual */ void
ImportRule::List(FILE* out, int32_t aIndent) const
@ -338,8 +351,18 @@ NS_IMPL_RELEASE_INHERITED(MediaRule, CSSMediaRule)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaRule)
NS_INTERFACE_MAP_END_INHERITING(CSSMediaRule)
NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, CSSMediaRule,
mMedia)
NS_IMPL_CYCLE_COLLECTION_CLASS(MediaRule)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MediaRule, CSSMediaRule)
if (tmp->mMedia) {
tmp->mMedia->SetStyleSheet(nullptr);
tmp->mMedia = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaRule, CSSMediaRule)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMedia)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
/* virtual */ void
MediaRule::SetStyleSheet(StyleSheet* aSheet)