Bug 1227458. Make setAttributeNode be an alias for setAttributeNodeNS and setNamedItem on the attribute map be an alias for setNamedItemNS. r=smaug

This commit is contained in:
Boris Zbarsky 2015-12-04 09:51:04 -05:00
parent 6fb87fd62a
commit 305d74eb7d
6 changed files with 27 additions and 48 deletions

View File

@ -1233,9 +1233,11 @@ Element::GetAttributeNode(const nsAString& aName)
already_AddRefed<Attr>
Element::SetAttributeNode(Attr& aNewAttr, ErrorResult& aError)
{
// XXXbz can we just remove this warning and the one in setAttributeNodeNS and
// alias setAttributeNode to setAttributeNodeNS?
OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNode);
return Attributes()->SetNamedItem(aNewAttr, aError);
return Attributes()->SetNamedItemNS(aNewAttr, aError);
}
already_AddRefed<Attr>

View File

@ -240,7 +240,7 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMAttr* aAttr, nsIDOMAttr** aReturn)
NS_ENSURE_ARG(attribute);
ErrorResult rv;
*aReturn = SetNamedItem(*attribute, rv).take();
*aReturn = SetNamedItemNS(*attribute, rv).take();
return rv.StealNSResult();
}
@ -256,9 +256,7 @@ nsDOMAttributeMap::SetNamedItemNS(nsIDOMAttr* aAttr, nsIDOMAttr** aReturn)
}
already_AddRefed<Attr>
nsDOMAttributeMap::SetNamedItemInternal(Attr& aAttr,
bool aWithNS,
ErrorResult& aError)
nsDOMAttributeMap::SetNamedItemNS(Attr& aAttr, ErrorResult& aError)
{
NS_ENSURE_TRUE(mContent, nullptr);
@ -293,24 +291,18 @@ nsDOMAttributeMap::SetNamedItemInternal(Attr& aAttr,
// Get nodeinfo and preexisting attribute (if it exists)
RefPtr<NodeInfo> oldNi;
if (!aWithNS) {
nsAutoString name;
aAttr.GetName(name);
oldNi = mContent->GetExistingAttrNameFromQName(name);
} else {
uint32_t i, count = mContent->GetAttrCount();
for (i = 0; i < count; ++i) {
const nsAttrName* name = mContent->GetAttrNameAt(i);
int32_t attrNS = name->NamespaceID();
nsIAtom* nameAtom = name->LocalName();
uint32_t i, count = mContent->GetAttrCount();
for (i = 0; i < count; ++i) {
const nsAttrName* name = mContent->GetAttrNameAt(i);
int32_t attrNS = name->NamespaceID();
nsIAtom* nameAtom = name->LocalName();
// we're purposefully ignoring the prefix.
if (aAttr.NodeInfo()->Equals(nameAtom, attrNS)) {
oldNi = mContent->NodeInfo()->NodeInfoManager()->
GetNodeInfo(nameAtom, name->GetPrefix(), aAttr.NodeInfo()->NamespaceID(),
nsIDOMNode::ATTRIBUTE_NODE);
break;
}
// we're purposefully ignoring the prefix.
if (aAttr.NodeInfo()->Equals(nameAtom, attrNS)) {
oldNi = mContent->NodeInfo()->NodeInfoManager()->
GetNodeInfo(nameAtom, name->GetPrefix(), aAttr.NodeInfo()->NamespaceID(),
nsIDOMNode::ATTRIBUTE_NODE);
break;
}
}

View File

@ -141,11 +141,6 @@ public:
Attr* NamedGetter(const nsAString& aAttrName, bool& aFound);
bool NameIsEnumerable(const nsAString& aName);
already_AddRefed<Attr>
SetNamedItem(Attr& aAttr, ErrorResult& aError)
{
return SetNamedItemInternal(aAttr, false, aError);
}
already_AddRefed<Attr>
RemoveNamedItem(mozilla::dom::NodeInfo* aNodeInfo, ErrorResult& aError);
already_AddRefed<Attr>
RemoveNamedItem(const nsAString& aName, ErrorResult& aError);
@ -158,10 +153,7 @@ public:
GetNamedItemNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName);
already_AddRefed<Attr>
SetNamedItemNS(Attr& aNode, ErrorResult& aError)
{
return SetNamedItemInternal(aNode, true, aError);
}
SetNamedItemNS(Attr& aNode, ErrorResult& aError);
already_AddRefed<Attr>
RemoveNamedItemNS(const nsAString& aNamespaceURI, const nsAString& aLocalName,
ErrorResult& aError);
@ -184,13 +176,6 @@ private:
*/
AttrCache mAttributeCache;
/**
* SetNamedItem() (aWithNS = false) and SetNamedItemNS() (aWithNS =
* true) implementation.
*/
already_AddRefed<Attr>
SetNamedItemInternal(Attr& aNode, bool aWithNS, ErrorResult& aError);
already_AddRefed<mozilla::dom::NodeInfo>
GetAttrNodeInfo(const nsAString& aNamespaceURI,
const nsAString& aLocalName);

View File

@ -29,7 +29,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1075702
document.documentElement.setAttributeNode(a1);
document.documentElement.setAttributeNode(a2);
is(document.documentElement.getAttributeNS("", "aa"), null, "Should be NULL!");
is(document.documentElement.getAttributeNS("", "aa"), "lowercase", "Should be lowercase!");
is(document.documentElement.getAttributeNS("", "AA"), "UPPERCASE", "Should be UPPERCASE!");
var a3 = document.createAttribute("AA");

View File

@ -27,17 +27,17 @@ function testGetAttribute() {
document.body.setAttributeNode(a1);
document.body.setAttributeNode(a2);
var log = document.getElementById("log");
is(document.body.getAttribute('aa'), null, "Attribute has the localName AA and not aa.");
is(document.body.getAttribute('AA'), null, "Attribute has the localName AA and not aa.");
is(document.body.getAttributeNS("", "aa"), null, "Attribute should have localName AA.");
is(document.body.getAttributeNS("", "AA"), "UPPERCASE", "Attribute should have value UPPERCASE!");
is(document.body.getAttribute('aa'), "lowercase", "First attribute should have localname aa (1).");
is(document.body.getAttribute('AA'), "lowercase", "First attribute should have localname aa (2).");
is(document.body.getAttributeNS("", "aa"), "lowercase", "First attribute should have localName aa (3).");
is(document.body.getAttributeNS("", "AA"), "UPPERCASE", "Second attribute should have value UPPERCASE!");
var s = "";
for (var i = 0; i < document.body.attributes.length; ++i) {
s += document.body.attributes[i].nodeName + "=" +
document.body.attributes[i].nodeValue;
}
is(s, "AA=UPPERCASE", "Wrong attribute!");
is(s, "aa=lowercaseAA=UPPERCASE", "Wrong attribute!");
is(document.body.getAttributeNode("aa"), document.body.getAttributeNode("AA"),
"Wrong node!");
@ -45,9 +45,9 @@ function testGetAttribute() {
document.body.getAttributeNodeNS("", "AA").nodeValue = "FOO";
is(document.body.getAttributeNS("", "AA"), "FOO", "Wrong value!");
document.body.removeAttributeNode(document.body.getAttributeNodeNS("", "AA"));
ok(!document.body.getAttributeNode("AA"), "Should not have attribute node!");
ok(!document.body.getAttributeNode("aa"), "Should not have attribute node!");
document.body.removeAttributeNode(document.body.getAttributeNodeNS("", "aa"));
ok(!document.body.getAttributeNode("AA"), "Should not have attribute node! (1)");
ok(!document.body.getAttributeNode("aa"), "Should not have attribute node! (2)");
is(a2.nodeValue, "FOO", "Wrong value!");
a2.nodeValue = "UPPERCASE";

View File

@ -5,7 +5,7 @@
interface NamedNodeMap {
getter Attr? getNamedItem(DOMString name);
[Throws]
[Throws, BinaryName="setNamedItemNS"]
Attr? setNamedItem(Attr arg);
[Throws]
Attr removeNamedItem(DOMString name);