Add Values() method for IDWeakMap
authorCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 08:54:20 +0000 (16:54 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 08:54:20 +0000 (16:54 +0800)
atom/common/id_weak_map.cc
atom/common/id_weak_map.h

index 4b653ca..fc5fa13 100644 (file)
@@ -47,6 +47,14 @@ std::vector<int32_t> IDWeakMap::Keys() const {
   return keys;
 }
 
+std::vector<v8::Local<v8::Object>> IDWeakMap::Values(v8::Isolate* isolate) {
+  std::vector<v8::Local<v8::Object>> keys;
+  keys.reserve(map_.size());
+  for (const auto& iter : map_)
+    keys.emplace_back(v8::Local<v8::Object>::New(isolate, *iter.second));
+  return keys;
+}
+
 void IDWeakMap::Remove(int32_t id) {
   auto iter = map_.find(id);
   if (iter == map_.end())
index ce1a9a1..b16334d 100644 (file)
@@ -31,6 +31,9 @@ class IDWeakMap {
   // Returns IDs of all available objects.
   std::vector<int32_t> Keys() const;
 
+  // Returns all objects.
+  std::vector<v8::Local<v8::Object>> Values(v8::Isolate* isolate);
+
   // Remove object with |id| in the WeakMap.
   void Remove(int32_t key);