diff options
Diffstat (limited to 'Source/WebCore/dom/NamedNodeMap.cpp')
-rw-r--r-- | Source/WebCore/dom/NamedNodeMap.cpp | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/Source/WebCore/dom/NamedNodeMap.cpp b/Source/WebCore/dom/NamedNodeMap.cpp index 1b8df0f82..bcfa227a7 100644 --- a/Source/WebCore/dom/NamedNodeMap.cpp +++ b/Source/WebCore/dom/NamedNodeMap.cpp @@ -26,18 +26,14 @@ #include "NamedNodeMap.h" #include "Attr.h" -#include "Element.h" #include "ExceptionCode.h" +#include "HTMLDocument.h" +#include "HTMLElement.h" namespace WebCore { using namespace HTMLNames; -static inline bool shouldIgnoreAttributeCase(const Element& element) -{ - return element.isHTMLElement() && element.document().isHTMLDocument(); -} - void NamedNodeMap::ref() { m_element.ref(); @@ -48,61 +44,60 @@ void NamedNodeMap::deref() m_element.deref(); } -PassRefPtr<Node> NamedNodeMap::getNamedItem(const AtomicString& name) const +RefPtr<Attr> NamedNodeMap::getNamedItem(const AtomicString& name) const { return m_element.getAttributeNode(name); } -PassRefPtr<Node> NamedNodeMap::getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const +RefPtr<Attr> NamedNodeMap::getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const { return m_element.getAttributeNodeNS(namespaceURI, localName); } -PassRefPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec) +ExceptionOr<Ref<Attr>> NamedNodeMap::removeNamedItem(const AtomicString& name) { - unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(name, shouldIgnoreAttributeCase(m_element)) : ElementData::attributeNotFound; - if (index == ElementData::attributeNotFound) { - ec = NOT_FOUND_ERR; - return 0; - } + if (!m_element.hasAttributes()) + return Exception { NOT_FOUND_ERR }; + auto index = m_element.findAttributeIndexByName(name, shouldIgnoreAttributeCase(m_element)); + if (index == ElementData::attributeNotFound) + return Exception { NOT_FOUND_ERR }; return m_element.detachAttribute(index); } -PassRefPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec) +Vector<String> NamedNodeMap::supportedPropertyNames() const { - unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(QualifiedName(nullAtom, localName, namespaceURI)) : ElementData::attributeNotFound; - if (index == ElementData::attributeNotFound) { - ec = NOT_FOUND_ERR; - return 0; + Vector<String> names = m_element.getAttributeNames(); + if (is<HTMLElement>(m_element) && is<HTMLDocument>(m_element.document())) { + names.removeAllMatching([](String& name) { + for (auto character : StringView { name }.codeUnits()) { + if (isASCIIUpper(character)) + return true; + } + return false; + }); } - return m_element.detachAttribute(index); + return names; } -PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* node, ExceptionCode& ec) +ExceptionOr<Ref<Attr>> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) { - if (!node) { - ec = NOT_FOUND_ERR; - return 0; - } - - // Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node - if (!node->isAttributeNode()) { - ec = HIERARCHY_REQUEST_ERR; - return 0; - } - - return m_element.setAttributeNode(toAttr(node), ec); + if (!m_element.hasAttributes()) + return Exception { NOT_FOUND_ERR }; + auto index = m_element.findAttributeIndexByName(QualifiedName { nullAtom, localName, namespaceURI }); + if (index == ElementData::attributeNotFound) + return Exception { NOT_FOUND_ERR }; + return m_element.detachAttribute(index); } -PassRefPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionCode& ec) +ExceptionOr<RefPtr<Attr>> NamedNodeMap::setNamedItem(Attr& attr) { - return setNamedItem(node, ec); + return m_element.setAttributeNode(attr); } -PassRefPtr<Node> NamedNodeMap::item(unsigned index) const +RefPtr<Attr> NamedNodeMap::item(unsigned index) const { if (index >= length()) - return 0; + return nullptr; return m_element.ensureAttr(m_element.attributeAt(index).name()); } |