| Index: Source/modules/webmidi/MIDIPortMap.h
|
| diff --git a/Source/modules/webmidi/MIDIPortMap.h b/Source/modules/webmidi/MIDIPortMap.h
|
| index 907e6ce5bea1ac4640588070867271fb60b49342..a7795cc32230bbf439bea267d053ebab8a702c0f 100644
|
| --- a/Source/modules/webmidi/MIDIPortMap.h
|
| +++ b/Source/modules/webmidi/MIDIPortMap.h
|
| @@ -9,8 +9,7 @@
|
| #include "bindings/core/v8/ScriptState.h"
|
| #include "bindings/core/v8/ScriptValue.h"
|
| #include "bindings/core/v8/V8Binding.h"
|
| -#include "bindings/core/v8/V8IteratorResultValue.h"
|
| -#include "core/dom/Iterator.h"
|
| +#include "core/dom/Iterable.h"
|
| #include "platform/heap/Handle.h"
|
| #include "wtf/HashMap.h"
|
| #include "wtf/text/StringHash.h"
|
| @@ -19,18 +18,14 @@
|
| namespace blink {
|
|
|
| template <typename T>
|
| -class MIDIPortMap : public GarbageCollected<MIDIPortMap<T>> {
|
| +class MIDIPortMap : public GarbageCollected<MIDIPortMap<T>>, public PairIterable<String, T*> {
|
| public:
|
| explicit MIDIPortMap(const HeapHashMap<String, Member<T>>& entries) : m_entries(entries) { }
|
|
|
| // IDL attributes / methods
|
| size_t size() const { return m_entries.size(); }
|
| - Iterator* keys();
|
| - Iterator* entries();
|
| - Iterator* values();
|
| T* get(const String& key) const;
|
| bool has(const String& key) const { return m_entries.contains(key); }
|
| - Iterator* iterator(ScriptState*, ExceptionState&) { return entries(); }
|
|
|
| virtual void trace(Visitor* visitor)
|
| {
|
| @@ -40,52 +35,37 @@ public:
|
| private:
|
| typedef HeapHashMap<String, Member<T>> MapType;
|
| typedef typename HeapHashMap<String, Member<T>>::const_iterator IteratorType;
|
| - struct KeySelector {
|
| - static const String& select(ScriptState*, IteratorType i) { return i->key; }
|
| - };
|
| - struct ValueSelector {
|
| - static T* select(ScriptState*, IteratorType i) { return i->value; }
|
| - };
|
| - struct EntrySelector {
|
| - static Vector<ScriptValue> select(ScriptState* scriptState, IteratorType i)
|
| - {
|
| - Vector<ScriptValue> entry;
|
| - entry.append(ScriptValue(scriptState, v8String(scriptState->isolate(), i->key)));
|
| - entry.append(ScriptValue(scriptState, toV8(i->value, scriptState->context()->Global(), scriptState->isolate())));
|
| - return entry;
|
| - }
|
| - };
|
| +
|
| + typename PairIterable<String, T*>::IterationSource* startIteration(ScriptState*, ExceptionState&) override
|
| + {
|
| + return new MapIterationSource(this, m_entries.begin(), m_entries.end());
|
| + }
|
|
|
| // Note: This template class relies on the fact that m_map.m_entries will
|
| // never be modified once it is created.
|
| - template <typename Selector>
|
| - class MapIterator : public Iterator {
|
| + class MapIterationSource final : public PairIterable<String, T*>::IterationSource {
|
| public:
|
| - MapIterator(MIDIPortMap<T>* map, IteratorType iterator, IteratorType end)
|
| + MapIterationSource(MIDIPortMap<T>* map, IteratorType iterator, IteratorType end)
|
| : m_map(map)
|
| , m_iterator(iterator)
|
| , m_end(end)
|
| {
|
| }
|
|
|
| - virtual ScriptValue next(ScriptState* scriptState, ExceptionState&) override
|
| + bool next(ScriptState* scriptState, String& key, T*& value, ExceptionState&) override
|
| {
|
| if (m_iterator == m_end)
|
| - return v8IteratorResultDone(scriptState);
|
| - ScriptValue result = v8IteratorResult(scriptState, Selector::select(scriptState, m_iterator));
|
| + return false;
|
| + key = m_iterator->key;
|
| + value = m_iterator->value;
|
| ++m_iterator;
|
| - return result;
|
| - }
|
| -
|
| - virtual ScriptValue next(ScriptState* scriptState, ScriptValue, ExceptionState& exceptionState) override
|
| - {
|
| - return next(scriptState, exceptionState);
|
| + return true;
|
| }
|
|
|
| - virtual void trace(Visitor* visitor) override
|
| + void trace(Visitor* visitor) override
|
| {
|
| visitor->trace(m_map);
|
| - Iterator::trace(visitor);
|
| + PairIterable<String, T*>::IterationSource::trace(visitor);
|
| }
|
|
|
| private:
|
| @@ -100,24 +80,6 @@ private:
|
| };
|
|
|
| template <typename T>
|
| -Iterator* MIDIPortMap<T>::keys()
|
| -{
|
| - return new MapIterator<KeySelector>(this, m_entries.begin(), m_entries.end());
|
| -}
|
| -
|
| -template <typename T>
|
| -Iterator* MIDIPortMap<T>::entries()
|
| -{
|
| - return new MapIterator<EntrySelector>(this, m_entries.begin(), m_entries.end());
|
| -}
|
| -
|
| -template <typename T>
|
| -Iterator* MIDIPortMap<T>::values()
|
| -{
|
| - return new MapIterator<ValueSelector>(this, m_entries.begin(), m_entries.end());
|
| -}
|
| -
|
| -template <typename T>
|
| T* MIDIPortMap<T>::get(const String& key) const
|
| {
|
| return has(key) ? m_entries.get(key) : 0;
|
|
|