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_) { }
244 internal::ValueHelper::SlotAsValue<V>(
248 return value_ == kPersistentContainerNotFound;
252 return SetReturnValueFromVal(&returnValue, value_);
255 value_ = kPersistentContainerNotFound;
258 value_ = other.value_;
292 : isolate_(
isolate), label_(nullptr) {}
294 : isolate_(
isolate), label_(label) {}
299 typename Traits::Impl*
impl() {
return &impl_; }
302 return internal::ValueHelper::SlotAsValue<V>(
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,
524 typename Traits = DefaultPersistentValueMapTraits<K, V> >
539template <
typename K,
typename V,
540 typename Traits = DefaultGlobalMapTraits<K, V> >
Definition: v8-util.h:117
static void DisposeCallbackData(WeakCallbackDataType *data)
Definition: v8-util.h:140
static void OnWeakCallback(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:141
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:136
GlobalValueMap< K, V, DefaultGlobalMapTraits< K, V > > MapType
Definition: v8-util.h:125
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:132
static const PersistentContainerCallbackType kCallbackType
Definition: v8-util.h:124
static void DisposeWeak(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:145
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
Definition: v8-util.h:128
static void Dispose(Isolate *isolate, Global< V > value, K key)
Definition: v8-util.h:143
void WeakCallbackDataType
Definition: v8-util.h:126
PersistentValueMap< K, V, DefaultPersistentValueMapTraits< K, V > > MapType
Definition: v8-util.h:96
static const PersistentContainerCallbackType kCallbackType
Definition: v8-util.h:94
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
Definition: v8-util.h:99
static void Dispose(Isolate *isolate, Global< V > value, K key)
Definition: v8-util.h:112
void WeakCallbackDataType
Definition: v8-util.h:97
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:107
static void DisposeCallbackData(WeakCallbackDataType *data)
Definition: v8-util.h:111
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
Definition: v8-util.h:103
Definition: v8-util.h:437
Global< V > Set(const K &key, Local< V > value)
Definition: v8-util.h:453
GlobalValueMap(Isolate *isolate, const char *label)
Definition: v8-util.h:441
Global< V > Set(const K &key, Global< V > value)
Definition: v8-util.h:461
Global< V > SetUnique(const K &key, Global< V > *persistent)
Definition: v8-util.h:469
GlobalValueMap(Isolate *isolate)
Definition: v8-util.h:439
PersistentValueMapBase< K, V, Traits >::PersistentValueReference PersistentValueReference
Definition: v8-util.h:446
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
Definition: v8-util.h:491
Definition: v8-persistent-handle.h:347
Global Pass()
Definition: v8-persistent-handle.h:394
Definition: v8-local-handle.h:97
Definition: v8-isolate.h:261
Definition: v8-local-handle.h:266
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:346
void Reset()
Definition: v8-persistent-handle.h:449
void AnnotateStrongRetainer(const char *label)
Definition: v8-persistent-handle.h:511
bool IsWeak() const
Definition: v8-persistent-handle.h:442
Definition: v8-util.h:236
bool SetReturnValue(ReturnValue< T > returnValue)
Definition: v8-util.h:251
PersistentValueReference(const PersistentValueReference &other)
Definition: v8-util.h:239
bool IsEmpty() const
Definition: v8-util.h:247
void Reset()
Definition: v8-util.h:254
Local< V > NewLocal(Isolate *isolate) const
Definition: v8-util.h:242
PersistentValueReference()
Definition: v8-util.h:238
void operator=(const PersistentValueReference &other)
Definition: v8-util.h:257
Definition: v8-util.h:166
Traits::Impl * impl()
Definition: v8-util.h:299
PersistentValueMapBase(Isolate *isolate)
Definition: v8-util.h:291
void Clear()
Definition: v8-util.h:218
PersistentValueMapBase(Isolate *isolate, const char *label)
Definition: v8-util.h:293
void AnnotateStrongRetainer(Global< V > *persistent)
Definition: v8-util.h:338
PersistentValueReference GetReference(const K &key)
Definition: v8-util.h:286
~PersistentValueMapBase()
Definition: v8-util.h:296
Local< V > Get(const K &key)
Definition: v8-util.h:183
void RemoveWeak(const K &key)
Definition: v8-util.h:331
static PersistentContainerValue ClearAndLeak(Global< V > *persistent)
Definition: v8-util.h:306
bool SetReturnValue(const K &key, ReturnValue< Value > returnValue)
Definition: v8-util.h:202
bool Contains(const K &key)
Definition: v8-util.h:194
bool IsWeak()
Definition: v8-util.h:178
static V * FromVal(PersistentContainerValue v)
Definition: v8-util.h:301
Isolate * isolate()
Definition: v8-util.h:298
Isolate * GetIsolate()
Definition: v8-util.h:168
static PersistentContainerValue Leak(Global< V > *persistent)
Definition: v8-util.h:312
size_t Size()
Definition: v8-util.h:173
static Global< V > Release(PersistentContainerValue v)
Definition: v8-util.h:321
Global< V > Remove(const K &key)
Definition: v8-util.h:210
Definition: v8-util.h:361
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
Definition: v8-util.h:415
Global< V > Set(const K &key, Global< V > value)
Definition: v8-util.h:385
Global< V > SetUnique(const K &key, Global< V > *persistent)
Definition: v8-util.h:393
Global< V > Set(const K &key, Local< V > value)
Definition: v8-util.h:377
PersistentValueMapBase< K, V, Traits >::PersistentValueReference PersistentValueReference
Definition: v8-util.h:370
PersistentValueMap(Isolate *isolate)
Definition: v8-util.h:363
PersistentValueMap(Isolate *isolate, const char *label)
Definition: v8-util.h:365
Definition: v8-function-callback.h:41
Definition: v8-util.h:541
StdGlobalValueMap(Isolate *isolate)
Definition: v8-util.h:543
static PersistentContainerValue Set(Impl *impl, K key, PersistentContainerValue value)
Definition: v8-util.h:57
static Iterator End(Impl *impl)
Definition: v8-util.h:54
static size_t Size(Impl *impl)
Definition: v8-util.h:51
static bool Empty(Impl *impl)
Definition: v8-util.h:50
static PersistentContainerValue Get(Impl *impl, K key)
Definition: v8-util.h:67
static K Key(Iterator it)
Definition: v8-util.h:55
static Iterator Begin(Impl *impl)
Definition: v8-util.h:53
std::map< K, PersistentContainerValue > Impl
Definition: v8-util.h:47
Impl::iterator Iterator
Definition: v8-util.h:48
static PersistentContainerValue Remove(Impl *impl, K key)
Definition: v8-util.h:72
static PersistentContainerValue Value(Iterator it)
Definition: v8-util.h:56
static void Swap(Impl &a, Impl &b)
Definition: v8-util.h:52
Definition: v8-util.h:525
StdPersistentValueMap(Isolate *isolate)
Definition: v8-util.h:527
Definition: v8-weak-callback-info.h:22
Isolate * GetIsolate() const
Definition: v8-weak-callback-info.h:35
T * GetParameter() const
Definition: v8-weak-callback-info.h:36
void SetSecondPassCallback(Callback callback) const
Definition: v8-weak-callback-info.h:45
internal::Address *const & slot() const
Definition: v8-handle-base.h:83
void Clear()
Definition: v8-handle-base.h:63
uintptr_t Address
Definition: v8-internal.h:52
Definition: libplatform.h:15
WeakCallbackType
Definition: v8-weak-callback-info.h:57
PersistentContainerCallbackType
Definition: v8-util.h:30
@ kWeakWithInternalFields
Definition: v8-util.h:34
@ kWeakWithParameter
Definition: v8-util.h:33
@ kNotWeak
Definition: v8-util.h:31
uintptr_t PersistentContainerValue
Definition: v8-util.h:28