 |
V8
latest master commit
V8 is Google's open source JavaScript engine
|
Go to the documentation of this file.
23 static const uintptr_t kPersistentContainerNotFound = 0;
37 template<
typename K,
typename V>
41 typedef std::map<K, PersistentContainerValue>
Impl;
44 static bool Empty(
Impl* impl) {
return impl->empty(); }
45 static size_t Size(
Impl* impl) {
return impl->size(); }
53 std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value));
56 old_value = res.first->second;
57 res.first->second = value;
63 if (it == impl->end())
return kPersistentContainerNotFound;
68 if (it == impl->end())
return kPersistentContainerNotFound;
84 template<
typename K,
typename V>
110 template <
typename K,
typename V>
113 template <
typename T>
114 struct RemovePointer;
142 template <
typename T>
143 struct RemovePointer<T*> {
159 template <
typename K,
typename V,
typename Traits>
167 size_t Size() {
return Traits::Size(&impl_); }
185 return Traits::Get(&impl_, key) != kPersistentContainerNotFound;
194 return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key));
201 return Release(Traits::Remove(&impl_, key)).Pass();
209 typedef typename Traits::Iterator It;
212 while (!Traits::Empty(&impl_)) {
213 typename Traits::Impl
impl;
214 Traits::Swap(impl_,
impl);
215 for (It i = Traits::Begin(&
impl); i != Traits::End(&
impl); ++i) {
216 Traits::Dispose(isolate_,
Release(Traits::Value(i)).Pass(),
230 : value_(other.value_) { }
236 return value_ == kPersistentContainerNotFound;
240 return SetReturnValueFromVal(&returnValue, value_);
243 value_ = kPersistentContainerNotFound;
246 value_ = other.value_;
275 return PersistentValueReference(Traits::Get(&impl_, key));
280 : isolate_(
isolate), label_(nullptr) {}
282 : isolate_(
isolate), label_(label) {}
287 typename Traits::Impl*
impl() {
return &impl_; }
290 return reinterpret_cast<V*
>(v);
294 V* v = persistent->val_;
295 persistent->val_ =
nullptr;
311 if (Traits::kCallbackType !=
kNotWeak && p.IsWeak()) {
312 Traits::DisposeCallbackData(
313 p.template ClearWeak<typename Traits::WeakCallbackDataType>());
320 p.val_ =
FromVal(Traits::Remove(&impl_, key));
325 persistent->AnnotateStrongRetainer(label_);
334 bool hasValue = value != kPersistentContainerNotFound;
336 returnValue->SetInternal(
343 typename Traits::Impl impl_;
347 template <
typename K,
typename V,
typename Traits>
381 if (Traits::kCallbackType ==
kNotWeak) {
389 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
390 Traits::WeakCallbackParameter(
this, key, value), WeakCallback,
395 return this->
Release(old_value).Pass();
404 *reference = this->
Leak(&value);
409 static void WeakCallback(
411 if (Traits::kCallbackType !=
kNotWeak) {
413 Traits::MapFromWeakCallbackInfo(data);
414 K key = Traits::KeyFromWeakCallbackInfo(data);
416 persistentValueMap->
Remove(key).Pass(), key);
423 template <
typename K,
typename V,
typename Traits>
457 if (Traits::kCallbackType ==
kNotWeak) {
465 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
466 Traits::WeakCallbackParameter(
this, key, value), OnWeakCallback,
471 return this->
Release(old_value).Pass();
480 *reference = this->
Leak(&value);
485 static void OnWeakCallback(
487 if (Traits::kCallbackType !=
kNotWeak) {
488 auto map = Traits::MapFromWeakCallbackInfo(data);
489 K key = Traits::KeyFromWeakCallbackInfo(data);
490 map->RemoveWeak(key);
491 Traits::OnWeakCallback(data);
496 static void SecondWeakCallback(
497 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) {
498 Traits::DisposeWeak(data);
510 template<
typename K,
typename V,
511 typename Traits = DefaultPersistentValueMapTraits<K, V> >
526 template <
typename K,
typename V,
527 typename Traits = DefaultGlobalMapTraits<K, V> >
537 typedef std::vector<PersistentContainerValue>
Impl;
540 impl->push_back(value);
543 return impl->empty();
549 return (i < impl->size()) ? impl->at(i) : kPersistentContainerNotFound;
552 impl->reserve(capacity);
570 template<
typename V,
typename Traits = DefaultPersistentValueVectorTraits>
584 Traits::Append(&impl_, ClearAndLeak(&persistent));
591 Traits::Append(&impl_, ClearAndLeak(&persistent));
598 return Traits::IsEmpty(&impl_);
605 return Traits::Size(&impl_);
612 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, index)));
619 size_t length = Traits::Size(&impl_);
620 for (
size_t i = 0; i < length; i++) {
622 p.val_ = FromVal(Traits::Get(&impl_, i));
624 Traits::Clear(&impl_);
632 Traits::ReserveCapacity(&impl_, capacity);
637 V* v = persistent->val_;
638 persistent->val_ =
nullptr;
643 return reinterpret_cast<V*
>(v);
647 typename Traits::Impl impl_;
void ReserveCapacity(size_t capacity)
void WeakCallbackDataType
~PersistentValueMapBase()
static PersistentContainerValue Remove(Impl *impl, K key)
static void Swap(Impl &a, Impl &b)
void RemoveWeak(const K &key)
PersistentValueReference GetReference(const K &key)
StdPersistentValueMap(Isolate *isolate)
V8_INLINE Isolate * GetIsolate() const
void AnnotateStrongRetainer(Global< V > *persistent)
PersistentValueReference()
static void DisposeWeak(const WeakCallbackInfo< WeakCallbackDataType > &data)
PersistentValueReference(const PersistentValueReference &other)
V8_INLINE T * GetParameter() const
Global< V > Set(const K &key, Global< V > value)
PersistentValueMapBase< K, V, Traits >::PersistentValueReference PersistentValueReference
Global< V > Set(const K &key, Local< V > value)
@ kWeakWithInternalFields
static PersistentContainerValue Get(Impl *impl, K key)
static bool IsEmpty(const Impl *impl)
static bool Empty(Impl *impl)
void Append(Local< V > value)
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
Global< V > Remove(const K &key)
PersistentValueMap< K, V, DefaultPersistentValueMapTraits< K, V > > MapType
GlobalValueMap< K, V, DefaultGlobalMapTraits< K, V > > MapType
static PersistentContainerValue ClearAndLeak(Global< V > *persistent)
static PersistentContainerValue Set(Impl *impl, K key, PersistentContainerValue value)
static const PersistentContainerCallbackType kCallbackType
Local< V > NewLocal(Isolate *isolate) const
static Global< V > Release(PersistentContainerValue v)
Global< V > SetUnique(const K &key, Global< V > *persistent)
void Append(Global< V > persistent)
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
static WeakCallbackDataType * WeakCallbackParameter(MapType *map, const K &key, Local< V > value)
PersistentValueMap(Isolate *isolate, const char *label)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
PersistentValueMap(Isolate *isolate)
std::map< K, PersistentContainerValue > Impl
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
PersistentContainerCallbackType
uintptr_t PersistentContainerValue
GlobalValueMap(Isolate *isolate)
StdGlobalValueMap(Isolate *isolate)
Local< V > Get(size_t index) const
static void Dispose(Isolate *isolate, Global< V > value, K key)
static void OnWeakCallback(const WeakCallbackInfo< WeakCallbackDataType > &data)
PersistentValueMapBase< K, V, Traits >::PersistentValueReference PersistentValueReference
std::vector< PersistentContainerValue > Impl
bool Contains(const K &key)
static void DisposeCallbackData(WeakCallbackDataType *data)
GlobalValueMap(Isolate *isolate, const char *label)
static PersistentContainerValue Get(const Impl *impl, size_t i)
static MapType * MapFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
static const PersistentContainerCallbackType kCallbackType
void SetSecondPassCallback(Callback callback) const
static Iterator Begin(Impl *impl)
PersistentValueMapBase(Isolate *isolate, const char *label)
static PersistentContainerValue Value(Iterator it)
bool SetReturnValue(ReturnValue< T > returnValue)
Global< V > Set(const K &key, Local< V > value)
Global< V > Set(const K &key, Global< V > value)
Global< V > SetUnique(const K &key, Global< V > *persistent)
PersistentValueVector(Isolate *isolate)
static size_t Size(Impl *impl)
PersistentValueMapBase(Isolate *isolate)
static size_t Size(const Impl *impl)
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
static void ReserveCapacity(Impl *impl, size_t capacity)
static void Clear(Impl *impl)
void operator=(const PersistentValueReference &other)
bool SetReturnValue(const K &key, ReturnValue< Value > returnValue)
static K Key(Iterator it)
static Iterator End(Impl *impl)
void WeakCallbackDataType
static void Dispose(Isolate *isolate, Global< V > value, K key)
Local< V > Get(const K &key)
static K KeyFromWeakCallbackInfo(const WeakCallbackInfo< WeakCallbackDataType > &data)
static PersistentContainerValue Leak(Global< V > *persistent)
static void Append(Impl *impl, PersistentContainerValue value)
static void DisposeCallbackData(WeakCallbackDataType *data)
Global< V > Set(const K &key, Global< V > value, PersistentValueReference *reference)
static V * FromVal(PersistentContainerValue v)