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

Side by Side 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: const& 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 unified diff | Download patch
« Source/core/dom/Iterable.h ('K') | « Source/modules/fetch/Headers.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/fetch/Headers.h" 6 #include "modules/fetch/Headers.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8IteratorResultValue.h" 10 #include "bindings/core/v8/V8IteratorResultValue.h"
11 #include "core/dom/Iterator.h" 11 #include "core/dom/Iterator.h"
12 #include "core/fetch/FetchUtils.h" 12 #include "core/fetch/FetchUtils.h"
13 #include "wtf/NotFound.h" 13 #include "wtf/NotFound.h"
14 #include "wtf/PassRefPtr.h" 14 #include "wtf/PassRefPtr.h"
15 #include "wtf/RefPtr.h" 15 #include "wtf/RefPtr.h"
16 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 namespace { 20 namespace {
21 21
22 class HeadersIterator final : public Iterator { 22 class HeadersIterationSource final : public PairIterable<String, String>::Iterat ionSource {
23 public: 23 public:
24 // Only KeyValue is currently used; the other types are to support 24 HeadersIterationSource(FetchHeaderList* headers) : m_headers(headers), m_cur rent(0) { }
haraken 2015/01/13 12:46:31 Add explicit.
Jens Widell 2015/01/13 12:57:40 Done.
25 // Map-like iteration with entries(), keys() and values(), but this has
26 // not yet been added to any spec.
27 enum IterationType { KeyValue, Key, Value };
28 25
29 HeadersIterator(FetchHeaderList* headers, IterationType type) : m_headers(he aders), m_type(type), m_current(0) { } 26 bool next(ScriptState* scriptState, String& key, String& value, ExceptionSta te& exception) override
30
31 virtual ScriptValue next(ScriptState* scriptState, ExceptionState& exception ) override
32 { 27 {
33 // FIXME: This simply advances an index and returns the next value if 28 // FIXME: This simply advances an index and returns the next value if
34 // any, so if the iterated object is mutated values may be skipped. 29 // any, so if the iterated object is mutated values may be skipped.
35 if (m_current >= m_headers->size()) 30 if (m_current >= m_headers->size())
haraken 2015/01/13 12:46:31 m_current => m_index
Jens Widell 2015/01/13 13:07:22 Joshua made a similar comment earlier, so I'll jus
36 return v8IteratorResultDone(scriptState); 31 return false;
37 32
38 const FetchHeaderList::Header& header = m_headers->entry(m_current++); 33 const FetchHeaderList::Header& header = m_headers->entry(m_current++);
39 switch (m_type) { 34 key = header.first;
40 case KeyValue: { 35 value = header.second;
41 Vector<String> pair; 36 return true;
42 pair.append(header.first);
43 pair.append(header.second);
44 return v8IteratorResult(scriptState, pair);
45 }
46 case Key:
47 return v8IteratorResult(scriptState, header.first);
48 case Value:
49 return v8IteratorResult(scriptState, header.second);
50 }
51 ASSERT_NOT_REACHED();
52 return ScriptValue();
53 } 37 }
54 38
55 virtual ScriptValue next(ScriptState* scriptState, ScriptValue, ExceptionSta te& exceptionState) override 39 void trace(Visitor* visitor) override
56 { 40 {
57 return next(scriptState, exceptionState); 41 PairIterable<String, String>::IterationSource::trace(visitor);
haraken 2015/01/13 12:46:31 Make this a tail call of trace() (Just a conventio
Jens Widell 2015/01/13 12:57:40 Done.
58 }
59
60 virtual void trace(Visitor* visitor)
61 {
62 Iterator::trace(visitor);
63 visitor->trace(m_headers); 42 visitor->trace(m_headers);
64 } 43 }
65 44
66 private: 45 private:
67 const Member<FetchHeaderList> m_headers; 46 const Member<FetchHeaderList> m_headers;
68 const IterationType m_type;
69 size_t m_current; 47 size_t m_current;
70 }; 48 };
71 49
72 } // namespace 50 } // namespace
73 51
74 Headers* Headers::create() 52 Headers* Headers::create()
75 { 53 {
76 return new Headers; 54 return new Headers;
77 } 55 }
78 56
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 , m_guard(NoneGuard) 311 , m_guard(NoneGuard)
334 { 312 {
335 } 313 }
336 314
337 Headers::Headers(FetchHeaderList* headerList) 315 Headers::Headers(FetchHeaderList* headerList)
338 : m_headerList(headerList) 316 : m_headerList(headerList)
339 , m_guard(NoneGuard) 317 , m_guard(NoneGuard)
340 { 318 {
341 } 319 }
342 320
343 Iterator* Headers::iterator(ScriptState*, ExceptionState&)
344 {
345 return new HeadersIterator(m_headerList, HeadersIterator::KeyValue);
346 }
347
348 void Headers::trace(Visitor* visitor) 321 void Headers::trace(Visitor* visitor)
349 { 322 {
350 visitor->trace(m_headerList); 323 visitor->trace(m_headerList);
351 } 324 }
352 325
326 PairIterable<String, String>::IterationSource* Headers::startIteration(ScriptSta te*, ExceptionState&)
327 {
328 return new HeadersIterationSource(m_headerList);
329 }
330
353 } // namespace blink 331 } // namespace blink
OLDNEW
« Source/core/dom/Iterable.h ('K') | « Source/modules/fetch/Headers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698