| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 V8_UTIL_H_ | 5 #ifndef V8_UTIL_H_ |
| 6 #define V8_UTIL_H_ | 6 #define V8_UTIL_H_ |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 template <typename K, typename V> | 111 template <typename K, typename V> |
| 112 class DefaultGlobalMapTraits : public StdMapTraits<K, V> { | 112 class DefaultGlobalMapTraits : public StdMapTraits<K, V> { |
| 113 private: | 113 private: |
| 114 template <typename T> | 114 template <typename T> |
| 115 struct RemovePointer; | 115 struct RemovePointer; |
| 116 | 116 |
| 117 public: | 117 public: |
| 118 // Weak callback & friends: | 118 // Weak callback & friends: |
| 119 static const PersistentContainerCallbackType kCallbackType = kNotWeak; | 119 static const PersistentContainerCallbackType kCallbackType = kNotWeak; |
| 120 typedef PersistentValueMap<K, V, DefaultGlobalMapTraits<K, V> > MapType; | 120 typedef GlobalValueMap<K, V, DefaultGlobalMapTraits<K, V> > MapType; |
| 121 typedef void WeakCallbackInfoType; | 121 typedef void WeakCallbackDataType; |
| 122 | 122 |
| 123 static WeakCallbackInfoType* WeakCallbackParameter(MapType* map, const K& key, | 123 static WeakCallbackDataType* WeakCallbackParameter(MapType* map, const K& key, |
| 124 Local<V> value) { | 124 Local<V> value) { |
| 125 return nullptr; | 125 return nullptr; |
| 126 } | 126 } |
| 127 static MapType* MapFromWeakCallbackInfo( | 127 static MapType* MapFromWeakCallbackInfo( |
| 128 const WeakCallbackInfo<WeakCallbackInfoType>& data) { | 128 const WeakCallbackInfo<WeakCallbackDataType>& data) { |
| 129 return nullptr; | 129 return nullptr; |
| 130 } | 130 } |
| 131 static K KeyFromWeakCallbackInfo( | 131 static K KeyFromWeakCallbackInfo( |
| 132 const WeakCallbackInfo<WeakCallbackInfoType>& data) { | 132 const WeakCallbackInfo<WeakCallbackDataType>& data) { |
| 133 return K(); | 133 return K(); |
| 134 } | 134 } |
| 135 static void DisposeCallbackData(WeakCallbackInfoType* data) {} | 135 static void DisposeCallbackData(WeakCallbackDataType* data) {} |
| 136 static void Dispose(Isolate* isolate, Global<V> value, K key) {} | 136 static void Dispose(Isolate* isolate, Global<V> value, K key) {} |
| 137 // This is a second pass callback, so SetSecondPassCallback cannot be called. | 137 // This is a second pass callback, so SetSecondPassCallback cannot be called. |
| 138 static void DisposeWeak(const WeakCallbackInfo<WeakCallbackInfoType>& data) {} | 138 static void DisposeWeak(const WeakCallbackInfo<WeakCallbackDataType>& data) {} |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 template <typename T> | 141 template <typename T> |
| 142 struct RemovePointer<T*> { | 142 struct RemovePointer<T*> { |
| 143 typedef T Type; | 143 typedef T Type; |
| 144 }; | 144 }; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 | 147 |
| 148 /** | 148 /** |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 */ | 497 */ |
| 498 template<typename K, typename V, | 498 template<typename K, typename V, |
| 499 typename Traits = DefaultPersistentValueMapTraits<K, V> > | 499 typename Traits = DefaultPersistentValueMapTraits<K, V> > |
| 500 class StdPersistentValueMap : public PersistentValueMap<K, V, Traits> { | 500 class StdPersistentValueMap : public PersistentValueMap<K, V, Traits> { |
| 501 public: | 501 public: |
| 502 explicit StdPersistentValueMap(Isolate* isolate) | 502 explicit StdPersistentValueMap(Isolate* isolate) |
| 503 : PersistentValueMap<K, V, Traits>(isolate) {} | 503 : PersistentValueMap<K, V, Traits>(isolate) {} |
| 504 }; | 504 }; |
| 505 | 505 |
| 506 | 506 |
| 507 /** |
| 508 * A map that uses Global as value and std::map as the backing |
| 509 * implementation. Globals are held non-weak. |
| 510 * |
| 511 * C++11 embedders don't need this class, as they can use |
| 512 * Global directly in std containers. |
| 513 */ |
| 514 template <typename K, typename V, |
| 515 typename Traits = DefaultGlobalMapTraits<K, V> > |
| 516 class StdGlobalValueMap : public GlobalValueMap<K, V, Traits> { |
| 517 public: |
| 518 explicit StdGlobalValueMap(Isolate* isolate) |
| 519 : GlobalValueMap<K, V, Traits>(isolate) {} |
| 520 }; |
| 521 |
| 522 |
| 507 class DefaultPersistentValueVectorTraits { | 523 class DefaultPersistentValueVectorTraits { |
| 508 public: | 524 public: |
| 509 typedef std::vector<PersistentContainerValue> Impl; | 525 typedef std::vector<PersistentContainerValue> Impl; |
| 510 | 526 |
| 511 static void Append(Impl* impl, PersistentContainerValue value) { | 527 static void Append(Impl* impl, PersistentContainerValue value) { |
| 512 impl->push_back(value); | 528 impl->push_back(value); |
| 513 } | 529 } |
| 514 static bool IsEmpty(const Impl* impl) { | 530 static bool IsEmpty(const Impl* impl) { |
| 515 return impl->empty(); | 531 return impl->empty(); |
| 516 } | 532 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 return reinterpret_cast<V*>(v); | 631 return reinterpret_cast<V*>(v); |
| 616 } | 632 } |
| 617 | 633 |
| 618 Isolate* isolate_; | 634 Isolate* isolate_; |
| 619 typename Traits::Impl impl_; | 635 typename Traits::Impl impl_; |
| 620 }; | 636 }; |
| 621 | 637 |
| 622 } // namespace v8 | 638 } // namespace v8 |
| 623 | 639 |
| 624 #endif // V8_UTIL_H | 640 #endif // V8_UTIL_H |
| OLD | NEW |