Bug 1400624 - Fix a panic in Stylo memory reporting. r=heycam.
`MallocSizeOfOps::enclosing_size_of_op` is an `Option<>` type, and the panic in
question is caused by not providing a value in a case where it's needed for
measuring a HashSet.
HashMaps and HashSets are common enough that it makes sense to make
`enclosing_size_of_op` non-optional, which this patch does.
MozReview-Commit-ID: IB2aRuXHj8E
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -4209,33 +4209,36 @@ void
Element::SetCustomElementData(CustomElementData* aData)
{
nsExtendedDOMSlots *slots = ExtendedDOMSlots();
MOZ_ASSERT(!slots->mCustomElementData, "Custom element data may not be changed once set.");
slots->mCustomElementData = aData;
}
MOZ_DEFINE_MALLOC_SIZE_OF(ServoElementMallocSizeOf)
+MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoElementMallocEnclosingSizeOf)
void
Element::AddSizeOfExcludingThis(nsWindowSizes& aSizes, size_t* aNodeSize) const
{
FragmentOrElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
if (HasServoData()) {
// Measure the ElementData object itself.
aSizes.mLayoutServoElementDataObjects +=
aSizes.mState.mMallocSizeOf(mServoData.Get());
// Measure mServoData, excluding the ComputedValues. This measurement
- // counts towards the element's size. We use ServoElementMallocSizeOf
- // rather than |aState.mMallocSizeOf| to better distinguish in DMD's
- // output the memory measured within Servo code.
+ // counts towards the element's size. We use ServoElementMallocSizeOf and
+ // ServoElementMallocEnclosingSizeOf rather than |aState.mMallocSizeOf| to
+ // better distinguish in DMD's output the memory measured within Servo
+ // code.
*aNodeSize +=
Servo_Element_SizeOfExcludingThisAndCVs(ServoElementMallocSizeOf,
+ ServoElementMallocEnclosingSizeOf,
&aSizes.mState.mSeenPtrs, this);
// Now measure just the ComputedValues (and style structs) under
// mServoData. This counts towards the relevant fields in |aSizes|.
RefPtr<ServoStyleContext> sc;
if (Servo_Element_HasPrimaryComputedValues(this)) {
sc = Servo_Element_GetPrimaryComputedValues(this).Consume();
if (!aSizes.mState.HaveSeenPtr(sc.get())) {
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -16,18 +16,19 @@
* Users of this list should define a macro
* SERVO_BINDING_FUNC(name_, return_, ...)
* before including this file.
*/
// Element data
SERVO_BINDING_FUNC(Servo_Element_ClearData, void, RawGeckoElementBorrowed node)
SERVO_BINDING_FUNC(Servo_Element_SizeOfExcludingThisAndCVs, size_t,
- mozilla::MallocSizeOf, mozilla::SeenPtrs* seen_ptrs,
- RawGeckoElementBorrowed node)
+ mozilla::MallocSizeOf malloc_size_of,
+ mozilla::MallocSizeOf malloc_enclosing_size_of,
+ mozilla::SeenPtrs* seen_ptrs, RawGeckoElementBorrowed node)
SERVO_BINDING_FUNC(Servo_Element_HasPrimaryComputedValues, bool,
RawGeckoElementBorrowed node)
SERVO_BINDING_FUNC(Servo_Element_GetPrimaryComputedValues,
ServoStyleContextStrong,
RawGeckoElementBorrowed node)
SERVO_BINDING_FUNC(Servo_Element_HasPseudoComputedValues, bool,
RawGeckoElementBorrowed node, size_t index)
SERVO_BINDING_FUNC(Servo_Element_GetPseudoComputedValues,
@@ -55,16 +56,17 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_HasR
RawServoStyleSheetContentsBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_GetRules, ServoCssRulesStrong,
RawServoStyleSheetContentsBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_Clone, RawServoStyleSheetContentsStrong,
RawServoStyleSheetContentsBorrowed sheet,
const mozilla::ServoStyleSheet* reference_sheet);
SERVO_BINDING_FUNC(Servo_StyleSheet_SizeOfIncludingThis, size_t,
mozilla::MallocSizeOf malloc_size_of,
+ mozilla::MallocSizeOf malloc_enclosing_size_of,
RawServoStyleSheetContentsBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_GetSourceMapURL, void,
RawServoStyleSheetContentsBorrowed sheet, nsAString* result)
// We'd like to return `OriginFlags` here, but bindgen bitfield enums don't
// work as return values with the Linux 32-bit ABI at the moment because
// they wrap the value in a struct.
SERVO_BINDING_FUNC(Servo_StyleSheet_GetOrigin, uint8_t,
RawServoStyleSheetContentsBorrowed sheet)
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -109,23 +109,26 @@ ServoStyleSheetInner::~ServoStyleSheetIn
StyleSheetInfo*
ServoStyleSheetInner::CloneFor(StyleSheet* aPrimarySheet)
{
return new ServoStyleSheetInner(*this,
static_cast<ServoStyleSheet*>(aPrimarySheet));
}
MOZ_DEFINE_MALLOC_SIZE_OF(ServoStyleSheetMallocSizeOf)
+MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoStyleSheetMallocEnclosingSizeOf)
size_t
ServoStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += Servo_StyleSheet_SizeOfIncludingThis(
- ServoStyleSheetMallocSizeOf, mContents);
+ ServoStyleSheetMallocSizeOf,
+ ServoStyleSheetMallocEnclosingSizeOf,
+ mContents);
return n;
}
ServoStyleSheet::ServoStyleSheet(css::SheetParsingMode aParsingMode,
CORSMode aCORSMode,
net::ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity)
: StyleSheet(StyleBackendType::Servo, aParsingMode)