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

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: Rebaseline inpector test 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..4dc278927b61f635e4678f450f760dd4ef6704eb 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,45 @@ 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)
+{
+ // The supported property names are the values from the list returned by these steps:
haraken 2014/02/06 02:47:41 You can add a spec link: http://dom.spec.whatwg.or
Inactive 2014/02/06 02:55:39 Will do.
Inactive 2014/02/06 03:03:29 Done.
+ // 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() && (type() != DocAll || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) {
haraken 2014/02/06 02:47:41 I'm just curious: Where is this condition speced?
Inactive 2014/02/06 02:55:39 Right, this is spec'd at: http://www.whatwg.org/sp
Inactive 2014/02/06 03:01:24 Oops, the HTMLAllCollection spec says "with the id
Inactive 2014/02/06 03:03:29 Done.
+ 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