22 static const uintptr_t kPersistentContainerNotFound = 0;
38 template<
typename K,
typename V>
45 static bool Empty(
Impl* impl) {
return impl->empty(); }
46 static size_t
Size(
Impl* impl) {
return impl->size(); }
54 std::pair<
Iterator,
bool> res = impl->insert(std::make_pair(key, value));
57 old_value = res.first->second;
58 res.first->second = value;
64 if (it == impl->end())
return kPersistentContainerNotFound;
69 if (it == impl->end())
return kPersistentContainerNotFound;
85 template<
typename K,
typename V>
111 template <
typename K,
typename V>
114 template <
typename T>
115 struct RemovePointer;
141 template <
typename T>
142 struct RemovePointer<T*> {
158 template <
typename K,
typename V,
typename Traits>
166 size_t
Size() {
return Traits::Size(&impl_); }
177 return Local<V>::New(isolate_,
FromVal(Traits::Get(&impl_, key)
));
184 return Traits::Get(&impl_, key) != kPersistentContainerNotFound;
193 return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key));
202 reinterpret_cast<
internal::Object**>(parent.val_),
210 return Release(Traits::Remove(&impl_, key)
).Pass();
218 typedef typename Traits::Iterator It;
221 while (!Traits::Empty(&impl_)) {
222 typename Traits::Impl impl;
223 Traits::Swap(impl_, impl);
224 for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) {
225 Traits::Dispose(isolate_,
Release(Traits::Value(i)
).Pass(),
239 : value_(other.value_) { }
245 return value_ == kPersistentContainerNotFound;
249 return SetReturnValueFromVal(&returnValue, value_);
252 value_ = kPersistentContainerNotFound;
255 value_ = other.value_;
296 return reinterpret_cast<V*>(v);
300 V* v = persistent->val_;
301 persistent->val_ = 0;
317 if (Traits::kCallbackType !=
kNotWeak && p.IsWeak()) {
318 Traits::DisposeCallbackData(
319 p.
template ClearWeak<
typename Traits::WeakCallbackDataType>());
326 p.val_ =
FromVal(Traits::Remove(&impl_, key)
);
336 bool hasValue = value != kPersistentContainerNotFound;
338 returnValue->SetInternal(
345 typename Traits::Impl impl_;
349 template <
typename K,
typename V,
typename Traits>
365 Global<V> persistent(
this->isolate(), value);
381 if (Traits::kCallbackType !=
kNotWeak) {
382 Local<V> value(
Local<V>::New(
this->isolate(), *persistent));
383 persistent->
template SetWeak<
typename Traits::WeakCallbackDataType>(
384 Traits::WeakCallbackParameter(
this, key, value), WeakCallback);
387 Traits::Set(
this->impl(), key,
this->ClearAndLeak(persistent));
388 return this->Release(old_value).Pass();
397 *reference =
this->Leak(&value);
402 static void WeakCallback(
404 if (Traits::kCallbackType !=
kNotWeak) {
406 Traits::MapFromWeakCallbackData(data);
407 K key = Traits::KeyFromWeakCallbackData(data);
408 Traits::Dispose(data.GetIsolate(),
409 persistentValueMap->Remove(key).Pass(), key);
410 Traits::DisposeCallbackData(data.GetParameter());
416 template <
typename K,
typename V,
typename Traits>
432 Global<V> persistent(
this->isolate(), value);
448 if (Traits::kCallbackType !=
kNotWeak) {
453 Local<V> value(
Local<V>::New(
this->isolate(), *persistent));
454 persistent->
template SetWeak<
typename Traits::WeakCallbackDataType>(
455 Traits::WeakCallbackParameter(
this, key, value), FirstWeakCallback,
459 Traits::Set(
this->impl(), key,
this->ClearAndLeak(persistent));
460 return this->Release(old_value).Pass();
469 *reference =
this->Leak(&value);
474 static void FirstWeakCallback(
476 if (Traits::kCallbackType !=
kNotWeak) {
477 auto map = Traits::MapFromWeakCallbackInfo(data);
478 K key = Traits::KeyFromWeakCallbackInfo(data);
479 map->RemoveWeak(key);
480 data.SetSecondPassCallback(SecondWeakCallback);
484 static void SecondWeakCallback(
486 Traits::DisposeWeak(data);
498 template<
typename K,
typename V,
514 template <
typename K,
typename V,
528 impl->push_back(value);
531 return impl->empty();
537 return (i < impl->size()) ? impl->at(i) : kPersistentContainerNotFound;
540 impl->reserve(capacity);
571 Global<V> persistent(isolate_, value);
572 Traits::Append(&impl_, ClearAndLeak(&persistent));
579 Traits::Append(&impl_, ClearAndLeak(&persistent));
586 return Traits::IsEmpty(&impl_);
593 return Traits::Size(&impl_);
600 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, index)));
607 size_t length = Traits::Size(&impl_);
608 for (size_t i = 0; i < length; i++) {
610 p.val_ = FromVal(Traits::Get(&impl_, i));
612 Traits::Clear(&impl_);
620 Traits::ReserveCapacity(&impl_, capacity);
625 V* v = persistent->val_;
626 persistent->val_ = 0;
631 return reinterpret_cast<V*>(v);
635 typename Traits::Impl impl_;