diff --git a/src/js_class.hpp b/src/js_class.hpp index 0e6eb112..39603897 100644 --- a/src/js_class.hpp +++ b/src/js_class.hpp @@ -68,27 +68,22 @@ using MethodMap = std::map; template using PropertyMap = std::map>; -template +template struct ClassDefinition { using Internal = U; + using Parent = V; - // Every specialization *must* at least have a name. - std::string name; -}; - -template -struct BaseClassDefinition { - // This pointer does not need to be set. - ClassDefinition* superclass; + // Every subclass *must* at least have a name. + // std::string const name; // ClassDefinition specializations should inherit from this class and override what's needed below. - ConstructorType* constructor; - MethodMap static_methods; - PropertyMap static_properties; - MethodMap methods; - PropertyMap properties; - IndexPropertyType index_accessor; - StringPropertyType string_accessor; + ConstructorType* const constructor = nullptr; + MethodMap const static_methods = {}; + PropertyMap const static_properties = {}; + MethodMap const methods = {}; + PropertyMap const properties = {}; + IndexPropertyType const index_accessor = {}; + StringPropertyType const string_accessor = {}; }; template diff --git a/src/js_collection.hpp b/src/js_collection.hpp index 2ed53915..510333a7 100644 --- a/src/js_collection.hpp +++ b/src/js_collection.hpp @@ -27,7 +27,7 @@ namespace js { class Collection {}; template -struct CollectionClass : ClassDefinition, BaseClassDefinition { +struct CollectionClass : ClassDefinition { std::string const name = "Collection"; }; diff --git a/src/js_list.hpp b/src/js_list.hpp index a1152915..b78883c7 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -58,7 +58,7 @@ struct List { }; template -struct ListClass : ClassDefinition, BaseClassDefinition> { +struct ListClass : ClassDefinition> { using List = List; std::string const name = "List"; diff --git a/src/js_object.hpp b/src/js_object.hpp index f79ddbce..9872706b 100644 --- a/src/js_object.hpp +++ b/src/js_object.hpp @@ -48,7 +48,7 @@ struct RealmObject { }; template -struct RealmObjectClass : ClassDefinition, BaseClassDefinition { +struct RealmObjectClass : ClassDefinition { using RealmObject = RealmObject; const std::string name = "RealmObject"; diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 2ea8ebf3..b7609391 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -199,7 +199,7 @@ class Realm { }; template -struct RealmClass : ClassDefinition, BaseClassDefinition { +struct RealmClass : ClassDefinition { using Realm = Realm; std::string const name = "Realm"; diff --git a/src/js_results.hpp b/src/js_results.hpp index a0577b3a..641293f9 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -58,7 +58,7 @@ struct Results { }; template -struct ResultsClass : ClassDefinition, BaseClassDefinition> { +struct ResultsClass : ClassDefinition> { using Results = Results; std::string const name = "Results"; diff --git a/src/jsc/jsc_class.hpp b/src/jsc/jsc_class.hpp index 2aefe1cf..403f37bf 100644 --- a/src/jsc/jsc_class.hpp +++ b/src/jsc/jsc_class.hpp @@ -40,6 +40,7 @@ template class ObjectWrap { public: using Internal = typename ClassType::Internal; + using ParentClassType = typename ClassType::Parent; operator Internal*() const { return m_object.get(); @@ -186,11 +187,6 @@ private: } } - template - static JSClassRef get_superclass(ClassDefinition*) { - return ObjectWrap::get_class(); - } - static std::vector get_methods(const MethodMap &methods) { std::vector functions; functions.reserve(methods.size() + 1); @@ -227,7 +223,7 @@ private: std::vector methods; std::vector properties; - definition.parentClass = get_superclass(s_class.superclass); + definition.parentClass = ObjectWrap::get_class(); definition.className = s_class.name.c_str(); definition.finalize = finalize; diff --git a/src/node/node_class.hpp b/src/node/node_class.hpp index 5319e011..3c9dbbc0 100644 --- a/src/node/node_class.hpp +++ b/src/node/node_class.hpp @@ -86,6 +86,7 @@ static inline void setup_property(v8::Local target, const std::strin template class ObjectWrap : public Nan::ObjectWrap { using Internal = typename ClassType::Internal; + using ParentClassType = typename ClassType::Parent; static ClassType s_class; @@ -93,11 +94,6 @@ class ObjectWrap : public Nan::ObjectWrap { ObjectWrap(Internal* object = nullptr) : m_object(object) {} - template - static v8::Local get_superclass(ClassDefinition*) { - return ObjectWrap::get_template(); - } - static void get_nonexistent_property(v8::Local property, Nan::NAN_PROPERTY_GETTER_ARGS_TYPE info) { // Do nothing. This function exists only to prevent a crash where it is used. } @@ -149,7 +145,7 @@ class ObjectWrap : public Nan::ObjectWrap { tpl->SetClassName(name); instance_tpl->SetInternalFieldCount(1); - v8::Local super_tpl = get_superclass(s_class.superclass); + v8::Local super_tpl = ObjectWrap::get_template(); if (!super_tpl.IsEmpty()) { tpl->Inherit(super_tpl); }