| 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" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 // Typically, use one of ValueIterable<> and PairIterable<> (below) instead! | 14 // Typically, use one of ValueIterable<> and PairIterable<> (below) instead! |
| 15 template <typename KeyType, typename ValueType> | 15 template <typename KeyType, typename ValueType> |
| 16 class Iterable { | 16 class Iterable { |
| 17 public: | 17 public: |
| 18 Iterator* keys(ScriptState* scriptState, ExceptionState& exceptionState) | 18 Iterator* keysForBinding(ScriptState* scriptState, ExceptionState& exception
State) |
| 19 { | 19 { |
| 20 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); | 20 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); |
| 21 if (!source) | 21 if (!source) |
| 22 return nullptr; | 22 return nullptr; |
| 23 return new IterableIterator<KeySelector>(source); | 23 return new IterableIterator<KeySelector>(source); |
| 24 } | 24 } |
| 25 | 25 |
| 26 Iterator* values(ScriptState* scriptState, ExceptionState& exceptionState) | 26 Iterator* valuesForBinding(ScriptState* scriptState, ExceptionState& excepti
onState) |
| 27 { | 27 { |
| 28 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); | 28 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); |
| 29 if (!source) | 29 if (!source) |
| 30 return nullptr; | 30 return nullptr; |
| 31 return new IterableIterator<ValueSelector>(source); | 31 return new IterableIterator<ValueSelector>(source); |
| 32 } | 32 } |
| 33 | 33 |
| 34 Iterator* entries(ScriptState* scriptState, ExceptionState& exceptionState) | 34 Iterator* entriesForBinding(ScriptState* scriptState, ExceptionState& except
ionState) |
| 35 { | 35 { |
| 36 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); | 36 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); |
| 37 if (!source) | 37 if (!source) |
| 38 return nullptr; | 38 return nullptr; |
| 39 return new IterableIterator<EntrySelector>(source); | 39 return new IterableIterator<EntrySelector>(source); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void forEach(ScriptState* scriptState, const ScriptValue& thisValue, const S
criptValue& callback, const ScriptValue& thisArg, ExceptionState& exceptionState
) | 42 void forEachForBinding(ScriptState* scriptState, const ScriptValue& thisValu
e, const ScriptValue& callback, const ScriptValue& thisArg, ExceptionState& exce
ptionState) |
| 43 { | 43 { |
| 44 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); | 44 IterationSource* source = this->startIteration(scriptState, exceptionSta
te); |
| 45 | 45 |
| 46 v8::Isolate* isolate = scriptState->isolate(); | 46 v8::Isolate* isolate = scriptState->isolate(); |
| 47 v8::TryCatch tryCatch(isolate); | 47 v8::TryCatch tryCatch(isolate); |
| 48 | 48 |
| 49 v8::Local<v8::Object> creationContext(scriptState->context()->Global()); | 49 v8::Local<v8::Object> creationContext(scriptState->context()->Global()); |
| 50 v8::Local<v8::Function> v8Callback(callback.v8Value().As<v8::Function>()
); | 50 v8::Local<v8::Function> v8Callback(callback.v8Value().As<v8::Function>()
); |
| 51 v8::Local<v8::Value> v8ThisArg(thisArg.v8Value()); | 51 v8::Local<v8::Value> v8ThisArg(thisArg.v8Value()); |
| 52 v8::Local<v8::Value> args[3]; | 52 v8::Local<v8::Value> args[3]; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 Member<IterationSource> m_source; | 147 Member<IterationSource> m_source; |
| 148 }; | 148 }; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T>". | 151 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T>". |
| 152 template <typename ValueType> | 152 template <typename ValueType> |
| 153 class ValueIterable : public Iterable<unsigned, ValueType> { | 153 class ValueIterable : public Iterable<unsigned, ValueType> { |
| 154 public: | 154 public: |
| 155 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) | 155 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) |
| 156 { | 156 { |
| 157 return this->values(scriptState, exceptionState); | 157 return this->valuesForBinding(scriptState, exceptionState); |
| 158 } | 158 } |
| 159 | 159 |
| 160 class IterationSource : public Iterable<unsigned, ValueType>::IterationSourc
e { | 160 class IterationSource : public Iterable<unsigned, ValueType>::IterationSourc
e { |
| 161 public: | 161 public: |
| 162 IterationSource() | 162 IterationSource() |
| 163 : m_index(0) | 163 : m_index(0) |
| 164 { | 164 { |
| 165 } | 165 } |
| 166 | 166 |
| 167 ~IterationSource() override { } | 167 ~IterationSource() override { } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 } | 185 } |
| 186 }; | 186 }; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T1, T2>". | 189 // Utiltity mixin base-class for classes implementing IDL interfaces with "itera
ble<T1, T2>". |
| 190 template <typename KeyType, typename ValueType> | 190 template <typename KeyType, typename ValueType> |
| 191 class PairIterable : public Iterable<KeyType, ValueType> { | 191 class PairIterable : public Iterable<KeyType, ValueType> { |
| 192 public: | 192 public: |
| 193 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) | 193 Iterator* iterator(ScriptState* scriptState, ExceptionState& exceptionState) |
| 194 { | 194 { |
| 195 return this->entries(scriptState, exceptionState); | 195 return this->entriesForBinding(scriptState, exceptionState); |
| 196 } | 196 } |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 } // namespace blink | 199 } // namespace blink |
| 200 | 200 |
| 201 #endif // Iterable_h | 201 #endif // Iterable_h |
| OLD | NEW |