Chromium Code Reviews| 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" |
|
haraken
2015/02/12 13:41:36
Nit: Would core/dom/ be a right place for Iterable
Jens Widell
2015/02/12 13:50:47
I don't know. Maybe bindings/core/v8/ makes more s
haraken
2015/02/12 13:56:50
Either way let's consider in a separate CL.
|
| + |
| +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); |
|
haraken
2015/02/12 13:39:39
It's a bit inefficient to call getMapEntry() to im
Jens Widell
2015/02/12 13:50:48
It's not a lot inefficient though in most cases. I
haraken
2015/02/12 13:56:50
Sounds reasonable.
|
| + } |
| + |
| + 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 |