From a8f10f24ece04ffee57610adf7b2e06d3a365b9f Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 5 May 2017 13:48:53 -0700 Subject: [PATCH] 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 | 2 +- layout/style/ServoElementSnapshot.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/layout/style/ServoElementSnapshot.cpp b/layout/style/ServoElementSnapshot.cpp index 29999ffe3749..1ef36308abd3 100644 --- a/layout/style/ServoElementSnapshot.cpp +++ b/layout/style/ServoElementSnapshot.cpp @@ -32,7 +32,7 @@ ServoElementSnapshot::AddAttrs(Element* aElement) { MOZ_ASSERT(aElement); - if (HasAny(Flags::Attributes)) { + if (HasAttrs()) { return; } diff --git a/layout/style/ServoElementSnapshot.h b/layout/style/ServoElementSnapshot.h index 7a064d9e110d..0b3b797b999d 100644 --- a/layout/style/ServoElementSnapshot.h +++ b/layout/style/ServoElementSnapshot.h @@ -70,9 +70,9 @@ public: 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). @@ -95,6 +95,7 @@ public: */ BorrowedAttrInfo GetAttrInfoAt(uint32_t aIndex) const { + MOZ_ASSERT(HasAttrs()); if (aIndex >= mAttrs.Length()) { return BorrowedAttrInfo(nullptr, nullptr); } @@ -109,6 +110,7 @@ public: 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 @@ -135,7 +137,7 @@ public: 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