Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: Source/core/dom/NamedNodeMap.cpp

Issue 436603003: Make Element::attributes() less error-prone and simplify call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Keep synchronizeAllAttributes() in hasAttributes() Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
7 * (C) 2007 Eric Seidel (eric@webkit.org) 7 * (C) 2007 Eric Seidel (eric@webkit.org)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return m_element->getAttributeNode(name); 51 return m_element->getAttributeNode(name);
52 } 52 }
53 53
54 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::getNamedItemNS(const AtomicString& na mespaceURI, const AtomicString& localName) const 54 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::getNamedItemNS(const AtomicString& na mespaceURI, const AtomicString& localName) const
55 { 55 {
56 return m_element->getAttributeNodeNS(namespaceURI, localName); 56 return m_element->getAttributeNodeNS(namespaceURI, localName);
57 } 57 }
58 58
59 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& n ame, ExceptionState& exceptionState) 59 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& n ame, ExceptionState& exceptionState)
60 { 60 {
61 size_t index = m_element->hasAttributes() ? m_element->attributes().findInde x(name, m_element->shouldIgnoreAttributeCase()) : kNotFound; 61 size_t index = m_element->attributes().findIndex(name, m_element->shouldIgno reAttributeCase());
62 if (index == kNotFound) { 62 if (index == kNotFound) {
63 exceptionState.throwDOMException(NotFoundError, "No item with name '" + name + "' was found."); 63 exceptionState.throwDOMException(NotFoundError, "No item with name '" + name + "' was found.");
64 return nullptr; 64 return nullptr;
65 } 65 }
66 return m_element->detachAttribute(index); 66 return m_element->detachAttribute(index);
67 } 67 }
68 68
69 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionState& exceptionState) 69 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionState& exceptionState)
70 { 70 {
71 size_t index = m_element->hasAttributes() ? m_element->attributes().findInde x(QualifiedName(nullAtom, localName, namespaceURI)) : kNotFound; 71 size_t index = m_element->attributes().findIndex(QualifiedName(nullAtom, loc alName, namespaceURI));
72 if (index == kNotFound) { 72 if (index == kNotFound) {
73 exceptionState.throwDOMException(NotFoundError, "No item with name '" + namespaceURI + "::" + localName + "' was found."); 73 exceptionState.throwDOMException(NotFoundError, "No item with name '" + namespaceURI + "::" + localName + "' was found.");
74 return nullptr; 74 return nullptr;
75 } 75 }
76 return m_element->detachAttribute(index); 76 return m_element->detachAttribute(index);
77 } 77 }
78 78
79 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::setNamedItem(Node* node, ExceptionSta te& exceptionState) 79 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::setNamedItem(Node* node, ExceptionSta te& exceptionState)
80 { 80 {
81 if (!node) { 81 if (!node) {
(...skipping 10 matching lines...) Expand all
92 return m_element->setAttributeNode(toAttr(node), exceptionState); 92 return m_element->setAttributeNode(toAttr(node), exceptionState);
93 } 93 }
94 94
95 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionS tate& exceptionState) 95 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionS tate& exceptionState)
96 { 96 {
97 return setNamedItem(node, exceptionState); 97 return setNamedItem(node, exceptionState);
98 } 98 }
99 99
100 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::item(unsigned index) const 100 PassRefPtrWillBeRawPtr<Node> NamedNodeMap::item(unsigned index) const
101 { 101 {
102 if (!m_element->hasAttributes())
103 return nullptr;
104 AttributeCollection attributes = m_element->attributes(); 102 AttributeCollection attributes = m_element->attributes();
105 if (index >= attributes.size()) 103 if (index >= attributes.size())
106 return nullptr; 104 return nullptr;
107 return m_element->ensureAttr(attributes[index].name()); 105 return m_element->ensureAttr(attributes[index].name());
108 } 106 }
109 107
110 size_t NamedNodeMap::length() const 108 size_t NamedNodeMap::length() const
111 { 109 {
112 if (!m_element->hasAttributes())
113 return 0;
114 return m_element->attributes().size(); 110 return m_element->attributes().size();
115 } 111 }
116 112
117 void NamedNodeMap::trace(Visitor* visitor) 113 void NamedNodeMap::trace(Visitor* visitor)
118 { 114 {
119 visitor->trace(m_element); 115 visitor->trace(m_element);
120 } 116 }
121 117
122 } // namespace blink 118 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698