Index: Source/core/dom/Maplike.h |
diff --git a/Source/core/dom/Maplike.h b/Source/core/dom/Maplike.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8d001413df1e6dd90af5108fcc3fd97272873856 |
--- /dev/null |
+++ b/Source/core/dom/Maplike.h |
@@ -0,0 +1,37 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef Maplike_h |
+#define Maplike_h |
+ |
+#include "bindings/core/v8/ScriptValue.h" |
+#include "bindings/core/v8/ToV8.h" |
+#include "core/dom/Iterable.h" |
+ |
+namespace blink { |
+ |
+template <typename KeyType, typename ValueType> |
+class Maplike : public PairIterable<KeyType, ValueType> { |
+public: |
+ bool hasForBinding(ScriptState* scriptState, const KeyType& key, ExceptionState& exceptionState) |
+ { |
+ ValueType value; |
+ return getMapEntry(scriptState, key, value, exceptionState); |
+ } |
+ |
+ ScriptValue getForBinding(ScriptState* scriptState, const KeyType& key, ExceptionState& exceptionState) |
+ { |
+ ValueType value; |
+ if (getMapEntry(scriptState, key, value, exceptionState)) |
+ return ScriptValue(scriptState, toV8(value, scriptState->context()->Global(), scriptState->isolate())); |
+ return ScriptValue(scriptState, v8::Undefined(scriptState->isolate())); |
+ } |
+ |
+private: |
+ virtual bool getMapEntry(ScriptState*, const KeyType&, ValueType&, ExceptionState&) = 0; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // Maplike_h |