Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 01c9ca9b81b23ad7980d451fddf1ecb42b838fb6..f4202f1fb0a861ee9d6a14a09dc22d8e6186d7f8 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -50,6 +50,7 @@ |
#include "unicode-inl.h" |
#include "utils.h" |
#include "vm-state.h" |
+#include "../include/v8-util.h" |
static const bool kLogThreading = false; |
@@ -3444,45 +3445,14 @@ THREADED_TEST(UniquePersistent) { |
} |
-template<typename K, typename V, bool is_weak> |
-class StdPersistentValueMapTraits { |
+template<typename K, typename V, typename Impl> |
+class TestDisposeTraits { |
public: |
- static const bool kIsWeak = is_weak; |
- typedef v8::PersistentContainerValue VInt; |
- typedef std::map<K, VInt> 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( |
@@ -3506,13 +3476,11 @@ class StdPersistentValueMapTraits { |
}; |
-template<bool is_weak> |
+template<typename PMap> |
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); |
+ PMap map(isolate); |
v8::internal::GlobalHandles* global_handles = |
reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
int initial_handle_count = global_handles->global_handles_count(); |
@@ -3537,7 +3505,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 (PMap::kIsWeak) { |
reinterpret_cast<v8::internal::Isolate*>(isolate)->heap()-> |
CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
} else { |
@@ -3549,8 +3517,14 @@ static void TestPersistentValueMap() { |
TEST(PersistentValueMap) { |
- TestPersistentValueMap<false>(); |
- TestPersistentValueMap<true>(); |
+ // Map with std::map backing, without weak callback or Dispose logic. |
+ TestPersistentValueMap<v8::PersistentValueMap<int, v8::Object> >(); |
+ |
+ // Weak map with std::map backing, with custom callbacks. |
+ typedef v8::util::StdMapTraits<int, v8::Object> MapT; |
+ typedef TestDisposeTraits<int, v8::Object, MapT::Impl> DisposeT; |
+ TestPersistentValueMap< |
+ v8::PersistentValueMap<int, v8::Object, MapT, DisposeT> >(); |
} |