Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 27178474c3b197824135279a81be781c5e19ae08..c767d8f48c15173ea63fd280ead15cb8fb2614ac 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -3445,47 +3445,15 @@ THREADED_TEST(UniquePersistent) { |
} |
-template<typename K, typename V, bool is_weak> |
-class StdPersistentValueMapTraits { |
+template<typename K, typename V> |
+class WeakStdMapTraits : public v8::StdMapTraits<K, V> { |
public: |
- static const bool kIsWeak = is_weak; |
- typedef v8::PersistentContainerValue VInt; |
- typedef std::map<K, VInt> Impl; |
+ typedef typename v8::DefaultPersistentValueMapTraits<K, V>::Impl Impl; |
+ static const bool kIsWeak = true; |
struct WeakCallbackDataType { |
Impl* impl; |
K key; |
}; |
- typedef typename Impl::iterator Iterator; |
- static bool Empty(Impl* impl) { return impl->empty(); } |
- static size_t Size(Impl* impl) { return impl->size(); } |
- static void Swap(Impl& a, Impl& b) { std::swap(a, b); } // NOLINT |
- static Iterator Begin(Impl* impl) { return impl->begin(); } |
- static Iterator End(Impl* impl) { return impl->end(); } |
- static K Key(Iterator it) { return it->first; } |
- static VInt Value(Iterator it) { return it->second; } |
- static VInt Set(Impl* impl, K key, VInt value) { |
- std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value)); |
- VInt old_value = v8::kPersistentContainerNotFound; |
- if (!res.second) { |
- old_value = res.first->second; |
- res.first->second = value; |
- } |
- return old_value; |
- } |
- static VInt Get(Impl* impl, K key) { |
- Iterator it = impl->find(key); |
- if (it == impl->end()) return v8::kPersistentContainerNotFound; |
- return it->second; |
- } |
- static VInt Remove(Impl* impl, K key) { |
- Iterator it = impl->find(key); |
- if (it == impl->end()) return v8::kPersistentContainerNotFound; |
- VInt value = it->second; |
- impl->erase(it); |
- return value; |
- } |
- static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value, |
- Impl* impl, K key) {} |
static WeakCallbackDataType* WeakCallbackParameter( |
Impl* impl, const K& key, Local<V> value) { |
WeakCallbackDataType* data = new WeakCallbackDataType; |
@@ -3504,15 +3472,15 @@ class StdPersistentValueMapTraits { |
static void DisposeCallbackData(WeakCallbackDataType* data) { |
delete data; |
} |
+ static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value, |
+ Impl* impl, K key) { } |
}; |
-template<bool is_weak> |
+template<typename Map> |
static void TestPersistentValueMap() { |
LocalContext env; |
v8::Isolate* isolate = env->GetIsolate(); |
- typedef v8::PersistentValueMap<int, v8::Object, |
- StdPersistentValueMapTraits<int, v8::Object, is_weak> > Map; |
Map map(isolate); |
v8::internal::GlobalHandles* global_handles = |
reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
@@ -3538,7 +3506,7 @@ static void TestPersistentValueMap() { |
CHECK_EQ(1, static_cast<int>(map.Size())); |
} |
CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
- if (is_weak) { |
+ if (map.IsWeak()) { |
reinterpret_cast<v8::internal::Isolate*>(isolate)->heap()-> |
CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
} else { |
@@ -3550,8 +3518,13 @@ static void TestPersistentValueMap() { |
TEST(PersistentValueMap) { |
- TestPersistentValueMap<false>(); |
- TestPersistentValueMap<true>(); |
+ // Default case, w/o weak callbacks: |
+ TestPersistentValueMap<v8::StdPersistentValueMap<int, v8::Object> >(); |
+ |
+ // Custom traits with weak callbacks: |
+ typedef v8::StdPersistentValueMap<int, v8::Object, |
+ WeakStdMapTraits<int, v8::Object> > WeakPersistentValueMap; |
+ TestPersistentValueMap<WeakPersistentValueMap>(); |
} |