Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/bindings/generator.h

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Fixed bogus assert Created Aug. 31, 2017, 12:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/FilterNotifier.h ('k') | compiled/bindings/generator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/bindings/generator.h
===================================================================
--- a/compiled/bindings/generator.h
+++ b/compiled/bindings/generator.h
@@ -175,41 +175,47 @@ namespace bindings_internal
};
struct DifferentiatorInfo
{
size_t offset;
std::vector<std::pair<int, std::string>> mapping;
};
+ typedef std::vector<PropertyInfo> Properties;
+ typedef std::vector<MethodInfo> Methods;
+
struct ClassInfo
{
TYPEID id;
TYPEID baseClass;
std::string name;
- std::vector<PropertyInfo> properties;
- std::vector<MethodInfo> methods;
+ Properties properties;
+ Methods methods;
DifferentiatorInfo subclass_differentiator;
ptrdiff_t ref_counted_offset;
+ FunctionInfo instanceGetter;
};
void register_class(const char* name, TYPEID classID, TYPEID baseClassID,
- ptrdiff_t ref_counted_offset);
+ ptrdiff_t ref_counted_offset,
+ const FunctionInfo& instanceGetter = FunctionInfo());
void register_property(TYPEID classID, const char* name,
const FunctionInfo& getter, const FunctionInfo& setter,
const char* jsValue = "");
void register_method(TYPEID classID, const char* name,
const FunctionInfo& call);
void register_differentiator(TYPEID classID, size_t offset,
std::vector<std::pair<int, std::string>>& mapping);
- std::string wrapCall(const FunctionInfo& call, bool isFunction = true);
+ std::string wrapCall(const FunctionInfo& call, bool isFunction = true,
+ const FunctionInfo& instanceGetter = FunctionInfo());
}
template<typename ClassType,
typename BaseClass = bindings_internal::NoBaseClass,
typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::type* = nullptr>
class class_
{
public:
@@ -283,9 +289,50 @@ public:
mapping.emplace_back(item.first, item.second);
bindings_internal::register_differentiator(
bindings_internal::TypeInfo<ClassType>(), offset, mapping);
return *this;
}
};
+template<typename ClassType>
+class singleton
+{
+public:
+ singleton(const char* name, ClassType* (*instanceGetter)())
+ {
+ bindings_internal::register_class(name,
+ bindings_internal::TypeInfo<ClassType>(),
+ bindings_internal::TypeInfo<bindings_internal::NoBaseClass>(),
+ 0,
+ instanceGetter
+ );
+ }
+
+ template<typename FieldType>
+ const singleton& property(const char* name,
+ FieldType (ClassType::*getter)() const,
+ void (ClassType::*setter)(FieldType) = nullptr) const
+ {
+ bindings_internal::register_property(
+ bindings_internal::TypeInfo<ClassType>(), name, getter, setter);
+ return *this;
+ }
+
+ template<typename ReturnType, typename... Args>
+ const singleton& function(const char* name, ReturnType (ClassType::*method)(Args...)) const
+ {
+ bindings_internal::register_method(
+ bindings_internal::TypeInfo<ClassType>(), name, method);
+ return *this;
+ }
+
+ template<typename ReturnType, typename... Args>
+ const singleton& function(const char* name, ReturnType (ClassType::*method)(Args...) const) const
+ {
+ bindings_internal::register_method(
+ bindings_internal::TypeInfo<ClassType>(), name, method);
+ return *this;
+ }
+};
+
void printBindings();
« no previous file with comments | « compiled/FilterNotifier.h ('k') | compiled/bindings/generator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld