| Index: test/cctest/test-api.cc
|
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
| index 27178474c3b197824135279a81be781c5e19ae08..44ed87a73236219f7f9bab0809723530c5acdf91 100644
|
| --- a/test/cctest/test-api.cc
|
| +++ b/test/cctest/test-api.cc
|
| @@ -3445,45 +3445,17 @@ THREADED_TEST(UniquePersistent) {
|
| }
|
|
|
|
|
| -template<typename K, typename V, bool is_weak>
|
| -class StdPersistentValueMapTraits {
|
| +template<typename K, typename V>
|
| +class StrongSTLMapTraits
|
| + : public v8::persistent_value_map_traits::WeakSTLMapTraits<K, V> {
|
| public:
|
| - static const bool kIsWeak = is_weak;
|
| - typedef v8::PersistentContainerValue VInt;
|
| - typedef std::map<K, VInt> Impl;
|
| + typedef typename
|
| + v8::persistent_value_map_traits::WeakSTLMapTraits<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(
|
| @@ -3507,12 +3479,11 @@ class StdPersistentValueMapTraits {
|
| };
|
|
|
|
|
| -template<bool is_weak>
|
| +template<typename Traits>
|
| static void TestPersistentValueMap() {
|
| LocalContext env;
|
| v8::Isolate* isolate = env->GetIsolate();
|
| - typedef v8::PersistentValueMap<int, v8::Object,
|
| - StdPersistentValueMapTraits<int, v8::Object, is_weak> > Map;
|
| + typedef v8::PersistentValueMap<int, v8::Object, Traits> Map;
|
| Map map(isolate);
|
| v8::internal::GlobalHandles* global_handles =
|
| reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
|
| @@ -3538,7 +3509,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 (Traits::kIsWeak) {
|
| reinterpret_cast<v8::internal::Isolate*>(isolate)->heap()->
|
| CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
|
| } else {
|
| @@ -3550,8 +3521,12 @@ static void TestPersistentValueMap() {
|
|
|
|
|
| TEST(PersistentValueMap) {
|
| - TestPersistentValueMap<false>();
|
| - TestPersistentValueMap<true>();
|
| + typedef v8::persistent_value_map_traits::WeakSTLMapTraits<int, v8::Object>
|
| + WeakMap;
|
| + typedef StrongSTLMapTraits<int, v8::Object> StrongMap;
|
| +
|
| + TestPersistentValueMap<WeakMap>();
|
| + TestPersistentValueMap<StrongMap>();
|
| }
|
|
|
|
|
|
|