Bug 1362549 - Assert against accessing the attributes of a snapshot that doesn't have attributes saved. r=emilio
authorBobby Holley <bobbyholley@gmail.com>
Fri, 05 May 2017 13:48:53 -0700
changeset 404980 5a4de575944b503ec8d3f5e301200c3abc69e020
parent 404979 1c93dbb91910f1c7b6f07e794ac2af7a215e4522
child 404981 a717a61128accd351be6554bb747ef34f779c59b
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1362549
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1362549 - Assert against accessing the attributes of a snapshot that doesn't have attributes saved. r=emilio MozReview-Commit-ID: 8BsnTF6uIGM
layout/style/ServoElementSnapshot.cpp
layout/style/ServoElementSnapshot.h
--- a/layout/style/ServoElementSnapshot.cpp
+++ b/layout/style/ServoElementSnapshot.cpp
@@ -27,17 +27,17 @@ ServoElementSnapshot::~ServoElementSnaps
   MOZ_COUNT_DTOR(ServoElementSnapshot);
 }
 
 void
 ServoElementSnapshot::AddAttrs(Element* aElement)
 {
   MOZ_ASSERT(aElement);
 
-  if (HasAny(Flags::Attributes)) {
+  if (HasAttrs()) {
     return;
   }
 
   uint32_t attrCount = aElement->GetAttrCount();
   const nsAttrName* attrName;
   for (uint32_t i = 0; i < attrCount; ++i) {
     attrName = aElement->GetAttrNameAt(i);
     const nsAttrValue* attrValue =
--- a/layout/style/ServoElementSnapshot.h
+++ b/layout/style/ServoElementSnapshot.h
@@ -65,19 +65,19 @@ class ServoElementSnapshot
   typedef EventStates::ServoType ServoStateType;
 
 public:
   typedef ServoElementSnapshotFlags Flags;
 
   explicit ServoElementSnapshot(const Element* aElement);
   ~ServoElementSnapshot();
 
-  bool HasAttrs() { return HasAny(Flags::Attributes); }
+  bool HasAttrs() const { return HasAny(Flags::Attributes); }
 
-  bool HasState() { return HasAny(Flags::State); }
+  bool HasState() const { return HasAny(Flags::State); }
 
   /**
    * Captures the given state (if not previously captured).
    */
   void AddState(EventStates aState)
   {
     if (!HasAny(Flags::State)) {
       mState = aState.ServoValue();
@@ -90,30 +90,32 @@ public:
    */
   void AddAttrs(Element* aElement);
 
   /**
    * Needed methods for attribute matching.
    */
   BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const
   {
+    MOZ_ASSERT(HasAttrs());
     if (aIndex >= mAttrs.Length()) {
       return BorrowedAttrInfo(nullptr, nullptr);
     }
     return BorrowedAttrInfo(&mAttrs[aIndex].mName, &mAttrs[aIndex].mValue);
   }
 
   const nsAttrValue* GetParsedAttr(nsIAtom* aLocalName) const
   {
     return GetParsedAttr(aLocalName, kNameSpaceID_None);
   }
 
   const nsAttrValue* GetParsedAttr(nsIAtom* aLocalName,
                                    int32_t aNamespaceID) const
   {
+    MOZ_ASSERT(HasAttrs());
     uint32_t i, len = mAttrs.Length();
     if (aNamespaceID == kNameSpaceID_None) {
       // This should be the common case so lets make an optimized loop
       for (i = 0; i < len; ++i) {
         if (mAttrs[i].mName.Equals(aLocalName)) {
           return &mAttrs[i].mValue;
         }
       }
@@ -130,17 +132,17 @@ public:
     return nullptr;
   }
 
   bool IsInChromeDocument() const
   {
     return mIsInChromeDocument;
   }
 
-  bool HasAny(Flags aFlags) { return bool(mContains & aFlags); }
+  bool HasAny(Flags aFlags) const { return bool(mContains & aFlags); }
 
 private:
   // TODO: Profile, a 1 or 2 element AutoTArray could be worth it, given we know
   // we're dealing with attribute changes when we take snapshots of attributes,
   // though it can be wasted space if we deal with a lot of state-only
   // snapshots.
   Flags mContains;
   nsTArray<ServoAttrSnapshot> mAttrs;