diff --git a/content/base/public/Element.h b/content/base/public/Element.h index fb6aae8059fa..83745f6be611 100644 --- a/content/base/public/Element.h +++ b/content/base/public/Element.h @@ -548,9 +548,9 @@ public: } nsDOMTokenList* GetClassList(); - nsDOMAttributeMap* GetAttributes() + nsDOMAttributeMap* Attributes() { - nsDOMSlots *slots = DOMSlots(); + nsDOMSlots* slots = DOMSlots(); if (!slots->mAttributeMap) { slots->mAttributeMap = new nsDOMAttributeMap(this); } diff --git a/content/base/src/Element.cpp b/content/base/src/Element.cpp index 956f255b01d4..5c1a4c422960 100644 --- a/content/base/src/Element.cpp +++ b/content/base/src/Element.cpp @@ -777,13 +777,7 @@ nsIDOMAttr* Element::GetAttributeNode(const nsAString& aName) { OwnerDoc()->WarnOnceAbout(nsIDocument::eGetAttributeNode); - - nsDOMAttributeMap* map = GetAttributes(); - if (!map) { - return nullptr; - } - - return map->GetNamedItem(aName); + return Attributes()->GetNamedItem(aName); } already_AddRefed @@ -791,14 +785,8 @@ Element::SetAttributeNode(nsIDOMAttr* aNewAttr, ErrorResult& aError) { OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNode); - nsDOMAttributeMap* map = GetAttributes(); - if (!map) { - // XXX Throw? - return nullptr; - } - nsCOMPtr returnNode; - aError = map->SetNamedItem(aNewAttr, getter_AddRefs(returnNode)); + aError = Attributes()->SetNamedItem(aNewAttr, getter_AddRefs(returnNode)); if (aError.Failed()) { return nullptr; } @@ -812,12 +800,6 @@ Element::RemoveAttributeNode(nsIDOMAttr* aAttribute, { OwnerDoc()->WarnOnceAbout(nsIDocument::eRemoveAttributeNode); - nsDOMAttributeMap* map = GetAttributes(); - if (!map) { - // XXX Throw? - return nullptr; - } - nsAutoString name; aError = aAttribute->GetName(name); @@ -826,7 +808,7 @@ Element::RemoveAttributeNode(nsIDOMAttr* aAttribute, } nsCOMPtr node; - aError = map->RemoveNamedItem(name, getter_AddRefs(node)); + aError = Attributes()->RemoveNamedItem(name, getter_AddRefs(node)); if (aError.Failed()) { return nullptr; } @@ -909,12 +891,7 @@ Element::GetAttributeNodeNSInternal(const nsAString& aNamespaceURI, const nsAString& aLocalName, ErrorResult& aError) { - nsDOMAttributeMap* map = GetAttributes(); - if (!map) { - return nullptr; - } - - return map->GetNamedItemNS(aNamespaceURI, aLocalName, aError); + return Attributes()->GetNamedItemNS(aNamespaceURI, aLocalName, aError); } already_AddRefed @@ -922,13 +899,7 @@ Element::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, ErrorResult& aError) { OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNodeNS); - - nsDOMAttributeMap* map = GetAttributes(); - if (!map) { - return nullptr; - } - - return map->SetNamedItemNS(aNewAttr, aError); + return Attributes()->SetNamedItemNS(aNewAttr, aError); } already_AddRefed @@ -1505,14 +1476,7 @@ Element::GetExistingAttrNameFromQName(const nsAString& aStr) const NS_IMETHODIMP Element::GetAttributes(nsIDOMNamedNodeMap** aAttributes) { - nsDOMSlots *slots = DOMSlots(); - - if (!slots->mAttributeMap) { - slots->mAttributeMap = new nsDOMAttributeMap(this); - } - - NS_ADDREF(*aAttributes = slots->mAttributeMap); - + NS_ADDREF(*aAttributes = Attributes()); return NS_OK; } diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp index fca347e81f71..4c2bc07906c2 100644 --- a/content/base/src/nsINode.cpp +++ b/content/base/src/nsINode.cpp @@ -2408,17 +2408,15 @@ nsINode::GetAttributes() if (!IsElement()) { return nullptr; } - return AsElement()->GetAttributes(); + return AsElement()->Attributes(); } nsresult nsINode::GetAttributes(nsIDOMNamedNodeMap** aAttributes) { - if (!IsElement()) { - *aAttributes = nullptr; - return NS_OK; - } - return CallQueryInterface(GetAttributes(), aAttributes); + nsRefPtr map = GetAttributes(); + map.forget(aAttributes); + return NS_OK; } bool