summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/guest_view
diff options
context:
space:
mode:
authormnaganov <mnaganov@chromium.org>2015-03-19 03:36:40 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-19 10:37:17 +0000
commit48a180623e4e2b4d3dc32d19281d617603218000 (patch)
tree62c61ece7a8ed108f4860ddafa6e76c4ef9cb564 /extensions/renderer/guest_view
parent62bd9e3de2849b73f09d618cab31a03e072bcc73 (diff)
downloadchromium_src-48a180623e4e2b4d3dc32d19281d617603218000.zip
chromium_src-48a180623e4e2b4d3dc32d19281d617603218000.tar.gz
chromium_src-48a180623e4e2b4d3dc32d19281d617603218000.tar.bz2
Cache locally function templates returned by gin::CreateFunctionTemplate
V8 caches FunctionTemplates for a lifetime of a web page for its own internal reasons, thus it is generally a good idea to cache the template returned by gin::CreateFunctionTemplate function. Otherwise, repeated method invocations from JS will create substantial memory leaks. BUG=463487 Review URL: https://codereview.chromium.org/974183005 Cr-Commit-Position: refs/heads/master@{#321330}
Diffstat (limited to 'extensions/renderer/guest_view')
-rw-r--r--extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc
index 6371561..ed586a7 100644
--- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc
+++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc
@@ -50,9 +50,15 @@ class ScriptableObject : public gin::Wrappable<ScriptableObject>,
v8::Isolate* isolate,
const std::string& identifier) override {
if (identifier == kPostMessageName) {
- return gin::CreateFunctionTemplate(isolate,
- base::Bind(&MimeHandlerViewContainer::PostMessage,
- container_, isolate))->GetFunction();
+ if (post_message_function_template_.IsEmpty()) {
+ post_message_function_template_.Reset(
+ isolate,
+ gin::CreateFunctionTemplate(
+ isolate, base::Bind(&MimeHandlerViewContainer::PostMessage,
+ container_, isolate)));
+ }
+ return v8::Local<v8::FunctionTemplate>::New(
+ isolate, post_message_function_template_)->GetFunction();
}
return v8::Local<v8::Value>();
}
@@ -71,6 +77,7 @@ class ScriptableObject : public gin::Wrappable<ScriptableObject>,
}
base::WeakPtr<MimeHandlerViewContainer> container_;
+ v8::Persistent<v8::FunctionTemplate> post_message_function_template_;
};
// static