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

Unified Diff: gin/interceptor_unittest.cc

Issue 352223008: Add a function template cache to the interceptor unittest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/interceptor_unittest.cc
diff --git a/gin/interceptor_unittest.cc b/gin/interceptor_unittest.cc
index ee6b7dc50a765a7fd14bbdd5bd6a5768187fb632..965ad6c57f39092d3a9f28da6ff056cd757332da 100644
--- a/gin/interceptor_unittest.cc
+++ b/gin/interceptor_unittest.cc
@@ -13,6 +13,7 @@
#include "gin/try_catch.h"
#include "gin/wrappable.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "v8/include/v8-util.h"
namespace gin {
@@ -36,9 +37,7 @@ class MyInterceptor : public Wrappable<MyInterceptor>,
if (property == "value") {
return ConvertToV8(isolate, value_);
} else if (property == "func") {
- return CreateFunctionTemplate(isolate,
- base::Bind(&MyInterceptor::Call),
- HolderIsFirstArgument)->GetFunction();
+ return GetFunctionTemplate(isolate, "func")->GetFunction();
} else {
return v8::Local<v8::Value>();
}
@@ -83,7 +82,8 @@ class MyInterceptor : public Wrappable<MyInterceptor>,
explicit MyInterceptor(v8::Isolate* isolate)
: NamedPropertyInterceptor(isolate, this),
IndexedPropertyInterceptor(isolate, this),
- value_(0) {}
+ value_(0),
+ template_cache_(isolate) {}
virtual ~MyInterceptor() {}
// gin::Wrappable
@@ -100,7 +100,23 @@ class MyInterceptor : public Wrappable<MyInterceptor>,
return tmp;
}
+ v8::Local<v8::FunctionTemplate> GetFunctionTemplate(v8::Isolate* isolate,
+ const std::string& name) {
+ v8::Local<v8::FunctionTemplate> function_template =
+ template_cache_.Get(name);
+ if (!function_template.IsEmpty())
+ return function_template;
+ function_template = CreateFunctionTemplate(
+ isolate, base::Bind(&MyInterceptor::Call), HolderIsFirstArgument);
+ template_cache_.Set(name, function_template);
+ return function_template;
+ }
+
int value_;
+
+ v8::StdPersistentValueMap<std::string, v8::FunctionTemplate> template_cache_;
+
+ DISALLOW_COPY_AND_ASSIGN(MyInterceptor);
};
WrapperInfo MyInterceptor::kWrapperInfo = {kEmbedderNativeGin};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698