]> khamidou — GitHub mirrors - electron.git/commitdiff
Leak FunctionTemplateHandle
authorCheng Zhao <zcbenz@gmail.com>
Tue, 29 Dec 2015 02:40:10 +0000 (10:40 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 29 Dec 2015 02:40:10 +0000 (10:40 +0800)
They are cached through the app's lifetime, and freeing them at the
right time is complicate, so just leak them.

atom/common/api/atom_api_v8_util.cc

index 7b9490df6a8bafa3bbf8a21b9774ce7988886766..c86335adb15e36b95a43b84b34f7d1889350ba1d 100644 (file)
 
 namespace {
 
-using FunctionTemplateHandle =
-    v8::CopyablePersistentTraits<v8::FunctionTemplate>::CopyablePersistent;
+// A Persistent that can be copied and will not free itself.
+template<class T>
+struct LeakedPersistentTraits {
+  typedef v8::Persistent<T, LeakedPersistentTraits<T> > LeakedPersistent;
+  static const bool kResetInDestructor = false;
+  template<class S, class M>
+  static V8_INLINE void Copy(const v8::Persistent<S, M>& source,
+                             LeakedPersistent* dest) {
+    // do nothing, just allow copy
+  }
+};
 
 // The handles are leaked on purpose.
+using FunctionTemplateHandle =
+    LeakedPersistentTraits<v8::FunctionTemplate>::LeakedPersistent;
 std::map<std::string, FunctionTemplateHandle> function_templates_;
 
 v8::Local<v8::Object> CreateObjectWithName(v8::Isolate* isolate,