Bug 1649197 - Remove StyleSheet::UnparentChildren. r=nordzilla

It leaves parent pointers nulled out when it really shouldn't when
cloning shared sheets (if there's another suitable parent, we should use
that instead of nulling out).

Fix the code in StyleSheetInfo::RemoveSheet to handle all cases
(including nulling out when removing the only remaining sheet), and rely
on that instead.

Differential Revision: https://phabricator.services.mozilla.com/D81569
This commit is contained in:
Emilio Cobos Álvarez 2020-06-29 18:41:20 +00:00
Родитель 63d17a46c6
Коммит 7649856b1f
2 изменённых файлов: 6 добавлений и 28 удалений

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

@ -194,8 +194,6 @@ void StyleSheet::LastRelease() {
MOZ_DIAGNOSTIC_ASSERT(mAdopters.IsEmpty(),
"Should have no adopters at time of destruction.");
UnparentChildren();
mInner->RemoveSheet(this);
mInner = nullptr;
@ -416,9 +414,12 @@ void StyleSheetInfo::AddSheet(StyleSheet* aSheet) {
}
void StyleSheetInfo::RemoveSheet(StyleSheet* aSheet) {
if (aSheet == mSheets[0] && mSheets.Length() > 1) {
StyleSheet* newParent = mSheets[1];
for (StyleSheet* child : mChildren) {
// Fix up the parent pointer in children lists.
StyleSheet* newParent = aSheet == mSheets[0] ? mSheets.SafeElementAt(1) : mSheets[0];
for (StyleSheet* child : mChildren) {
MOZ_ASSERT(child->mParentSheet);
MOZ_ASSERT(child->mParentSheet->mInner == this);
if (child->mParentSheet == aSheet) {
child->mParentSheet = newParent;
}
}
@ -890,27 +891,6 @@ void StyleSheet::RemoveFromParent() {
mParentSheet = nullptr;
}
void StyleSheet::UnparentChildren() {
MOZ_ASSERT(!mDocumentOrShadowRoot,
"How did we get to the destructor, exactly, if we're owned "
"by a document?");
// XXXbz this is a little bogus; see the comment where we
// declare mChildren in StyleSheetInfo.
//
// FIXME(emilio): StyleSheetInfo::RemoveSheet fixes up the parent list
// instead... We should maybe remove this and make that fix up more correct
// (right now it only tries to fix them up if you're the first sheet, but
// there's no guarantee that the first stylesheet is where the children end up
// being inserted in presence of deferred loads).
for (StyleSheet* child : Inner().mChildren) {
MOZ_ASSERT(!child->GetParentSheet() ||
child->GetParentSheet()->mInner == mInner);
if (child->mParentSheet == this) {
child->mParentSheet = nullptr;
}
}
}
void StyleSheet::SubjectSubsumesInnerPrincipal(nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv) {
StyleSheetInfo& info = Inner();

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

@ -530,8 +530,6 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache {
// assertion will fail if the expectation does not match reality.
void ApplicableStateChanged(bool aApplicable);
void UnparentChildren();
void LastRelease();
// Return success if the subject principal subsumes the principal of our