Chromium Code Reviews| 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..4ce397b010eb1bf560d66424029b358c727f15e9 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) { |
| + v8::HandleScope handle_scope; |
|
not at google - send to devlin
2013/01/07 19:43:43
do you really need a handle scope here?
koz (OOO until 15th September)
2013/01/07 22:55:28
Done.
|
| + 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); |
|
not at google - send to devlin
2013/01/07 19:43:43
Comment "deleted in DisposeFunction once v8 garbag
koz (OOO until 15th September)
2013/01/07 22:55:28
Done.
|
| + 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); |
| } |