From c4405e747ee01adf0182b3cf7a83a93333fd2447 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sat, 11 Aug 2012 00:27:28 +0200 Subject: [PATCH] Bug 794582 - Rename nsINode::GetSlots() to nsINode::Slots() and remove null-checks; r=mounir --- content/base/public/FragmentOrElement.h | 2 +- content/base/public/nsINode.h | 24 +++++++++++------------ content/base/src/FragmentOrElement.cpp | 9 +++------ content/base/src/nsDocument.cpp | 2 +- content/base/src/nsGenericDOMDataNode.cpp | 5 +---- content/base/src/nsGenericDOMDataNode.h | 4 ++-- content/base/src/nsINode.cpp | 6 +----- content/xul/content/src/nsXULElement.cpp | 3 +-- 8 files changed, 21 insertions(+), 34 deletions(-) diff --git a/content/base/public/FragmentOrElement.h b/content/base/public/FragmentOrElement.h index 37d2bbf3159e..6cb11f726d47 100644 --- a/content/base/public/FragmentOrElement.h +++ b/content/base/public/FragmentOrElement.h @@ -410,7 +410,7 @@ protected: nsDOMSlots *DOMSlots() { - return static_cast(GetSlots()); + return static_cast(Slots()); } nsDOMSlots *GetExistingDOMSlots() const diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index 2cdc31b034ec..13026626745c 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -789,13 +789,11 @@ public: */ void AddMutationObserver(nsIMutationObserver* aMutationObserver) { - nsSlots* s = GetSlots(); - if (s) { - NS_ASSERTION(s->mMutationObservers.IndexOf(aMutationObserver) == - nsTArray::NoIndex, - "Observer already in the list"); - s->mMutationObservers.AppendElement(aMutationObserver); - } + nsSlots* s = Slots(); + NS_ASSERTION(s->mMutationObservers.IndexOf(aMutationObserver) == + nsTArray::NoIndex, + "Observer already in the list"); + s->mMutationObservers.AppendElement(aMutationObserver); } /** @@ -804,10 +802,8 @@ public: */ void AddMutationObserverUnlessExists(nsIMutationObserver* aMutationObserver) { - nsSlots* s = GetSlots(); - if (s) { - s->mMutationObservers.AppendElementUnlessExists(aMutationObserver); - } + nsSlots* s = Slots(); + s->mMutationObservers.AppendElementUnlessExists(aMutationObserver); } /** @@ -893,7 +889,7 @@ public: #ifdef DEBUG nsSlots* DebugGetSlots() { - return GetSlots(); + return Slots(); } #endif @@ -1419,6 +1415,7 @@ public: protected: // Override this function to create a custom slots class. + // Must not return null. virtual nsINode::nsSlots* CreateSlots(); bool HasSlots() const @@ -1431,10 +1428,11 @@ protected: return mSlots; } - nsSlots* GetSlots() + nsSlots* Slots() { if (!HasSlots()) { mSlots = CreateSlots(); + MOZ_ASSERT(mSlots); } return GetExistingSlots(); } diff --git a/content/base/src/FragmentOrElement.cpp b/content/base/src/FragmentOrElement.cpp index 7075b8a3d6a6..1658e2a1a0a3 100644 --- a/content/base/src/FragmentOrElement.cpp +++ b/content/base/src/FragmentOrElement.cpp @@ -482,10 +482,9 @@ NS_IMPL_ISUPPORTS1(nsNodeWeakReference, nsNodeWeakReference::~nsNodeWeakReference() { if (mNode) { - NS_ASSERTION(mNode->GetSlots() && - mNode->GetSlots()->mWeakReference == this, + NS_ASSERTION(mNode->Slots()->mWeakReference == this, "Weak reference has wrong value"); - mNode->GetSlots()->mWeakReference = nullptr; + mNode->Slots()->mWeakReference = nullptr; } } @@ -509,9 +508,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNodeSupportsWeakRefTearoff) NS_IMETHODIMP nsNodeSupportsWeakRefTearoff::GetWeakReference(nsIWeakReference** aInstancePtr) { - nsINode::nsSlots* slots = mNode->GetSlots(); - NS_ENSURE_TRUE(slots, NS_ERROR_OUT_OF_MEMORY); - + nsINode::nsSlots* slots = mNode->Slots(); if (!slots->mWeakReference) { slots->mWeakReference = new nsNodeWeakReference(mNode); NS_ENSURE_TRUE(slots->mWeakReference, NS_ERROR_OUT_OF_MEMORY); diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 0a2641a4baf4..5bf174116b28 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -1986,7 +1986,7 @@ nsDocument::Init() mRadioGroups.Init(); // Force initialization. - nsINode::nsSlots* slots = GetSlots(); + nsINode::nsSlots* slots = Slots(); // Prepend self as mutation-observer whether we need it or not (some // subclasses currently do, other don't). This is because the code in diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index e2380cce6098..47ca8c5c37ce 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -458,15 +458,12 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // First set the binding parent if (aBindingParent) { - nsDataSlots *slots = GetDataSlots(); - NS_ENSURE_TRUE(slots, NS_ERROR_OUT_OF_MEMORY); - NS_ASSERTION(IsRootOfNativeAnonymousSubtree() || !HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE) || (aParent && aParent->IsInNativeAnonymousSubtree()), "Trying to re-bind content from native anonymous subtree to " "non-native anonymous parent!"); - slots->mBindingParent = aBindingParent; // Weak, so no addref happens. + DataSlots()->mBindingParent = aBindingParent; // Weak, so no addref happens. if (aParent->IsInNativeAnonymousSubtree()) { SetFlags(NODE_IS_IN_ANONYMOUS_SUBTREE); } diff --git a/content/base/src/nsGenericDOMDataNode.h b/content/base/src/nsGenericDOMDataNode.h index c8b7975bfdd6..deeff26c74e9 100644 --- a/content/base/src/nsGenericDOMDataNode.h +++ b/content/base/src/nsGenericDOMDataNode.h @@ -269,9 +269,9 @@ protected: // Override from nsINode virtual nsINode::nsSlots* CreateSlots(); - nsDataSlots *GetDataSlots() + nsDataSlots* DataSlots() { - return static_cast(GetSlots()); + return static_cast(Slots()); } nsDataSlots *GetExistingDataSlots() const diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp index 34a13b5d870a..919e94c659bc 100644 --- a/content/base/src/nsINode.cpp +++ b/content/base/src/nsINode.cpp @@ -311,11 +311,7 @@ nsINode::GetSelectionRootContent(nsIPresShell* aPresShell) nsINodeList* nsINode::GetChildNodesList() { - nsSlots *slots = GetSlots(); - if (!slots) { - return nullptr; - } - + nsSlots* slots = Slots(); if (!slots->mChildNodes) { slots->mChildNodes = new nsChildContentList(this); if (slots->mChildNodes) { diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 260e0ec358d8..83c866451816 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -1376,8 +1376,7 @@ nsXULElement::LoadSrc() NodeInfo()->Equals(nsGkAtoms::overlay, kNameSpaceID_XUL)) { return NS_OK; } - nsXULSlots* slots = static_cast(GetSlots()); - NS_ENSURE_TRUE(slots, NS_ERROR_OUT_OF_MEMORY); + nsXULSlots* slots = static_cast(Slots()); if (!slots->mFrameLoader) { // false as the last parameter so that xul:iframe/browser/editor // session history handling works like dynamic html:iframes.