22 static const uintptr_t kPersistentContainerNotFound = 0;
35 template<
typename K,
typename V>
42 static bool Empty(
Impl* impl) {
return impl->empty(); }
43 static size_t
Size(
Impl* impl) {
return impl->size(); }
51 std::pair<
Iterator,
bool> res = impl->insert(std::make_pair(key, value));
54 old_value = res.first->second;
55 res.first->second = value;
61 if (it == impl->end())
return kPersistentContainerNotFound;
66 if (it == impl->end())
return kPersistentContainerNotFound;
82 template<
typename K,
typename V>
118 template<
typename K,
typename V,
typename Traits>
130 size_t
Size() {
return Traits::Size(&impl_); }
141 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, key)));
148 return Traits::Get(&impl_, key) != kPersistentContainerNotFound;
157 return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key));
166 reinterpret_cast<
internal::Object**>(parent.val_),
167 reinterpret_cast<
internal::Object**>(FromVal(Traits::Get(&impl_, key))));
177 return SetUnique(key, &persistent);
184 return SetUnique(key, &value);
191 return Release(Traits::Remove(&impl_, key)).Pass();
199 typedef typename Traits::Iterator It;
202 while (!Traits::Empty(&impl_)) {
203 typename Traits::Impl impl;
204 Traits::Swap(impl_, impl);
205 for (It i = Traits::Begin(&impl); i != Traits::End(&impl); ++i) {
206 Traits::Dispose(isolate_, Release(Traits::Value(i)).Pass(),
220 : value_(other.value_) { }
223 return Local<V>::New(isolate, FromVal(value_));
226 return value_ == kPersistentContainerNotFound;
230 return SetReturnValueFromVal(&returnValue, value_);
233 value_ = kPersistentContainerNotFound;
236 value_ = other.value_;
272 *reference = Leak(&value);
273 return SetUnique(key, &value);
285 if (Traits::kCallbackType !=
kNotWeak) {
286 Local<V> value(
Local<V>::New(isolate_, *persistent));
287 persistent->
template SetWeak<
typename Traits::WeakCallbackDataType>(
288 Traits::WeakCallbackParameter(
this, key, value), WeakCallback);
291 Traits::Set(&impl_, key, ClearAndLeak(persistent));
292 return Release(old_value).Pass();
295 static void WeakCallback(
297 if (Traits::kCallbackType !=
kNotWeak) {
299 Traits::MapFromWeakCallbackData(data);
300 K key = Traits::KeyFromWeakCallbackData(data);
301 Traits::Dispose(data.GetIsolate(),
302 persistentValueMap->Remove(key).Pass(), key);
303 Traits::DisposeCallbackData(data.GetParameter());
308 return reinterpret_cast<V*>(v);
311 static bool SetReturnValueFromVal(
313 bool hasValue = value != kPersistentContainerNotFound;
315 returnValue->SetInternal(
316 *
reinterpret_cast<
internal::Object**>(FromVal(value)));
323 V* v = persistent->val_;
324 persistent->val_ = 0;
341 if (Traits::kCallbackType !=
kNotWeak && p.IsWeak()) {
342 Traits::DisposeCallbackData(
343 p.
template ClearWeak<
typename Traits::WeakCallbackDataType>());
349 typename Traits::Impl impl_;
360 template<
typename K,
typename V,
374 impl->push_back(value);
377 return impl->empty();
383 return (i < impl->size()) ? impl->at(i) : kPersistentContainerNotFound;
386 impl->reserve(capacity);
418 Traits::Append(&impl_, ClearAndLeak(&persistent));
425 Traits::Append(&impl_, ClearAndLeak(&persistent));
432 return Traits::IsEmpty(&impl_);
439 return Traits::Size(&impl_);
446 return Local<V>::New(isolate_, FromVal(Traits::Get(&impl_, index)));
453 size_t length = Traits::Size(&impl_);
454 for (size_t i = 0; i < length; i++) {
456 p.val_ = FromVal(Traits::Get(&impl_, i));
458 Traits::Clear(&impl_);
466 Traits::ReserveCapacity(&impl_, capacity);
472 V* v = persistent->val_;
473 persistent->val_ = 0;
478 return reinterpret_cast<V*>(v);
482 typename Traits::Impl impl_;