Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Unified Diff: Source/core/dom/Maplike.h

Issue 920713002: Add Maplike<> utility mixin class for implementing maplike interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-iterable-etc-typedefs
Patch Set: drop some includes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/modules/encryptedmedia/MediaKeyStatusMap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | Source/modules/encryptedmedia/MediaKeyStatusMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698