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

Unified Diff: chrome/renderer/extensions/native_handler.cc

Issue 10918042: Use MakeWeak() to clean up function pointers in NativeHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 7 years, 11 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 | « chrome/renderer/extensions/native_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/native_handler.cc
diff --git a/chrome/renderer/extensions/native_handler.cc b/chrome/renderer/extensions/native_handler.cc
index a294891b9cb0119e371233e1ec7b260bc72653b5..4561f19c656d8e6a256cd228a135d83d9ac24db1 100644
--- a/chrome/renderer/extensions/native_handler.cc
+++ b/chrome/renderer/extensions/native_handler.cc
@@ -38,15 +38,25 @@ v8::Handle<v8::Value> NativeHandler::Router(const v8::Arguments& args) {
return handler_function->Run(args);
}
+// static
+void NativeHandler::DisposeFunction(v8::Persistent<v8::Value> object,
+ void* parameter) {
+ HandlerFunction* handler_function =
+ reinterpret_cast<HandlerFunction*>(parameter);
+
+ object.Dispose();
+ delete handler_function;
+}
+
void NativeHandler::RouteFunction(const std::string& name,
const HandlerFunction& handler_function) {
- linked_ptr<HandlerFunction> function(new HandlerFunction(handler_function));
- // TODO(koz): Investigate using v8's MakeWeak() function instead of holding
- // on to these pointers here.
- handler_functions_.push_back(function);
+ HandlerFunction* function = new HandlerFunction(handler_function);
+ // Deleted in DisposeFunction once v8 garbage collects function_template.
+ v8::Persistent<v8::External> function_value =
+ v8::Persistent<v8::External>::New(v8::External::New(function));
+ function_value.MakeWeak(function, DisposeFunction);
v8::Handle<v8::FunctionTemplate> function_template =
- v8::FunctionTemplate::New(Router,
- v8::External::New(function.get()));
+ v8::FunctionTemplate::New(Router, function_value);
object_template_->Set(name.c_str(), function_template);
}
« no previous file with comments | « chrome/renderer/extensions/native_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698