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

Unified Diff: Source/modules/fetch/Headers.cpp

Issue 848673002: Add keys(), values() and entries() methods on iterable<> interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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/modules/fetch/Headers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/fetch/Headers.cpp
diff --git a/Source/modules/fetch/Headers.cpp b/Source/modules/fetch/Headers.cpp
index db5461a94002cee02b06e7c04feaaee618883569..651c9b4d00c844e5977e804061a227c698d5e5c3 100644
--- a/Source/modules/fetch/Headers.cpp
+++ b/Source/modules/fetch/Headers.cpp
@@ -19,53 +19,31 @@ namespace blink {
namespace {
-class HeadersIterator final : public Iterator {
+class HeadersIterationSource final : public PairIterable<String, String>::IterationSource {
public:
- // Only KeyValue is currently used; the other types are to support
- // Map-like iteration with entries(), keys() and values(), but this has
- // not yet been added to any spec.
- enum IterationType { KeyValue, Key, Value };
+ explicit HeadersIterationSource(FetchHeaderList* headers) : m_headers(headers), m_current(0) { }
- HeadersIterator(FetchHeaderList* headers, IterationType type) : m_headers(headers), m_type(type), m_current(0) { }
-
- virtual ScriptValue next(ScriptState* scriptState, ExceptionState& exception) override
+ bool next(ScriptState* scriptState, String& key, String& value, ExceptionState& exception) override
{
// FIXME: This simply advances an index and returns the next value if
// any, so if the iterated object is mutated values may be skipped.
if (m_current >= m_headers->size())
- return v8IteratorResultDone(scriptState);
+ return false;
const FetchHeaderList::Header& header = m_headers->entry(m_current++);
- switch (m_type) {
- case KeyValue: {
- Vector<String> pair;
- pair.append(header.first);
- pair.append(header.second);
- return v8IteratorResult(scriptState, pair);
- }
- case Key:
- return v8IteratorResult(scriptState, header.first);
- case Value:
- return v8IteratorResult(scriptState, header.second);
- }
- ASSERT_NOT_REACHED();
- return ScriptValue();
- }
-
- virtual ScriptValue next(ScriptState* scriptState, ScriptValue, ExceptionState& exceptionState) override
- {
- return next(scriptState, exceptionState);
+ key = header.first;
+ value = header.second;
+ return true;
}
- virtual void trace(Visitor* visitor)
+ void trace(Visitor* visitor) override
{
- Iterator::trace(visitor);
visitor->trace(m_headers);
+ PairIterable<String, String>::IterationSource::trace(visitor);
}
private:
const Member<FetchHeaderList> m_headers;
- const IterationType m_type;
size_t m_current;
};
@@ -340,14 +318,14 @@ Headers::Headers(FetchHeaderList* headerList)
{
}
-Iterator* Headers::iterator(ScriptState*, ExceptionState&)
+void Headers::trace(Visitor* visitor)
{
- return new HeadersIterator(m_headerList, HeadersIterator::KeyValue);
+ visitor->trace(m_headerList);
}
-void Headers::trace(Visitor* visitor)
+PairIterable<String, String>::IterationSource* Headers::startIteration(ScriptState*, ExceptionState&)
{
- visitor->trace(m_headerList);
+ return new HeadersIterationSource(m_headerList);
}
} // namespace blink
« no previous file with comments | « Source/modules/fetch/Headers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698