Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1123)

Unified Diff: include/v8-util.h

Issue 201643003: First attempt at providing default traits for PersistentValueMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 1st stab at providng default traits for persistentValueMap Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8-util.h
diff --git a/include/v8-util.h b/include/v8-util.h
index 5cee46704af332d97443c903b59f92384e7f490c..eb06b56002aa15bc829558cb480f34d153aac692 100644
--- a/include/v8-util.h
+++ b/include/v8-util.h
@@ -42,6 +42,69 @@ namespace v8 {
typedef uintptr_t PersistentContainerValue;
static const uintptr_t kPersistentContainerNotFound = 0;
+
+namespace persistent_value_map_traits {
dcarney 2014/03/17 12:53:55 no need for a new namespace
vogelheim 2014/03/17 19:20:37 Removed.
+
+template<typename K, typename V>
+class WeakSTLMapTraits {
dcarney 2014/03/17 12:53:55 would be better as StdPersistentValueMap which it
vogelheim 2014/03/17 19:20:37 I couldn't really figure this one out. What I've d
+ public:
+ // STL map & related:
+ typedef std::map<K, v8::PersistentContainerValue> Impl;
+ 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 v8::PersistentContainerValue Value(Iterator it) { return it->second; }
+ static v8::PersistentContainerValue Set(Impl* impl, K key,
+ v8::PersistentContainerValue value) {
+ std::pair<Iterator, bool> res = impl->insert(std::make_pair(key, value));
+ v8::PersistentContainerValue old_value = v8::kPersistentContainerNotFound;
+ if (!res.second) {
+ old_value = res.first->second;
+ res.first->second = value;
+ }
+ return old_value;
+ }
+ static v8::PersistentContainerValue Get(Impl* impl, K key) {
+ Iterator it = impl->find(key);
+ if (it == impl->end()) return v8::kPersistentContainerNotFound;
+ return it->second;
+ }
+ static v8::PersistentContainerValue Remove(Impl* impl, K key) {
+ Iterator it = impl->find(key);
+ if (it == impl->end()) return v8::kPersistentContainerNotFound;
+ v8::PersistentContainerValue value = it->second;
+ impl->erase(it);
+ return value;
+ }
+
+ // Weak callback & friends:
+ static const bool kIsWeak = false;
dcarney 2014/03/17 12:53:55 this should be true for a class called WeakSTLMapT
vogelheim 2014/03/17 19:20:37 Yes. But actually, this class was misnamed, since
+ typedef void WeakCallbackDataType;
+ 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) {
+ return NULL;
+ }
+ static Impl* ImplFromWeakCallbackData(
+ const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
+ return NULL;
+ }
+ static K KeyFromWeakCallbackData(
+ const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
+ return K();
+ }
+ static void DisposeCallbackData(WeakCallbackDataType* data) {
+ }
+};
+
+} // namespace persistent_value_map_traits
+
/**
* A map wrapper that allows using UniquePersistent as a mapped value.
* C++11 embedders don't need this class, as they can use UniquePersistent
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698