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