summaryrefslogtreecommitdiffstats
path: root/dom/base/Element.cpp
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-07-17 12:14:56 +0200
committerGitHub <noreply@github.com>2018-07-17 12:14:56 +0200
commit8eb01c2ce4960a6a908bb2efdd48f141bf548c92 (patch)
tree49640df1fd38269c64b12f45fff362b43fb08f6e /dom/base/Element.cpp
parent0cb3a0ccf18b2f763b856295c7cfa0a0c6b8941e (diff)
parentd4c0def3b80d6dd4359985e400a7282ce198c228 (diff)
downloadUXP-8eb01c2ce4960a6a908bb2efdd48f141bf548c92.tar
UXP-8eb01c2ce4960a6a908bb2efdd48f141bf548c92.tar.gz
UXP-8eb01c2ce4960a6a908bb2efdd48f141bf548c92.tar.lz
UXP-8eb01c2ce4960a6a908bb2efdd48f141bf548c92.tar.xz
UXP-8eb01c2ce4960a6a908bb2efdd48f141bf548c92.zip
Merge pull request #642 from janekptacijarabaci/dom_element_toggleAttribute_1
Add support for Element.toggleAttribute()
Diffstat (limited to 'dom/base/Element.cpp')
-rw-r--r--dom/base/Element.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index 52d06b0f8..79b36a314 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1230,6 +1230,42 @@ Element::GetAttribute(const nsAString& aName, DOMString& aReturn)
}
}
+bool
+Element::ToggleAttribute(const nsAString& aName,
+ const Optional<bool>& aForce,
+ ErrorResult& aError)
+{
+ aError = nsContentUtils::CheckQName(aName, false);
+ if (aError.Failed()) {
+ return false;
+ }
+
+ nsAutoString nameToUse;
+ const nsAttrName* name = InternalGetAttrNameFromQName(aName, &nameToUse);
+ if (!name) {
+ if (aForce.WasPassed() && !aForce.Value()) {
+ return false;
+ }
+ nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(nameToUse);
+ if (!nameAtom) {
+ aError.Throw(NS_ERROR_OUT_OF_MEMORY);
+ return false;
+ }
+ aError = SetAttr(kNameSpaceID_None, nameAtom, EmptyString(), true);
+ return true;
+ }
+ if (aForce.WasPassed() && aForce.Value()) {
+ return true;
+ }
+ // Hold a strong reference here so that the atom or nodeinfo doesn't go
+ // away during UnsetAttr. If it did UnsetAttr would be left with a
+ // dangling pointer as argument without knowing it.
+ nsAttrName tmp(*name);
+
+ aError = UnsetAttr(name->NamespaceID(), name->LocalName(), true);
+ return false;
+}
+
void
Element::SetAttribute(const nsAString& aName,
const nsAString& aValue,