| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef Iterable_h | 5 #ifndef Iterable_h |
| 6 #define Iterable_h | 6 #define Iterable_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8IteratorResultValue.h" | 8 #include "bindings/core/v8/V8IteratorResultValue.h" |
| 9 #include "bindings/core/v8/V8ScriptRunner.h" | 9 #include "bindings/core/v8/V8ScriptRunner.h" |
| 10 #include "core/dom/Iterator.h" | 10 #include "core/dom/Iterator.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 exceptionState.rethrowV8Exception(tryCatch.Exception()); | 81 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 class IterationSource : public GarbageCollectedFinalized<IterationSource> { | 87 class IterationSource : public GarbageCollectedFinalized<IterationSource> { |
| 88 public: | 88 public: |
| 89 virtual ~IterationSource() {} | 89 virtual ~IterationSource() {} |
| 90 | 90 |
| 91 // If end of iteration has been reached or an exception thrown: return false
. | 91 // If end of iteration has been reached or an exception thrown: return |
| 92 // Otherwise: set |key| and |value| and return true. | 92 // false. Otherwise: set |key| and |value| and return true. |
| 93 virtual bool next(ScriptState*, KeyType&, ValueType&, ExceptionState&) = 0; | 93 virtual bool next(ScriptState*, KeyType&, ValueType&, ExceptionState&) = 0; |
| 94 | 94 |
| 95 DEFINE_INLINE_VIRTUAL_TRACE() {} | 95 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 virtual IterationSource* startIteration(ScriptState*, ExceptionState&) = 0; | 99 virtual IterationSource* startIteration(ScriptState*, ExceptionState&) = 0; |
| 100 | 100 |
| 101 struct KeySelector { | 101 struct KeySelector { |
| 102 STATIC_ONLY(KeySelector); | 102 STATIC_ONLY(KeySelector); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 DEFINE_INLINE_VIRTUAL_TRACE() { | 157 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 158 visitor->trace(m_source); | 158 visitor->trace(m_source); |
| 159 Iterator::trace(visitor); | 159 Iterator::trace(visitor); |
| 160 } | 160 } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 Member<IterationSource> m_source; | 163 Member<IterationSource> m_source; |
| 164 }; | 164 }; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T>". | 167 // Utiltity mixin base-class for classes implementing IDL interfaces with |
| 168 // "iterable<T>". |
| 168 template <typename ValueType> | 169 template <typename ValueType> |
| 169 class ValueIterable : public Iterable<unsigned, ValueType> { | 170 class ValueIterable : public Iterable<unsigned, ValueType> { |
| 170 public: | 171 public: |
| 171 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) { | 172 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) { |
| 172 return this->valuesForBinding(scriptState, exceptionState); | 173 return this->valuesForBinding(scriptState, exceptionState); |
| 173 } | 174 } |
| 174 | 175 |
| 175 class IterationSource | 176 class IterationSource |
| 176 : public Iterable<unsigned, ValueType>::IterationSource { | 177 : public Iterable<unsigned, ValueType>::IterationSource { |
| 177 public: | 178 public: |
| 178 IterationSource() : m_index(0) {} | 179 IterationSource() : m_index(0) {} |
| 179 | 180 |
| 180 ~IterationSource() override {} | 181 ~IterationSource() override {} |
| 181 | 182 |
| 182 // If end of iteration has been reached or an exception thrown: return false
. | 183 // If end of iteration has been reached or an exception thrown: return |
| 184 // false. |
| 183 // Otherwise: set |value| and return true. | 185 // Otherwise: set |value| and return true. |
| 184 // Note: |this->m_index| is the index being accessed. | 186 // Note: |this->m_index| is the index being accessed. |
| 185 virtual bool next(ScriptState*, ValueType&, ExceptionState&) = 0; | 187 virtual bool next(ScriptState*, ValueType&, ExceptionState&) = 0; |
| 186 | 188 |
| 187 protected: | 189 protected: |
| 188 unsigned m_index; | 190 unsigned m_index; |
| 189 | 191 |
| 190 private: | 192 private: |
| 191 bool next(ScriptState* scriptState, | 193 bool next(ScriptState* scriptState, |
| 192 unsigned& key, | 194 unsigned& key, |
| 193 ValueType& value, | 195 ValueType& value, |
| 194 ExceptionState& exceptionState) final { | 196 ExceptionState& exceptionState) final { |
| 195 if (!next(scriptState, value, exceptionState)) | 197 if (!next(scriptState, value, exceptionState)) |
| 196 return false; | 198 return false; |
| 197 key = m_index; | 199 key = m_index; |
| 198 ++m_index; | 200 ++m_index; |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 }; | 203 }; |
| 202 }; | 204 }; |
| 203 | 205 |
| 204 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T1, T2>". | 206 // Utiltity mixin base-class for classes implementing IDL interfaces with |
| 207 // "iterable<T1, T2>". |
| 205 template <typename KeyType, typename ValueType> | 208 template <typename KeyType, typename ValueType> |
| 206 class PairIterable : public Iterable<KeyType, ValueType> { | 209 class PairIterable : public Iterable<KeyType, ValueType> { |
| 207 public: | 210 public: |
| 208 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) { | 211 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) { |
| 209 return this->entriesForBinding(scriptState, exceptionState); | 212 return this->entriesForBinding(scriptState, exceptionState); |
| 210 } | 213 } |
| 211 }; | 214 }; |
| 212 | 215 |
| 213 } // namespace blink | 216 } // namespace blink |
| 214 | 217 |
| 215 #endif // Iterable_h | 218 #endif // Iterable_h |
| OLD | NEW |