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

Unified Diff: gin/object_template_builder.h

Issue 93813002: Implement gin::ObjectTemplateBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asdf Created 7 years, 1 month 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 | « gin/gin.gyp ('k') | gin/object_template_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/object_template_builder.h
diff --git a/gin/object_template_builder.h b/gin/object_template_builder.h
new file mode 100644
index 0000000000000000000000000000000000000000..87e2633862c0f175e06594a376536a03b9427480
--- /dev/null
+++ b/gin/object_template_builder.h
@@ -0,0 +1,56 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GIN_OBJECT_TEMPLATE_BUILDER_H_
+#define GIN_OBJECT_TEMPLATE_BUILDER_H_
+
+#include "base/bind.h"
+#include "base/strings/string_piece.h"
+#include "gin/converter.h"
+#include "gin/function_template.h"
+#include "v8/include/v8.h"
+
+namespace gin {
+
+// ObjectTemplateBuilder provides a handy interface to creating
+// v8::ObjectTemplate instances with various sorts of properties.
+class ObjectTemplateBuilder {
+ public:
+ explicit ObjectTemplateBuilder(v8::Isolate* isolate);
+ ~ObjectTemplateBuilder();
+
+ // It's against Google C++ style to return a non-const ref, but we take some
+ // poetic license here in order that all calls to Set() can be via the '.'
+ // operator and line up nicely.
+ template<typename T>
+ ObjectTemplateBuilder& SetValue(const base::StringPiece& name, T val) {
+ return SetImpl(name, ConvertToV8(isolate_, val));
+ }
+
+ template<typename T>
+ ObjectTemplateBuilder& SetMethod(const base::StringPiece& name, T val) {
+ return SetMethod(name, base::Bind(val));
+ }
+
+ template<typename T>
+ ObjectTemplateBuilder& SetMethod(const base::StringPiece& name,
+ const base::Callback<T>& callback) {
+ return SetImpl(name, CreateFunctionTemplate(isolate_, callback));
+ }
+
+ v8::Local<v8::ObjectTemplate> Build();
+
+ private:
+ ObjectTemplateBuilder& SetImpl(const base::StringPiece& name,
+ v8::Handle<v8::Data> val);
+
+ v8::Isolate* isolate_;
+
+ // ObjectTemplateBuilder should only be used on the stack.
+ v8::Local<v8::ObjectTemplate> template_;
+};
+
+} // namespace gin
+
+#endif // GIN_OBJECT_TEMPLATE_BUILDER_H_
« no previous file with comments | « gin/gin.gyp ('k') | gin/object_template_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698