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

Unified Diff: Source/core/html/HTMLCollection.cpp

Issue 148323008: Update HTMLCollection's named property getter to behave according to spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideation Created 6 years, 10 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 | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLCollection.cpp
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp
index ab7115febeab54ce8e6685399ac3df6d9288ed3c..63049916bebd65e06c5d22683d41af18bb1bfdd0 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Samsung Electronics. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -32,6 +33,7 @@
#include "core/html/HTMLElement.h"
#include "core/html/HTMLObjectElement.h"
#include "core/html/HTMLOptionElement.h"
+#include "wtf/HashSet.h"
namespace WebCore {
@@ -487,6 +489,46 @@ Element* HTMLCollection::namedItem(const AtomicString& name) const
return 0;
}
+bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState&)
+{
+ return namedItem(name);
+}
+
+void HTMLCollection::supportedPropertyNames(Vector<String>& names)
+{
+ // As per the specification (http://dom.spec.whatwg.org/#htmlcollection):
+ // The supported property names are the values from the list returned by these steps:
+ // 1. Let result be an empty list.
+ // 2. For each element represented by the collection, in tree order, run these substeps:
+ // 1. If element is in the HTML namespace and has a name attribute whose value is neither the empty string
+ // nor is in result, append element's name attribute value to result.
+ // 2. If element has an ID which is neither the empty string nor is in result, append element's ID to result.
+ // 3. Return result.
+ HashSet<AtomicString> existingNames;
+ ContainerNode& root = rootNode();
+ for (Element* element = traverseToFirstElement(root); element; element = traverseNextElement(*element, root)) {
+ if (element->isHTMLElement()) {
+ const AtomicString& nameAttribute = element->getNameAttribute();
+ if (!nameAttribute.isEmpty()) {
+ HashSet<AtomicString>::AddResult addResult = existingNames.add(nameAttribute);
+ if (addResult.isNewEntry)
+ names.append(nameAttribute);
+ }
+ }
+ const AtomicString& idAttribute = element->getIdAttribute();
+ if (!idAttribute.isEmpty()) {
+ HashSet<AtomicString>::AddResult addResult = existingNames.add(idAttribute);
+ if (addResult.isNewEntry)
+ names.append(idAttribute);
+ }
+ }
+}
+
+void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionState&)
+{
+ return supportedPropertyNames(names);
+}
+
void HTMLCollection::updateNameCache() const
{
if (hasNameCache())
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698