| 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 "wtf/Allocator.h" |
| 8 #include "wtf/HashMap.h" | 9 #include "wtf/HashMap.h" |
| 9 #include "wtf/text/StringHash.h" | 10 #include "wtf/text/StringHash.h" |
| 10 #include <v8-util.h> | 11 #include <v8-util.h> |
| 11 #include <v8.h> | 12 #include <v8.h> |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * 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 |
| 17 * backing store. | 18 * backing store. |
| 18 * | 19 * |
| 19 * The parameter is_weak will determine whether the references are 'weak'. | 20 * The parameter is_weak will determine whether the references are 'weak'. |
| 20 * 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 |
| 21 * collected. | 22 * collected. |
| 22 */ | 23 */ |
| 23 template <class KeyType, class ValueType, v8::PersistentContainerCallbackType ty
pe> | 24 template <class KeyType, class ValueType, v8::PersistentContainerCallbackType ty
pe> |
| 24 class V8GlobalValueMapTraits { | 25 class V8GlobalValueMapTraits { |
| 26 STATIC_ONLY(V8GlobalValueMapTraits); |
| 25 public: | 27 public: |
| 26 // Map traits: | 28 // Map traits: |
| 27 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl; | 29 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl; |
| 28 typedef typename Impl::iterator Iterator; | 30 typedef typename Impl::iterator Iterator; |
| 29 static size_t Size(const Impl* impl) { return impl->size(); } | 31 static size_t Size(const Impl* impl) { return impl->size(); } |
| 30 static bool Empty(Impl* impl) { return impl->isEmpty(); } | 32 static bool Empty(Impl* impl) { return impl->isEmpty(); } |
| 31 static void Swap(Impl& impl, Impl& other) { impl.swap(other); } | 33 static void Swap(Impl& impl, Impl& other) { impl.swap(other); } |
| 32 static Iterator Begin(Impl* impl) { return impl->begin(); } | 34 static Iterator Begin(Impl* impl) { return impl->begin(); } |
| 33 static Iterator End(Impl* impl) { return impl->end(); } | 35 static Iterator End(Impl* impl) { return impl->end(); } |
| 34 static v8::PersistentContainerValue Value(Iterator& iter) | 36 static v8::PersistentContainerValue Value(Iterator& iter) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 static void Dispose(v8::Isolate* isolate, v8::Global<ValueType> value, KeyTy
pe key) { } | 88 static void Dispose(v8::Isolate* isolate, v8::Global<ValueType> value, KeyTy
pe key) { } |
| 87 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>& da
ta) { } | 89 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>& da
ta) { } |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 /** | 92 /** |
| 91 * A map for safely storing persistent V8 values, based on | 93 * A map for safely storing persistent V8 values, based on |
| 92 * v8::GlobalValueMap. | 94 * v8::GlobalValueMap. |
| 93 */ | 95 */ |
| 94 template <class KeyType, class ValueType, v8::PersistentContainerCallbackType ty
pe> | 96 template <class KeyType, class ValueType, v8::PersistentContainerCallbackType ty
pe> |
| 95 class V8GlobalValueMap : public v8::GlobalValueMap<KeyType, ValueType, V8GlobalV
alueMapTraits<KeyType, ValueType, type>> { | 97 class V8GlobalValueMap : public v8::GlobalValueMap<KeyType, ValueType, V8GlobalV
alueMapTraits<KeyType, ValueType, type>> { |
| 98 DISALLOW_ALLOCATION(); |
| 96 public: | 99 public: |
| 97 typedef V8GlobalValueMapTraits<KeyType, ValueType, type> Traits; | 100 typedef V8GlobalValueMapTraits<KeyType, ValueType, type> Traits; |
| 98 explicit V8GlobalValueMap(v8::Isolate* isolate) | 101 explicit V8GlobalValueMap(v8::Isolate* isolate) |
| 99 : v8::GlobalValueMap<KeyType, ValueType, Traits>(isolate) | 102 : v8::GlobalValueMap<KeyType, ValueType, Traits>(isolate) |
| 100 { | 103 { |
| 101 } | 104 } |
| 102 }; | 105 }; |
| 103 | 106 |
| 104 } // namespace blink | 107 } // namespace blink |
| 105 | 108 |
| 106 #endif // V8GlobalValueMap_h | 109 #endif // V8GlobalValueMap_h |
| OLD | NEW |