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" | |
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.
| |
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); | |
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.
| |
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 |