Bug 847144 - Rename Element::GetAttributes() to Attributes() and remove null-checks; r=mounir

This commit is contained in:
Ms2ger 2013-03-10 08:58:47 +01:00
parent 161a2d489e
commit 4d99e1ce9d
3 changed files with 12 additions and 50 deletions

View File

@ -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);
}

View File

@ -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<nsIDOMAttr>
@ -791,14 +785,8 @@ Element::SetAttributeNode(nsIDOMAttr* aNewAttr, ErrorResult& aError)
{
OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNode);
nsDOMAttributeMap* map = GetAttributes();
if (!map) {
// XXX Throw?
return nullptr;
}
nsCOMPtr<nsIDOMNode> 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<nsIDOMNode> 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<nsIDOMAttr>
@ -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<nsIHTMLCollection>
@ -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;
}

View File

@ -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<nsDOMAttributeMap> map = GetAttributes();
map.forget(aAttributes);
return NS_OK;
}
bool