From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/dom/NamedNodeMap.cpp | 69 +++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'Source/WebCore/dom/NamedNodeMap.cpp') 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 NamedNodeMap::getNamedItem(const AtomicString& name) const +RefPtr NamedNodeMap::getNamedItem(const AtomicString& name) const { return m_element.getAttributeNode(name); } -PassRefPtr NamedNodeMap::getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const +RefPtr NamedNodeMap::getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const { return m_element.getAttributeNodeNS(namespaceURI, localName); } -PassRefPtr NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec) +ExceptionOr> 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 NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec) +Vector 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 names = m_element.getAttributeNames(); + if (is(m_element) && is(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 NamedNodeMap::setNamedItem(Node* node, ExceptionCode& ec) +ExceptionOr> 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 NamedNodeMap::setNamedItemNS(Node* node, ExceptionCode& ec) +ExceptionOr> NamedNodeMap::setNamedItem(Attr& attr) { - return setNamedItem(node, ec); + return m_element.setAttributeNode(attr); } -PassRefPtr NamedNodeMap::item(unsigned index) const +RefPtr NamedNodeMap::item(unsigned index) const { if (index >= length()) - return 0; + return nullptr; return m_element.ensureAttr(m_element.attributeAt(index).name()); } -- cgit v1.2.1