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

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

Issue 1220883007: [dom] support iterable<> NodeList (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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
Index: Source/core/html/HTMLCollection.cpp
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp
index e2b14857228b5d7d87725109a4810d8a238860a9..d79ba45b571fe0edea4dc97d0e5266e86c72dc07 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -40,6 +40,42 @@
namespace blink {
+namespace {
+
+class HTMLCollectionIterationSource final : public ValueIterable<Element*>::IterationSource {
+public:
+ explicit HTMLCollectionIterationSource(HTMLCollection* collection)
+ : m_collection(collection)
+ {
+ }
+
+ bool next(ScriptState* scriptState, Element*& value, ExceptionState& exceptionState) override
+ {
+ if (m_index >= m_collection->length()) {
+ value = nullptr;
+ return false;
+ }
+ value = m_collection->item(m_index);
+ return true;
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE()
+ {
+ visitor->trace(m_collection);
+ ValueIterable<Element*>::IterationSource::trace(visitor);
+ }
+
+private:
+ const RefPtrWillBeMember<HTMLCollection> m_collection;
+};
+
+} // namespace
+
+ValueIterable<Element*>::IterationSource* HTMLCollection::startIteration(ScriptState*, ExceptionState&)
+{
+ return new HTMLCollectionIterationSource(this);
+}
+
using namespace HTMLNames;
static bool shouldTypeOnlyIncludeDirectChildren(CollectionType type)

Powered by Google App Engine
This is Rietveld 408576698