25template <
typename K,
typename V,
typename Traits>
29static const uintptr_t kPersistentContainerNotFound = 0;
43template<
typename K,
typename V>
47 typedef std::map<K, PersistentContainerValue>
Impl;
50 static bool Empty(
Impl* impl) {
return impl->empty(); }
51 static size_t Size(
Impl* impl) {
return impl->size(); }
59 std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value));
62 old_value = res.first->second;
63 res.first->second = value;
69 if (it == impl->end())
return kPersistentContainerNotFound;
74 if (it == impl->end())
return kPersistentContainerNotFound;
90template<
typename K,
typename V>
116template <
typename K,
typename V>
119 template <
typename T>
120 struct RemovePointer;
148 template <
typename T>
149 struct RemovePointer<T*> {
165template <
typename K,
typename V,
typename Traits>
173 size_t Size() {
return Traits::Size(&impl_); }
184 V* p =
FromVal(Traits::Get(&impl_, key));
185#ifdef V8_ENABLE_DIRECT_HANDLE
186 if (p ==
nullptr)
return Local<V>();
195 return Traits::Get(&impl_, key) != kPersistentContainerNotFound;
204 return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key));
211 return Release(Traits::Remove(&impl_, key)).Pass();
219 typedef typename Traits::Iterator It;
222 while (!Traits::Empty(&impl_)) {
223 typename Traits::Impl
impl;
224 Traits::Swap(impl_,
impl);
225 for (It i = Traits::Begin(&
impl); i != Traits::End(&
impl); ++i) {
226 Traits::Dispose(isolate_,
Release(Traits::Value(i)).Pass(),
240 : value_(other.value_) { }
248 return value_ == kPersistentContainerNotFound;
252 return SetReturnValueFromVal(&returnValue, value_);
255 value_ = kPersistentContainerNotFound;
258 value_ = other.value_;
287 return PersistentValueReference(Traits::Get(&impl_, key));
292 : isolate_(
isolate), label_(nullptr) {}
294 : isolate_(
isolate), label_(label) {}
299 typename Traits::Impl*
impl() {
return &impl_; }
325 Traits::DisposeCallbackData(
326 p.template ClearWeak<typename Traits::WeakCallbackDataType>());
348 bool hasValue = value != kPersistentContainerNotFound;
356 typename Traits::Impl impl_;
360template <
typename K,
typename V,
typename Traits>
394 if (Traits::kCallbackType ==
kNotWeak) {
402 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
403 Traits::WeakCallbackParameter(
this, key, value), WeakCallback,
408 return this->
Release(old_value).Pass();
417 *reference = this->
Leak(&value);
422 static void WeakCallback(
424 if (Traits::kCallbackType !=
kNotWeak) {
426 Traits::MapFromWeakCallbackInfo(data);
427 K key = Traits::KeyFromWeakCallbackInfo(data);
429 persistentValueMap->
Remove(key).Pass(), key);
436template <
typename K,
typename V,
typename Traits>
470 if (Traits::kCallbackType ==
kNotWeak) {
478 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
479 Traits::WeakCallbackParameter(
this, key, value), OnWeakCallback,
484 return this->
Release(old_value).Pass();
493 *reference = this->
Leak(&value);
498 static void OnWeakCallback(
500 if (Traits::kCallbackType !=
kNotWeak) {
501 auto map = Traits::MapFromWeakCallbackInfo(data);
502 K key = Traits::KeyFromWeakCallbackInfo(data);
503 map->RemoveWeak(key);
504 Traits::OnWeakCallback(data);
509 static void SecondWeakCallback(
510 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) {
511 Traits::DisposeWeak(data);
523template<
typename K,
typename V,
539template <
typename K,
typename V,
540 typename Traits = DefaultGlobalMapTraits<K, V> >
static const PersistentContainerCallbackType kCallbackType
static void Dispose(Isolate *isolate, Global< V > value, K key)
static void DisposeWeak(const WeakCallbackInfo< WeakCallbackDataType > &data)
void WeakCallbackDataType
static void OnWeakCallback(const WeakCallbackInfo< WeakCallbackDataType > &data)
GlobalValueMap< K, V, DefaultGlobalMapTraits< K, V > > MapType
static void DisposeCallbackData(WeakCallbackDataType *data)
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
static const PersistentContainerCallbackType kCallbackType
static void Dispose(Isolate *isolate, Global< V > value, K key)
PersistentValueMap< K, V, DefaultPersistentValueMapTraits< K, V > > MapType
void WeakCallbackDataType
static void DisposeCallbackData(WeakCallbackDataType *data)
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
GlobalValueMap(Isolate *isolate)
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
Global< V > Set(const K &key, Local< V > value)
GlobalValueMap(Isolate *isolate, const char *label)
Global< V > Set(const K &key, Global< V > value)
PersistentValueMapBase< K, V, DefaultGlobalMapTraits< K, V > >::PersistentValueReference PersistentValueReference
Global< V > SetUnique(const K &key, Global< V > *persistent)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
V8_INLINE bool IsWeak() const
V8_INLINE void AnnotateStrongRetainer(const char *label)
Local< V > NewLocal(Isolate *isolate) const
bool SetReturnValue(ReturnValue< T > returnValue)
void operator=(const PersistentValueReference &other)
PersistentValueReference(const PersistentValueReference &other)
friend class PersistentValueMapBase
PersistentValueReference()
static Global< V > Release(PersistentContainerValue v)
static PersistentContainerValue Leak(Global< V > *persistent)
~PersistentValueMapBase()
Global< V > Remove(const K &key)
PersistentValueMapBase(Isolate *isolate, const char *label)
bool SetReturnValue(const K &key, ReturnValue< Value > returnValue)
void RemoveWeak(const K &key)
static V * FromVal(PersistentContainerValue v)
PersistentValueReference GetReference(const K &key)
bool Contains(const K &key)
static PersistentContainerValue ClearAndLeak(Global< V > *persistent)
PersistentValueMapBase(Isolate *isolate)
void AnnotateStrongRetainer(Global< V > *persistent)
Local< V > Get(const K &key)
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
Global< V > Set(const K &key, Local< V > value)
PersistentValueMap(Isolate *isolate, const char *label)
PersistentValueMap(Isolate *isolate)
Global< V > Set(const K &key, Global< V > value)
PersistentValueMapBase< K, V, DefaultPersistentValueMapTraits< K, V > >::PersistentValueReference PersistentValueReference
Global< V > SetUnique(const K &key, Global< V > *persistent)
StdGlobalValueMap(Isolate *isolate)
static PersistentContainerValue Set(Impl *impl, K key, PersistentContainerValue value)
static Iterator End(Impl *impl)
static PersistentContainerValue Value(Iterator it)
static void Swap(Impl &a, Impl &b)
static K Key(Iterator it)
static PersistentContainerValue Remove(Impl *impl, K key)
static PersistentContainerValue Get(Impl *impl, K key)
static size_t Size(Impl *impl)
static bool Empty(Impl *impl)
std::map< K, PersistentContainerValue > Impl
static Iterator Begin(Impl *impl)
StdPersistentValueMap(Isolate *isolate)
V8_INLINE T * GetParameter() const
void SetSecondPassCallback(Callback callback) const
V8_INLINE Isolate * GetIsolate() const
V8_INLINE internal::Address *const & slot() const
static V8_INLINE T * SlotAsValue(S *slot)
PersistentContainerCallbackType
@ kWeakWithInternalFields
uintptr_t PersistentContainerValue