OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8GlobalValueMap_h | 5 #ifndef V8GlobalValueMap_h |
6 #define V8GlobalValueMap_h | 6 #define V8GlobalValueMap_h |
7 | 7 |
8 #include "platform/wtf/Allocator.h" | 8 #include "platform/wtf/Allocator.h" |
9 #include "platform/wtf/HashMap.h" | 9 #include "platform/wtf/HashMap.h" |
10 #include "platform/wtf/text/StringHash.h" | 10 #include "platform/wtf/text/StringHash.h" |
11 #include "v8-util.h" | 11 #include "v8-util.h" |
12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 /** | 16 /** |
17 * A Traits class for v8::GlobalValueMap that uses wtf/HashMap as a | 17 * A Traits class for v8::GlobalValueMap that uses wtf/HashMap as a |
18 * backing store. | 18 * backing store. |
19 * | 19 * |
20 * The parameter is_weak will determine whether the references are 'weak'. | 20 * The parameter is_weak will determine whether the references are 'weak'. |
21 * If so, entries will be removed from the map as the weak references are | 21 * If so, entries will be removed from the map as the weak references are |
22 * collected. | 22 * collected. |
23 */ | 23 */ |
24 template <class KeyType, | 24 template <typename KeyType, |
25 class ValueType, | 25 typename ValueType, |
26 v8::PersistentContainerCallbackType type> | 26 v8::PersistentContainerCallbackType type> |
27 class V8GlobalValueMapTraits { | 27 class V8GlobalValueMapTraits { |
28 STATIC_ONLY(V8GlobalValueMapTraits); | 28 STATIC_ONLY(V8GlobalValueMapTraits); |
29 | 29 |
30 public: | 30 public: |
31 // Map traits: | 31 // Map traits: |
32 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl; | 32 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl; |
33 typedef typename Impl::iterator Iterator; | 33 typedef typename Impl::iterator Iterator; |
34 static size_t Size(const Impl* impl) { return impl->size(); } | 34 static size_t Size(const Impl* impl) { return impl->size(); } |
35 static bool Empty(Impl* impl) { return impl->IsEmpty(); } | 35 static bool Empty(Impl* impl) { return impl->IsEmpty(); } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 v8::Global<ValueType> value, | 91 v8::Global<ValueType> value, |
92 KeyType key) {} | 92 KeyType key) {} |
93 static void DisposeWeak( | 93 static void DisposeWeak( |
94 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} | 94 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} |
95 }; | 95 }; |
96 | 96 |
97 /** | 97 /** |
98 * A map for safely storing persistent V8 values, based on | 98 * A map for safely storing persistent V8 values, based on |
99 * v8::GlobalValueMap. | 99 * v8::GlobalValueMap. |
100 */ | 100 */ |
101 template <class KeyType, | 101 template <typename KeyType, |
102 class ValueType, | 102 typename ValueType, |
103 v8::PersistentContainerCallbackType type> | 103 v8::PersistentContainerCallbackType type> |
104 class V8GlobalValueMap : public v8::GlobalValueMap< | 104 class V8GlobalValueMap : public v8::GlobalValueMap< |
105 KeyType, | 105 KeyType, |
106 ValueType, | 106 ValueType, |
107 V8GlobalValueMapTraits<KeyType, ValueType, type>> { | 107 V8GlobalValueMapTraits<KeyType, ValueType, type>> { |
108 DISALLOW_NEW(); | 108 DISALLOW_NEW(); |
109 | 109 |
110 public: | 110 public: |
111 typedef V8GlobalValueMapTraits<KeyType, ValueType, type> Traits; | 111 typedef V8GlobalValueMapTraits<KeyType, ValueType, type> Traits; |
112 explicit V8GlobalValueMap(v8::Isolate* isolate) | 112 explicit V8GlobalValueMap(v8::Isolate* isolate) |
113 : v8::GlobalValueMap<KeyType, ValueType, Traits>(isolate) {} | 113 : v8::GlobalValueMap<KeyType, ValueType, Traits>(isolate) {} |
114 }; | 114 }; |
115 | 115 |
116 } // namespace blink | 116 } // namespace blink |
117 | 117 |
118 #endif // V8GlobalValueMap_h | 118 #endif // V8GlobalValueMap_h |
OLD | NEW |