summaryrefslogtreecommitdiffstats
path: root/gin
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 17:08:16 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 17:08:16 +0000
commitdda52e48bf260f617f044619db268fcfd351a878 (patch)
tree7314d8f348329f15e95390b82f3243862cb2e74e /gin
parentc11e6591d1ed62fd84eb0ac7ec46f087c9bb8e0f (diff)
downloadchromium_src-dda52e48bf260f617f044619db268fcfd351a878.zip
chromium_src-dda52e48bf260f617f044619db268fcfd351a878.tar.gz
chromium_src-dda52e48bf260f617f044619db268fcfd351a878.tar.bz2
Add a function template cache to the interceptor unittest
The unittest also serves as an example how to use the interceptor API. BUG=none R=abarth@chromium.org,raymes@chromium.org Review URL: https://codereview.chromium.org/352223008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280350 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r--gin/interceptor_unittest.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/gin/interceptor_unittest.cc b/gin/interceptor_unittest.cc
index ee6b7dc..965ad6c 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};