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

Unified Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2737273002: [DOM] Fix null namespace handling in Node.isDefaultNamespace(). (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Node.cpp
diff --git a/third_party/WebKit/Source/core/dom/Node.cpp b/third_party/WebKit/Source/core/dom/Node.cpp
index 2d3a061973739b598e3b345d45378d6c94a8729b..2287b661c68ff829a3f1a43da7f9fd734b5c7fbd 100644
--- a/third_party/WebKit/Source/core/dom/Node.cpp
+++ b/third_party/WebKit/Source/core/dom/Node.cpp
@@ -1165,45 +1165,19 @@ bool Node::isEqualNode(Node* other) const {
bool Node::isDefaultNamespace(
const AtomicString& namespaceURIMaybeEmpty) const {
+ // https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
+
+ // 1. If namespace is the empty string, then set it to null.
const AtomicString& namespaceURI =
namespaceURIMaybeEmpty.isEmpty() ? nullAtom : namespaceURIMaybeEmpty;
- switch (getNodeType()) {
- case kElementNode: {
- const Element& element = toElement(*this);
-
- if (element.prefix().isNull())
- return element.namespaceURI() == namespaceURI;
-
- AttributeCollection attributes = element.attributes();
- for (const Attribute& attr : attributes) {
- if (attr.localName() == xmlnsAtom)
- return attr.value() == namespaceURI;
- }
-
- if (Element* parent = parentElement())
- return parent->isDefaultNamespace(namespaceURI);
+ // 2. Let defaultNamespace be the result of running locate a namespace for
+ // context object using null.
+ const AtomicString& defaultNamespace = lookupNamespaceURI(String());
- return false;
- }
- case kDocumentNode:
- if (Element* de = toDocument(this)->documentElement())
- return de->isDefaultNamespace(namespaceURI);
- return false;
- case kDocumentTypeNode:
- case kDocumentFragmentNode:
- return false;
- case kAttributeNode: {
- const Attr* attr = toAttr(this);
- if (attr->ownerElement())
- return attr->ownerElement()->isDefaultNamespace(namespaceURI);
- return false;
- }
- default:
- if (Element* parent = parentElement())
- return parent->isDefaultNamespace(namespaceURI);
- return false;
- }
+ // 3. Return true if defaultNamespace is the same as namespace, and false
+ // otherwise.
+ return namespaceURI == defaultNamespace;
}
const AtomicString& Node::lookupPrefix(const AtomicString& namespaceURI) const {
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698