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 Maplike_h | 5 #ifndef Maplike_h |
6 #define Maplike_h | 6 #define Maplike_h |
7 | 7 |
| 8 #include "bindings/core/v8/Iterable.h" |
8 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
9 #include "bindings/core/v8/ToV8.h" | 10 #include "bindings/core/v8/ToV8.h" |
10 #include "core/dom/Iterable.h" | |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 template <typename KeyType, typename ValueType> | 14 template <typename KeyType, typename ValueType> |
15 class Maplike : public PairIterable<KeyType, ValueType> { | 15 class Maplike : public PairIterable<KeyType, ValueType> { |
16 public: | 16 public: |
17 bool hasForBinding(ScriptState* scriptState, const KeyType& key, ExceptionSt
ate& exceptionState) | 17 bool hasForBinding(ScriptState* scriptState, const KeyType& key, ExceptionSt
ate& exceptionState) |
18 { | 18 { |
19 ValueType value; | 19 ValueType value; |
20 return getMapEntry(scriptState, key, value, exceptionState); | 20 return getMapEntry(scriptState, key, value, exceptionState); |
21 } | 21 } |
22 | 22 |
23 ScriptValue getForBinding(ScriptState* scriptState, const KeyType& key, Exce
ptionState& exceptionState) | 23 ScriptValue getForBinding(ScriptState* scriptState, const KeyType& key, Exce
ptionState& exceptionState) |
24 { | 24 { |
25 ValueType value; | 25 ValueType value; |
26 if (getMapEntry(scriptState, key, value, exceptionState)) | 26 if (getMapEntry(scriptState, key, value, exceptionState)) |
27 return ScriptValue(scriptState, toV8(value, scriptState->context()->
Global(), scriptState->isolate())); | 27 return ScriptValue(scriptState, toV8(value, scriptState->context()->
Global(), scriptState->isolate())); |
28 return ScriptValue(scriptState, v8::Undefined(scriptState->isolate())); | 28 return ScriptValue(scriptState, v8::Undefined(scriptState->isolate())); |
29 } | 29 } |
30 | 30 |
31 private: | 31 private: |
32 virtual bool getMapEntry(ScriptState*, const KeyType&, ValueType&, Exception
State&) = 0; | 32 virtual bool getMapEntry(ScriptState*, const KeyType&, ValueType&, Exception
State&) = 0; |
33 }; | 33 }; |
34 | 34 |
35 } // namespace blink | 35 } // namespace blink |
36 | 36 |
37 #endif // Maplike_h | 37 #endif // Maplike_h |
OLD | NEW |