Bug 1448535 part 3 - Remove arena-related code from ComputedStyle. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Mon, 26 Mar 2018 11:54:30 +1100
changeset 772912 ae97a4674ae1633a068e8e5eb596cfd79c6df035
parent 772911 f08304fc5116b30936b0a9cf023112c53ae2b5b8
child 772913 f817dff1c5d4f9ba460c9dc5d1a45ee1c53202ff
push id104086
push userxquan@mozilla.com
push dateTue, 27 Mar 2018 05:15:17 +0000
reviewersemilio
bugs1448535
milestone61.0a1
Bug 1448535 part 3 - Remove arena-related code from ComputedStyle. r?emilio MozReview-Commit-ID: G2xh9nibHwJ
layout/style/ComputedStyle.cpp
layout/style/ComputedStyle.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
--- a/layout/style/ComputedStyle.cpp
+++ b/layout/style/ComputedStyle.cpp
@@ -310,23 +310,16 @@ void ComputedStyle::List(FILE* out, int3
     AppendUTF16toUTF8(buffer, str);
     str.Append(' ');
   }
 
   fprintf_stderr(out, "%s{ServoComputedData}\n", str.get());
 }
 #endif
 
-
-nsIPresShell*
-ComputedStyle::Arena()
-{
-  return PresContext()->PresShell();
-}
-
 template<typename Func>
 static nscolor
 GetVisitedDependentColorInternal(ComputedStyle* aSc, Func aColorFunc)
 {
   nscolor colors[2];
   colors[0] = aColorFunc(aSc);
   if (ComputedStyle* visitedStyle = aSc->GetStyleIfVisited()) {
     colors[1] = aColorFunc(visitedStyle);
--- a/layout/style/ComputedStyle.h
+++ b/layout/style/ComputedStyle.h
@@ -61,25 +61,16 @@ public:
   ComputedStyle(nsPresContext* aPresContext,
                 nsAtom* aPseudoTag,
                 CSSPseudoElementType aPseudoType,
                 ServoComputedDataForgotten aComputedValues);
 
   nsPresContext* PresContext() const { return mPresContext; }
   const ServoComputedData* ComputedData() const { return &mSource; }
 
-  // These two methods are for use by ArenaRefPtr.
-  //
-  // FIXME(emilio): Think this can go away.
-  static mozilla::ArenaObjectID ArenaObjectID()
-  {
-    return mozilla::eArenaObjectID_GeckoComputedStyle;
-  }
-  nsIPresShell* Arena();
-
   void AddRef() { Servo_ComputedStyle_AddRef(this); }
   void Release() { Servo_ComputedStyle_Release(this); }
 
   // Return the style context whose style data should be used for the R,
   // G, and B components of color, background-color, and border-*-color
   // if RelevantLinkIsVisited().
   //
   // GetPseudo() and GetPseudoType() on this style context return the
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -412,16 +412,18 @@ uint32_t
 nsComputedDOMStyle::Length()
 {
   uint32_t length = GetComputedStyleMap()->Length();
 
   // Make sure we have up to date style so that we can include custom
   // properties.
   UpdateCurrentStyleSources(false);
   if (mComputedStyle) {
+    MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() ==
+                       mPresShell->GetPresContext());
     length += Servo_GetCustomPropertiesCount(mComputedStyle);
   }
 
   ClearCurrentStyleSources();
 
   return length;
 }
 
@@ -721,16 +723,18 @@ nsComputedDOMStyle::GetCSSImageURLs(cons
 
   UpdateCurrentStyleSources(false);
 
   if (!mComputedStyle) {
     aRv.Throw(NS_ERROR_NOT_AVAILABLE);
     return;
   }
 
+  MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() ==
+                     mPresShell->GetPresContext());
   CollectImageURLsForProperty(prop, *mComputedStyle, aImageURLs);
   ClearCurrentStyleSources();
 }
 
 // nsDOMCSSDeclaration abstract methods which should never be called
 // on a nsComputedDOMStyle object, but must be defined to avoid
 // compile errors.
 DeclarationBlock*
@@ -1087,16 +1091,18 @@ nsComputedDOMStyle::IndexedGetter(uint32
   // Custom properties are exposed with indexed properties just after all
   // of the built-in properties.
   UpdateCurrentStyleSources(false);
   if (!mComputedStyle) {
     aFound = false;
     return;
   }
 
+  MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() ==
+                     mPresShell->GetPresContext());
   uint32_t count =
     Servo_GetCustomPropertiesCount(mComputedStyle);
 
   const uint32_t index = aIndex - length;
   if (index < count) {
     aFound = true;
     nsString varName;
     Servo_GetCustomPropertyNameAt(mComputedStyle, index, &varName);
@@ -5627,16 +5633,18 @@ nsComputedDOMStyle::GetLineHeightCoord(n
 
     if (nsLayoutUtils::IsNonWrapperBlock(mInnerFrame)) {
       blockHeight = mInnerFrame->GetContentRect().height;
     } else {
       GetCBContentHeight(blockHeight);
     }
   }
 
+  MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() ==
+                     mPresShell->GetPresContext());
   // lie about font size inflation since we lie about font size (since
   // the inflation only applies to text)
   aCoord = ReflowInput::CalcLineHeight(mContent, mComputedStyle,
                                        blockHeight, 1.0f);
 
   // CalcLineHeight uses font->mFont.size, but we want to use
   // font->mSize as the font size.  Adjust for that.  Also adjust for
   // the text zoom, if any.
@@ -7107,16 +7115,18 @@ MarkComputedStyleMapDirty(const char* aP
 {
   static_cast<ComputedStyleMap*>(aData)->MarkDirty();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetCustomProperty(const nsAString& aPropertyName)
 {
   MOZ_ASSERT(nsCSSProps::IsCustomPropertyName(aPropertyName));
+  MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() ==
+                     mPresShell->GetPresContext());
 
   nsString variableValue;
   const nsAString& name = Substring(aPropertyName,
                                     CSS_CUSTOM_NAME_PREFIX_LENGTH);
   bool present =
     Servo_GetCustomPropertyValue(mComputedStyle, &name, &variableValue);
   if (!present) {
     return nullptr;
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -4,18 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* DOM object returned from element.getComputedStyle() */
 
 #ifndef nsComputedDOMStyle_h__
 #define nsComputedDOMStyle_h__
 
-#include "mozilla/ArenaRefPtr.h"
-#include "mozilla/ArenaRefPtrInlines.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/StyleComplexColor.h"
 #include "mozilla/UniquePtr.h"
 #include "nsCOMPtr.h"
 #include "nscore.h"
 #include "nsCSSProps.h"
 #include "nsDOMCSSDeclaration.h"
 #include "mozilla/ComputedStyle.h"
@@ -171,19 +169,21 @@ private:
   void SetFrameComputedStyle(mozilla::ComputedStyle* aStyle, uint64_t aGeneration);
 
   static already_AddRefed<mozilla::ComputedStyle>
   DoGetComputedStyleNoFlush(mozilla::dom::Element* aElement,
                             nsAtom* aPseudo,
                             nsIPresShell* aPresShell,
                             StyleType aStyleType);
 
-#define STYLE_STRUCT(name_)                 \
-  const nsStyle##name_ * Style##name_() {   \
-    return mComputedStyle->Style##name_();  \
+#define STYLE_STRUCT(name_)                             \
+  const nsStyle##name_ * Style##name_() {               \
+    MOZ_RELEASE_ASSERT(mComputedStyle->PresContext() == \
+                       mPresShell->GetPresContext());   \
+    return mComputedStyle->Style##name_();              \
   }
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 
   already_AddRefed<CSSValue> GetEllipseRadii(const nsStyleCorners& aRadius,
                                              mozilla::Corner aFullCorner);
 
   already_AddRefed<CSSValue> GetOffsetWidthFor(mozilla::Side aSide);
@@ -725,32 +725,33 @@ private:
 
   // We don't really have a good immutable representation of "presentation".
   // Given the way GetComputedStyle is currently used, we should just grab the
   // 0th presshell, if any, from the document.
   nsWeakPtr mDocumentWeak;
   nsCOMPtr<nsIContent> mContent;
 
   /**
-   * Strong reference to the style context we access data from.  This can be
-   * either a style context we resolved ourselves or a style context we got
+   * Strong reference to the computed style we access data from.  This can be
+   * either a computed style we resolved ourselves or a computed style we got
    * from our frame.
    *
-   * If we got the style context from the frame, we clear out mComputedStyle
+   * If we got the computed style from the frame, we clear out mComputedStyle
    * in ClearCurrentStyleSources.  If we resolved one ourselves, then
    * ClearCurrentStyleSources leaves it in mComputedStyle for use the next
    * time this nsComputedDOMStyle object is queried.  UpdateCurrentStyleSources
-   * in this case will check that the style context is still valid to be used,
+   * in this case will check that the computed style is still valid to be used,
    * by checking whether flush styles results in any restyles having been
    * processed.
    *
-   * Since an ArenaRefPtr is used to hold the style context, it will be cleared
-   * if the pres arena from which it was allocated goes away.
+   * Note that this computed style can keep a dangling reference before
+   * UpdateCurrentStyleSources is called, and it's completely unsafe to poke
+   * at it without first having called that.
    */
-  mozilla::ArenaRefPtr<mozilla::ComputedStyle> mComputedStyle;
+  RefPtr<mozilla::ComputedStyle> mComputedStyle;
   RefPtr<nsAtom> mPseudo;
 
   /*
    * While computing style data, the primary frame for mContent --- named "outer"
    * because we should use it to compute positioning data.  Null
    * otherwise.
    */
   nsIFrame* mOuterFrame;