| 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 // This file has been moved to platform/bindings/V8GlobalValueMap.h. |
| 6 #define V8GlobalValueMap_h | 6 // TODO(adithyas): Remove this file. |
| 7 | 7 #include "platform/bindings/V8GlobalValueMap.h" |
| 8 #include "platform/wtf/Allocator.h" | |
| 9 #include "platform/wtf/HashMap.h" | |
| 10 #include "platform/wtf/text/StringHash.h" | |
| 11 #include "v8-util.h" | |
| 12 #include "v8/include/v8.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 /** | |
| 17 * A Traits class for v8::GlobalValueMap that uses wtf/HashMap as a | |
| 18 * backing store. | |
| 19 * | |
| 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 | |
| 22 * collected. | |
| 23 */ | |
| 24 template <class KeyType, | |
| 25 class ValueType, | |
| 26 v8::PersistentContainerCallbackType type> | |
| 27 class V8GlobalValueMapTraits { | |
| 28 STATIC_ONLY(V8GlobalValueMapTraits); | |
| 29 | |
| 30 public: | |
| 31 // Map traits: | |
| 32 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl; | |
| 33 typedef typename Impl::iterator Iterator; | |
| 34 static size_t Size(const Impl* impl) { return impl->size(); } | |
| 35 static bool Empty(Impl* impl) { return impl->IsEmpty(); } | |
| 36 static void Swap(Impl& impl, Impl& other) { impl.swap(other); } | |
| 37 static Iterator Begin(Impl* impl) { return impl->begin(); } | |
| 38 static Iterator End(Impl* impl) { return impl->end(); } | |
| 39 static v8::PersistentContainerValue Value(Iterator& iter) { | |
| 40 return iter->value; | |
| 41 } | |
| 42 static KeyType Key(Iterator& iter) { return iter->key; } | |
| 43 static v8::PersistentContainerValue Set(Impl* impl, | |
| 44 KeyType key, | |
| 45 v8::PersistentContainerValue value) { | |
| 46 v8::PersistentContainerValue old_value = Get(impl, key); | |
| 47 impl->Set(key, value); | |
| 48 return old_value; | |
| 49 } | |
| 50 static v8::PersistentContainerValue Get(const Impl* impl, KeyType key) { | |
| 51 return impl->at(key); | |
| 52 } | |
| 53 | |
| 54 static v8::PersistentContainerValue Remove(Impl* impl, KeyType key) { | |
| 55 return impl->Take(key); | |
| 56 } | |
| 57 | |
| 58 // Weak traits: | |
| 59 static const v8::PersistentContainerCallbackType kCallbackType = type; | |
| 60 typedef v8::GlobalValueMap<KeyType, | |
| 61 ValueType, | |
| 62 V8GlobalValueMapTraits<KeyType, ValueType, type>> | |
| 63 MapType; | |
| 64 | |
| 65 typedef void WeakCallbackDataType; | |
| 66 | |
| 67 static WeakCallbackDataType* WeakCallbackParameter( | |
| 68 MapType* map, | |
| 69 KeyType key, | |
| 70 const v8::Local<ValueType>& value) { | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 static void DisposeCallbackData(WeakCallbackDataType* callback_data) {} | |
| 75 | |
| 76 static MapType* MapFromWeakCallbackInfo( | |
| 77 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) { | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 static KeyType KeyFromWeakCallbackInfo( | |
| 82 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) { | |
| 83 return KeyType(); | |
| 84 } | |
| 85 | |
| 86 static void OnWeakCallback( | |
| 87 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} | |
| 88 | |
| 89 // Dispose traits: | |
| 90 static void Dispose(v8::Isolate* isolate, | |
| 91 v8::Global<ValueType> value, | |
| 92 KeyType key) {} | |
| 93 static void DisposeWeak( | |
| 94 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} | |
| 95 }; | |
| 96 | |
| 97 /** | |
| 98 * A map for safely storing persistent V8 values, based on | |
| 99 * v8::GlobalValueMap. | |
| 100 */ | |
| 101 template <class KeyType, | |
| 102 class ValueType, | |
| 103 v8::PersistentContainerCallbackType type> | |
| 104 class V8GlobalValueMap : public v8::GlobalValueMap< | |
| 105 KeyType, | |
| 106 ValueType, | |
| 107 V8GlobalValueMapTraits<KeyType, ValueType, type>> { | |
| 108 DISALLOW_NEW(); | |
| 109 | |
| 110 public: | |
| 111 typedef V8GlobalValueMapTraits<KeyType, ValueType, type> Traits; | |
| 112 explicit V8GlobalValueMap(v8::Isolate* isolate) | |
| 113 : v8::GlobalValueMap<KeyType, ValueType, Traits>(isolate) {} | |
| 114 }; | |
| 115 | |
| 116 } // namespace blink | |
| 117 | |
| 118 #endif // V8GlobalValueMap_h | |
| OLD | NEW |