diff --git a/src/js_list.hpp b/src/js_list.hpp index 628de5f1..455e58fa 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -33,7 +33,7 @@ namespace realm { namespace js { template -class List { +struct ListClass : ClassDefinition> { using ContextType = typename T::Context; using ObjectType = typename T::Object; using ValueType = typename T::Value; @@ -41,7 +41,6 @@ class List { using Value = js::Value; using ReturnValue = js::ReturnValue; - public: static ObjectType create_instance(ContextType, realm::List &); // properties @@ -58,45 +57,40 @@ class List { static void snapshot(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void filtered(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void sorted(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); -}; - -template -struct ListClass : ClassDefinition> { - using List = js::List; - + std::string const name = "List"; MethodMap const methods = { - {"push", wrap}, - {"pop", wrap}, - {"unshift", wrap}, - {"shift", wrap}, - {"splice", wrap}, - {"snapshot", wrap}, - {"filtered", wrap}, - {"sorted", wrap}, + {"push", wrap}, + {"pop", wrap}, + {"unshift", wrap}, + {"shift", wrap}, + {"splice", wrap}, + {"snapshot", wrap}, + {"filtered", wrap}, + {"sorted", wrap}, }; PropertyMap const properties = { - {"length", {wrap, nullptr}}, + {"length", {wrap, nullptr}}, }; - IndexPropertyType const index_accessor = {wrap, wrap}; + IndexPropertyType const index_accessor = {wrap, wrap}; }; template -typename T::Object List::create_instance(ContextType ctx, realm::List &list) { +typename T::Object ListClass::create_instance(ContextType ctx, realm::List &list) { return create_object>(ctx, new realm::List(list)); } template -void List::get_length(ContextType ctx, ObjectType object, ReturnValue &return_value) { +void ListClass::get_length(ContextType ctx, ObjectType object, ReturnValue &return_value) { auto list = get_internal>(object); return_value.set((uint32_t)list->size()); } template -void List::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) { +void ListClass::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) { auto list = get_internal>(object); auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); @@ -104,14 +98,14 @@ void List::get_index(ContextType ctx, ObjectType object, uint32_t index, Retu } template -bool List::set_index(ContextType ctx, ObjectType object, uint32_t index, ValueType value) { +bool ListClass::set_index(ContextType ctx, ObjectType object, uint32_t index, ValueType value) { auto list = get_internal>(object); list->set(ctx, value, index); return true; } template -void List::push(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::push(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto list = get_internal>(this_object); @@ -123,7 +117,7 @@ void List::push(ContextType ctx, ObjectType this_object, size_t argc, const V } template -void List::pop(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::pop(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal>(this_object); @@ -142,7 +136,7 @@ void List::pop(ContextType ctx, ObjectType this_object, size_t argc, const Va } template -void List::unshift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::unshift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto list = get_internal>(this_object); @@ -154,7 +148,7 @@ void List::unshift(ContextType ctx, ObjectType this_object, size_t argc, cons } template -void List::shift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::shift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal>(this_object); @@ -171,7 +165,7 @@ void List::shift(ContextType ctx, ObjectType this_object, size_t argc, const } template -void List::splice(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::splice(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto list = get_internal>(this_object); @@ -207,27 +201,27 @@ void List::splice(ContextType ctx, ObjectType this_object, size_t argc, const } template -void List::snapshot(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::snapshot(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal>(this_object); - return_value.set(Results::create_instance(ctx, *list, false)); + return_value.set(ResultsClass::create_instance(ctx, *list, false)); } template -void List::filtered(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::filtered(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto list = get_internal>(this_object); - return_value.set(Results::create_filtered(ctx, *list, argc, arguments)); + return_value.set(ResultsClass::create_filtered(ctx, *list, argc, arguments)); } template -void List::sorted(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ListClass::sorted(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1, 2); auto list = get_internal>(this_object); - return_value.set(Results::create_sorted(ctx, *list, argc, arguments)); + return_value.set(ResultsClass::create_sorted(ctx, *list, argc, arguments)); } } // js diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index 4bd985be..6b5e9752 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -135,7 +135,7 @@ struct NativeAccessor { return Object::validated_get_object(ctx, Value::validated_to_object(ctx, value), (uint32_t)index); } static ValueType from_list(ContextType ctx, realm::List list) { - return List::create_instance(ctx, list); + return ListClass::create_instance(ctx, list); } static Mixed to_mixed(ContextType ctx, ValueType &val) { diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 221f1d5c..33d0ded4 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -468,7 +468,7 @@ void Realm::objects(ContextType ctx, ObjectType this_object, size_t argc, con SharedRealm realm = *get_internal>(this_object); std::string type = validated_object_type_for_value(realm, ctx, arguments[0]); - return_value.set(Results::create_instance(ctx, realm, type)); + return_value.set(ResultsClass::create_instance(ctx, realm, type)); } template diff --git a/src/js_results.hpp b/src/js_results.hpp index 0318fb53..da7f1a25 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -30,7 +30,7 @@ namespace realm { namespace js { template -class Results { +struct ResultsClass : ClassDefinition> { using ContextType = typename T::Context; using ObjectType = typename T::Object; using ValueType = typename T::Value; @@ -38,7 +38,6 @@ class Results { using Value = js::Value; using ReturnValue = js::ReturnValue; - public: static ObjectType create_instance(ContextType, const realm::Results &, bool live = true); static ObjectType create_instance(ContextType, const realm::List &, bool live = true); static ObjectType create_instance(ContextType, SharedRealm, const std::string &type, bool live = true); @@ -56,29 +55,24 @@ class Results { static void snapshot(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void filtered(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void sorted(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); -}; - -template -struct ResultsClass : ClassDefinition> { - using Results = js::Results; std::string const name = "Results"; MethodMap const methods = { - {"snapshot", wrap}, - {"filtered", wrap}, - {"sorted", wrap}, + {"snapshot", wrap}, + {"filtered", wrap}, + {"sorted", wrap}, }; PropertyMap const properties = { - {"length", {wrap, nullptr}}, + {"length", {wrap, nullptr}}, }; - IndexPropertyType const index_accessor = {wrap, nullptr}; + IndexPropertyType const index_accessor = {wrap, nullptr}; }; template -typename T::Object Results::create_instance(ContextType ctx, const realm::Results &results, bool live) { +typename T::Object ResultsClass::create_instance(ContextType ctx, const realm::Results &results, bool live) { auto new_results = new realm::Results(results); new_results->set_live(live); @@ -86,12 +80,12 @@ typename T::Object Results::create_instance(ContextType ctx, const realm::Res } template -typename T::Object Results::create_instance(ContextType ctx, const realm::List &list, bool live) { +typename T::Object ResultsClass::create_instance(ContextType ctx, const realm::List &list, bool live) { return create_instance(ctx, list.get_realm(), list.get_object_schema(), list.get_query(), live); } template -typename T::Object Results::create_instance(ContextType ctx, SharedRealm realm, const std::string &type, bool live) { +typename T::Object ResultsClass::create_instance(ContextType ctx, SharedRealm realm, const std::string &type, bool live) { auto table = ObjectStore::table_for_object_type(realm->read_group(), type); auto &schema = realm->config().schema; auto object_schema = schema->find(type); @@ -107,7 +101,7 @@ typename T::Object Results::create_instance(ContextType ctx, SharedRealm real } template -typename T::Object Results::create_instance(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, Query query, bool live) { +typename T::Object ResultsClass::create_instance(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, Query query, bool live) { auto results = new realm::Results(realm, object_schema, std::move(query)); results->set_live(live); @@ -116,7 +110,7 @@ typename T::Object Results::create_instance(ContextType ctx, SharedRealm real template template -typename T::Object Results::create_filtered(ContextType ctx, const U &collection, size_t argc, const ValueType arguments[]) { +typename T::Object ResultsClass::create_filtered(ContextType ctx, const U &collection, size_t argc, const ValueType arguments[]) { auto query_string = Value::validated_to_string(ctx, arguments[0], "predicate"); auto query = collection.get_query(); auto const &realm = collection.get_realm(); @@ -138,7 +132,7 @@ typename T::Object Results::create_filtered(ContextType ctx, const U &collect template template -typename T::Object Results::create_sorted(ContextType ctx, const U &collection, size_t argc, const ValueType arguments[]) { +typename T::Object ResultsClass::create_sorted(ContextType ctx, const U &collection, size_t argc, const ValueType arguments[]) { auto const &realm = collection.get_realm(); auto const &object_schema = collection.get_object_schema(); std::vector prop_names; @@ -195,13 +189,13 @@ typename T::Object Results::create_sorted(ContextType ctx, const U &collectio } template -void Results::get_length(ContextType ctx, ObjectType object, ReturnValue &return_value) { +void ResultsClass::get_length(ContextType ctx, ObjectType object, ReturnValue &return_value) { auto results = get_internal>(object); return_value.set((uint32_t)results->size()); } template -void Results::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) { +void ResultsClass::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) { auto results = get_internal>(object); auto row = results->get(index); @@ -216,15 +210,15 @@ void Results::get_index(ContextType ctx, ObjectType object, uint32_t index, R } template -void Results::snapshot(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ResultsClass::snapshot(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto results = get_internal>(this_object); - return_value.set(Results::create_instance(ctx, *results, false)); + return_value.set(ResultsClass::create_instance(ctx, *results, false)); } template -void Results::filtered(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ResultsClass::filtered(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto results = get_internal>(this_object); @@ -232,7 +226,7 @@ void Results::filtered(ContextType ctx, ObjectType this_object, size_t argc, } template -void Results::sorted(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { +void ResultsClass::sorted(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1, 2); auto results = get_internal>(this_object);