diff --git a/src/js_list.hpp b/src/js_list.hpp index 04959f04..63207841 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -34,30 +34,30 @@ namespace js { template class List { - using TContext = typename T::Context; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using Object = Object; using Value = Value; using ReturnValue = ReturnValue; public: - static TObject create_instance(TContext, realm::List &); + static ObjectType create_instance(ContextType, realm::List &); // properties - static void get_length(TContext, TObject, ReturnValue &); - static void get_index(TContext, TObject, uint32_t, ReturnValue &); - static bool set_index(TContext, TObject, uint32_t, TValue); + static void get_length(ContextType, ObjectType, ReturnValue &); + static void get_index(ContextType, ObjectType, uint32_t, ReturnValue &); + static bool set_index(ContextType, ObjectType, uint32_t, ValueType); // methods - static void push(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void pop(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void unshift(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void shift(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void splice(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void snapshot(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void filtered(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void sorted(TContext, TObject, size_t, const TValue[], ReturnValue &); + static void push(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void pop(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void unshift(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void shift(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void splice(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + 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 @@ -85,18 +85,18 @@ struct ListClass : ClassDefinition> { }; template -typename T::Object List::create_instance(TContext ctx, realm::List &list) { +typename T::Object List::create_instance(ContextType ctx, realm::List &list) { return create_object>(ctx, new realm::List(list)); } template -void List::get_length(TContext ctx, TObject object, ReturnValue &return_value) { +void List::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(TContext ctx, TObject object, uint32_t index, ReturnValue &return_value) { +void List::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 +104,14 @@ void List::get_index(TContext ctx, TObject object, uint32_t index, ReturnValu } template -bool List::set_index(TContext ctx, TObject object, uint32_t index, TValue value) { +bool List::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(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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 +123,7 @@ void List::push(TContext ctx, TObject this_object, size_t argc, const TValue } template -void List::pop(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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 +142,7 @@ void List::pop(TContext ctx, TObject this_object, size_t argc, const TValue a } template -void List::unshift(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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 +154,7 @@ void List::unshift(TContext ctx, TObject this_object, size_t argc, const TVal } template -void List::shift(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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 +171,7 @@ void List::shift(TContext ctx, TObject this_object, size_t argc, const TValue } template -void List::splice(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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); @@ -190,7 +190,7 @@ void List::splice(TContext ctx, TObject this_object, size_t argc, const TValu remove = std::min(remove, size - index); } - std::vector removed_objects; + std::vector removed_objects; removed_objects.reserve(remove); for (size_t i = 0; i < remove; i++) { @@ -207,7 +207,7 @@ void List::splice(TContext ctx, TObject this_object, size_t argc, const TValu } template -void List::snapshot(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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); @@ -215,7 +215,7 @@ void List::snapshot(TContext ctx, TObject this_object, size_t argc, const TVa } template -void List::filtered(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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); @@ -223,7 +223,7 @@ void List::filtered(TContext ctx, TObject this_object, size_t argc, const TVa } template -void List::sorted(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void List::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); diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index 89c332d4..dd513247 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -27,81 +27,81 @@ namespace js { template struct NativeAccessor { - using TContext = typename T::Context; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using Object = Object; using Value = Value; - static bool dict_has_value_for_key(TContext ctx, TValue dict, const std::string &prop_name) { - TObject object = Value::validated_to_object(ctx, dict); + static bool dict_has_value_for_key(ContextType ctx, ValueType dict, const std::string &prop_name) { + ObjectType object = Value::validated_to_object(ctx, dict); return Object::has_property(ctx, object, prop_name); } - static TValue dict_value_for_key(TContext ctx, TValue dict, const std::string &prop_name) { - TObject object = Value::validated_to_object(ctx, dict); + static ValueType dict_value_for_key(ContextType ctx, ValueType dict, const std::string &prop_name) { + ObjectType object = Value::validated_to_object(ctx, dict); return Object::get_property(ctx, object, prop_name); } - static bool has_default_value_for_property(TContext ctx, realm::Realm *realm, const ObjectSchema &object_schema, const std::string &prop_name) { + static bool has_default_value_for_property(ContextType ctx, realm::Realm *realm, const ObjectSchema &object_schema, const std::string &prop_name) { auto defaults = get_delegate(realm)->m_defaults[object_schema.name]; return defaults.count(prop_name) != 0; } - static TValue default_value_for_property(TContext ctx, realm::Realm *realm, const ObjectSchema &object_schema, const std::string &prop_name) { + static ValueType default_value_for_property(ContextType ctx, realm::Realm *realm, const ObjectSchema &object_schema, const std::string &prop_name) { auto defaults = get_delegate(realm)->m_defaults[object_schema.name]; return defaults.at(prop_name); } // These must be implemented for each JS engine. - static std::string to_binary(TContext, TValue &); - static TValue from_binary(TContext, BinaryData); + static std::string to_binary(ContextType, ValueType &); + static ValueType from_binary(ContextType, BinaryData); - static bool to_bool(TContext ctx, TValue &value) { + static bool to_bool(ContextType ctx, ValueType &value) { return Value::validated_to_boolean(ctx, value, "Property"); } - static TValue from_bool(TContext ctx, bool boolean) { + static ValueType from_bool(ContextType ctx, bool boolean) { return Value::from_boolean(ctx, boolean); } - static long long to_long(TContext ctx, TValue &value) { + static long long to_long(ContextType ctx, ValueType &value) { return Value::validated_to_number(ctx, value, "Property"); } - static TValue from_long(TContext ctx, long long number) { + static ValueType from_long(ContextType ctx, long long number) { return Value::from_number(ctx, number); } - static float to_float(TContext ctx, TValue &value) { + static float to_float(ContextType ctx, ValueType &value) { return Value::validated_to_number(ctx, value, "Property"); } - static TValue from_float(TContext ctx, float number) { + static ValueType from_float(ContextType ctx, float number) { return Value::from_number(ctx, number); } - static double to_double(TContext ctx, TValue &value) { + static double to_double(ContextType ctx, ValueType &value) { return Value::validated_to_number(ctx, value, "Property"); } - static TValue from_double(TContext ctx, double number) { + static ValueType from_double(ContextType ctx, double number) { return Value::from_number(ctx, number); } - static std::string to_string(TContext ctx, TValue &value) { + static std::string to_string(ContextType ctx, ValueType &value) { return Value::validated_to_string(ctx, value, "Property"); } - static TValue from_string(TContext ctx, StringData string) { + static ValueType from_string(ContextType ctx, StringData string) { return Value::from_string(ctx, string.data()); } - static DateTime to_datetime(TContext ctx, TValue &value) { - TObject date = Value::validated_to_date(ctx, value, "Property"); + static DateTime to_datetime(ContextType ctx, ValueType &value) { + ObjectType date = Value::validated_to_date(ctx, value, "Property"); return DateTime(Value::to_number(ctx, date)); } - static TValue from_datetime(TContext ctx, DateTime dt) { + static ValueType from_datetime(ContextType ctx, DateTime dt) { return Object::create_date(ctx, dt.get_datetime()); } - static bool is_null(TContext ctx, TValue &value) { + static bool is_null(ContextType ctx, ValueType &value) { return Value::is_null(ctx, value) || Value::is_undefined(ctx, value); } - static TValue null_value(TContext ctx) { + static ValueType null_value(ContextType ctx) { return Value::from_null(ctx); } - static size_t to_object_index(TContext ctx, SharedRealm realm, TValue &value, const std::string &type, bool try_update) { - TObject object = Value::validated_to_object(ctx, value); + static size_t to_object_index(ContextType ctx, SharedRealm realm, ValueType &value, const std::string &type, bool try_update) { + ObjectType object = Value::validated_to_object(ctx, value); if (Object::template is_instance>(ctx, object)) { return get_internal>(object)->row().get_index(); } @@ -111,31 +111,31 @@ struct NativeAccessor { object = Schema::dict_for_property_array(ctx, *object_schema, object); } - auto child = realm::Object::create(ctx, realm, *object_schema, static_cast(object), try_update); + auto child = realm::Object::create(ctx, realm, *object_schema, static_cast(object), try_update); return child.row().get_index(); } - static size_t to_existing_object_index(TContext ctx, TValue &value) { - TObject object = Value::validated_to_object(ctx, value); + static size_t to_existing_object_index(ContextType ctx, ValueType &value) { + ObjectType object = Value::validated_to_object(ctx, value); if (Object::template is_instance>(ctx, object)) { return get_internal>(object)->row().get_index(); } throw std::runtime_error("object is not a Realm Object"); } - static TValue from_object(TContext ctx, realm::Object realm_object) { + static ValueType from_object(ContextType ctx, realm::Object realm_object) { return RealmObject::create_instance(ctx, realm_object); } - static size_t list_size(TContext ctx, TValue &value) { + static size_t list_size(ContextType ctx, ValueType &value) { return Object::validated_get_length(ctx, Value::validated_to_object(ctx, value)); } - static TValue list_value_at_index(TContext ctx, TValue &value, size_t index) { + static ValueType list_value_at_index(ContextType ctx, ValueType &value, size_t index) { return Object::validated_get_object(ctx, Value::validated_to_object(ctx, value), (uint32_t)index); } - static TValue from_list(TContext ctx, realm::List list) { + static ValueType from_list(ContextType ctx, realm::List list) { return List::create_instance(ctx, list); } - static Mixed to_mixed(TContext ctx, TValue &val) { + static Mixed to_mixed(ContextType ctx, ValueType &val) { throw std::runtime_error("'Any' type is unsupported"); } }; diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 83d713b7..c3c21d32 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -43,10 +43,10 @@ struct RealmClass; template class RealmDelegate : public BindingContext { public: - using TGlobalContext = typename T::GlobalContext; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using GlobalContextType = typename T::GlobalContext; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using Value = Value; using ObjectDefaultsMap = typename Schema::ObjectDefaultsMap; @@ -60,13 +60,13 @@ class RealmDelegate : public BindingContext { } virtual void will_change(std::vector const& observers, std::vector const& invalidated) {} - RealmDelegate(std::weak_ptr realm, TGlobalContext ctx) : m_context(ctx), m_realm(realm) {} + RealmDelegate(std::weak_ptr realm, GlobalContextType ctx) : m_context(ctx), m_realm(realm) {} ~RealmDelegate() { remove_all_notifications(); } - void add_notification(TFunction notification) { + void add_notification(FunctionType notification) { for (auto &handler : m_notifications) { if (handler == notification) { return; @@ -74,7 +74,7 @@ class RealmDelegate : public BindingContext { } m_notifications.emplace_back(m_context, notification); } - void remove_notification(TFunction notification) { + void remove_notification(FunctionType notification) { for (auto iter = m_notifications.begin(); iter != m_notifications.end(); ++iter) { if (*iter == notification) { m_notifications.erase(iter); @@ -90,8 +90,8 @@ class RealmDelegate : public BindingContext { ConstructorMap m_constructors; private: - Protected m_context; - std::list> m_notifications; + Protected m_context; + std::list> m_notifications; std::weak_ptr m_realm; void notify(const char *notification_name) { @@ -100,8 +100,8 @@ class RealmDelegate : public BindingContext { throw std::runtime_error("Realm no longer exists"); } - TObject realm_object = create_object>(m_context, new SharedRealm(realm)); - TValue arguments[2]; + ObjectType realm_object = create_object>(m_context, new SharedRealm(realm)); + ValueType arguments[2]; arguments[0] = realm_object; arguments[1] = Value::from_string(m_context, notification_name); @@ -117,45 +117,45 @@ void delete_all_realms(); template class Realm { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using String = String; using Object = Object; using Value = Value; using ReturnValue = ReturnValue; - using NativeAccessor = realm::NativeAccessor; + using NativeAccessor = realm::NativeAccessor; public: - static TFunction create_constructor(TContext); + static FunctionType create_constructor(ContextType); // methods - static void objects(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void create(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void delete_one(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void delete_all(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void write(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void add_listener(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void remove_listener(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void remove_all_listeners(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void close(TContext, TObject, size_t, const TValue[], ReturnValue &); + static void objects(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void create(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void delete_one(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void delete_all(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void write(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void add_listener(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void remove_listener(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void remove_all_listeners(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void close(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); // properties - static void get_path(TContext, TObject, ReturnValue &); - static void get_schema_version(TContext, TObject, ReturnValue &); + static void get_path(ContextType, ObjectType, ReturnValue &); + static void get_schema_version(ContextType, ObjectType, ReturnValue &); // static methods - static void constructor(TContext, TObject, size_t, const TValue[]); - static void schema_version(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void clear_test_state(TContext, TObject, size_t, const TValue[], ReturnValue &); + static void constructor(ContextType, ObjectType, size_t, const ValueType[]); + static void schema_version(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); + static void clear_test_state(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); // static properties - static void get_default_path(TContext, TObject, ReturnValue &); - static void set_default_path(TContext, TObject, TValue value); + static void get_default_path(ContextType, ObjectType, ReturnValue &); + static void set_default_path(ContextType, ObjectType, ValueType value); private: - static std::string validated_notification_name(TContext ctx, const TValue &value) { + static std::string validated_notification_name(ContextType ctx, const ValueType &value) { std::string name = Value::validated_to_string(ctx, value, "notification name"); if (name != "change") { throw std::runtime_error("Only the 'change' notification name is supported."); @@ -164,13 +164,13 @@ class Realm { } // converts constructor object or type name to type name - static std::string validated_object_type_for_value(SharedRealm &realm, TContext ctx, const TValue &value) { + static std::string validated_object_type_for_value(SharedRealm &realm, ContextType ctx, const ValueType &value) { if (Value::is_constructor(ctx, value)) { - TFunction constructor = Value::to_constructor(ctx, value); + FunctionType constructor = Value::to_constructor(ctx, value); auto delegate = get_delegate(realm.get()); for (auto &pair : delegate->m_constructors) { - if (TFunction(pair.second) == constructor) { + if (FunctionType(pair.second) == constructor) { return pair.first; } } @@ -223,11 +223,11 @@ struct RealmClass : ClassDefinition { }; template -inline typename T::Function Realm::create_constructor(TContext ctx) { - TFunction realm_constructor = ObjectWrap>::create_constructor(ctx); - TFunction collection_constructor = ObjectWrap>::create_constructor(ctx); - TFunction list_constructor = ObjectWrap>::create_constructor(ctx); - TFunction results_constructor = ObjectWrap>::create_constructor(ctx); +inline typename T::Function Realm::create_constructor(ContextType ctx) { + FunctionType realm_constructor = ObjectWrap>::create_constructor(ctx); + FunctionType collection_constructor = ObjectWrap>::create_constructor(ctx); + FunctionType list_constructor = ObjectWrap>::create_constructor(ctx); + FunctionType results_constructor = ObjectWrap>::create_constructor(ctx); PropertyAttributes attributes = PropertyAttributes(ReadOnly | DontEnum | DontDelete); Object::set_property(ctx, realm_constructor, "Collection", collection_constructor, attributes); @@ -238,7 +238,7 @@ inline typename T::Function Realm::create_constructor(TContext ctx) { } template -void Realm::constructor(TContext ctx, TObject this_object, size_t argc, const TValue arguments[]) { +void Realm::constructor(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[]) { static const String path_string = "path"; static const String schema_string = "schema"; static const String schema_version_string = "schemaVersion"; @@ -252,14 +252,14 @@ void Realm::constructor(TContext ctx, TObject this_object, size_t argc, const config.path = default_path(); } else if (argc == 1) { - TValue value = arguments[0]; + ValueType value = arguments[0]; if (Value::is_string(ctx, value)) { config.path = Value::validated_to_string(ctx, value, "path"); } else if (Value::is_object(ctx, value)) { - TObject object = Value::validated_to_object(ctx, value); + ObjectType object = Value::validated_to_object(ctx, value); - TValue path_value = Object::get_property(ctx, object, path_string); + ValueType path_value = Object::get_property(ctx, object, path_string); if (!Value::is_undefined(ctx, path_value)) { config.path = Value::validated_to_string(ctx, path_value, "path"); } @@ -267,13 +267,13 @@ void Realm::constructor(TContext ctx, TObject this_object, size_t argc, const config.path = js::default_path(); } - TValue schema_value = Object::get_property(ctx, object, schema_string); + ValueType schema_value = Object::get_property(ctx, object, schema_string); if (!Value::is_undefined(ctx, schema_value)) { - TObject schema_object = Value::validated_to_object(ctx, schema_value, "schema"); + ObjectType schema_object = Value::validated_to_object(ctx, schema_value, "schema"); config.schema.reset(new realm::Schema(Schema::parse_schema(ctx, schema_object, defaults, constructors))); } - TValue version_value = Object::get_property(ctx, object, schema_version_string); + ValueType version_value = Object::get_property(ctx, object, schema_version_string); if (!Value::is_undefined(ctx, version_value)) { config.schema_version = Value::validated_to_number(ctx, version_value, "schemaVersion"); } @@ -281,7 +281,7 @@ void Realm::constructor(TContext ctx, TObject this_object, size_t argc, const config.schema_version = 0; } - TValue encryption_key_value = Object::get_property(ctx, object, encryption_key_string); + ValueType encryption_key_value = Object::get_property(ctx, object, encryption_key_string); if (!Value::is_undefined(ctx, encryption_key_value)) { std::string encryption_key = NativeAccessor::to_binary(ctx, encryption_key_value); config.encryption_key = std::vector(encryption_key.begin(), encryption_key.end()); @@ -309,7 +309,7 @@ void Realm::constructor(TContext ctx, TObject this_object, size_t argc, const } template -void Realm::schema_version(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::schema_version(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1, 2); realm::Realm::Config config; @@ -330,35 +330,35 @@ void Realm::schema_version(TContext ctx, TObject this_object, size_t argc, co } template -void Realm::clear_test_state(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); delete_all_realms(); } template -void Realm::get_default_path(TContext ctx, TObject object, ReturnValue &return_value) { +void Realm::get_default_path(ContextType ctx, ObjectType object, ReturnValue &return_value) { return_value.set(realm::js::default_path()); } template -void Realm::set_default_path(TContext ctx, TObject object, TValue value) { +void Realm::set_default_path(ContextType ctx, ObjectType object, ValueType value) { js::set_default_path(Value::validated_to_string(ctx, value, "defaultPath")); } template -void Realm::get_path(TContext ctx, TObject object, ReturnValue &return_value) { +void Realm::get_path(ContextType ctx, ObjectType object, ReturnValue &return_value) { std::string path = get_internal>(object)->get()->config().path; return_value.set(path); } template -void Realm::get_schema_version(TContext ctx, TObject object, ReturnValue &return_value) { +void Realm::get_schema_version(ContextType ctx, ObjectType object, ReturnValue &return_value) { double version = get_internal>(object)->get()->config().schema_version; return_value.set(version); } template -void Realm::objects(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::objects(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1); SharedRealm realm = *get_internal>(this_object); @@ -368,7 +368,7 @@ void Realm::objects(TContext ctx, TObject this_object, size_t argc, const TVa } template -void Realm::create(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::create(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 2, 3); SharedRealm realm = *get_internal>(this_object); @@ -380,7 +380,7 @@ void Realm::create(TContext ctx, TObject this_object, size_t argc, const TVal throw std::runtime_error("Object type '" + className + "' not found in schema."); } - TObject object = Value::validated_to_object(ctx, arguments[1], "properties"); + ObjectType object = Value::validated_to_object(ctx, arguments[1], "properties"); if (Value::is_array(ctx, arguments[1])) { object = Schema::dict_for_property_array(ctx, *object_schema, object); } @@ -390,12 +390,12 @@ void Realm::create(TContext ctx, TObject this_object, size_t argc, const TVal update = Value::validated_to_boolean(ctx, arguments[2], "update"); } - auto realm_object = realm::Object::create(ctx, realm, *object_schema, object, update); + auto realm_object = realm::Object::create(ctx, realm, *object_schema, object, update); return_value.set(RealmObject::create_instance(ctx, realm_object)); } template -void Realm::delete_one(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::delete_one(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1); SharedRealm realm = *get_internal>(this_object); @@ -403,7 +403,7 @@ void Realm::delete_one(TContext ctx, TObject this_object, size_t argc, const throw std::runtime_error("Can only delete objects within a transaction."); } - TObject arg = Value::validated_to_object(ctx, arguments[0]); + ObjectType arg = Value::validated_to_object(ctx, arguments[0]); if (Object::template is_instance>(ctx, arg)) { auto object = get_internal>(arg); @@ -413,7 +413,7 @@ void Realm::delete_one(TContext ctx, TObject this_object, size_t argc, const else if (Value::is_array(ctx, arg)) { uint32_t length = Object::validated_get_length(ctx, arg); for (uint32_t i = length; i--;) { - TObject object = Object::validated_get_object(ctx, arg, i); + ObjectType object = Object::validated_get_object(ctx, arg, i); if (!Object::template is_instance>(ctx, object)) { throw std::runtime_error("Argument to 'delete' must be a Realm object or a collection of Realm objects."); @@ -438,7 +438,7 @@ void Realm::delete_one(TContext ctx, TObject this_object, size_t argc, const } template -void Realm::delete_all(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::delete_all(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); SharedRealm realm = *get_internal>(this_object); @@ -453,11 +453,11 @@ void Realm::delete_all(TContext ctx, TObject this_object, size_t argc, const } template -void Realm::write(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::write(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1); SharedRealm realm = *get_internal>(this_object); - TFunction callback = Value::validated_to_function(ctx, arguments[0]); + FunctionType callback = Value::validated_to_function(ctx, arguments[0]); try { realm->begin_transaction(); @@ -473,7 +473,7 @@ void Realm::write(TContext ctx, TObject this_object, size_t argc, const TValu } template -void Realm::add_listener(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::add_listener(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 2); __unused std::string name = validated_notification_name(ctx, arguments[0]); @@ -484,7 +484,7 @@ void Realm::add_listener(TContext ctx, TObject this_object, size_t argc, cons } template -void Realm::remove_listener(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::remove_listener(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 2); __unused std::string name = validated_notification_name(ctx, arguments[0]); @@ -495,7 +495,7 @@ void Realm::remove_listener(TContext ctx, TObject this_object, size_t argc, c } template -void Realm::remove_all_listeners(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::remove_all_listeners(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0, 1); if (argc) { validated_notification_name(ctx, arguments[0]); @@ -506,7 +506,7 @@ void Realm::remove_all_listeners(TContext ctx, TObject this_object, size_t ar } template -void Realm::close(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Realm::close(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); SharedRealm realm = *get_internal>(this_object); diff --git a/src/js_realm_object.hpp b/src/js_realm_object.hpp index b3629747..48b4a97d 100644 --- a/src/js_realm_object.hpp +++ b/src/js_realm_object.hpp @@ -30,10 +30,10 @@ namespace js { template class RealmObject { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using String = String; using Value = Value; using Object = Object; @@ -41,11 +41,11 @@ class RealmObject { using ReturnValue = ReturnValue; public: - static TObject create_instance(TContext, realm::Object &); + static ObjectType create_instance(ContextType, realm::Object &); - static void get_property(TContext, TObject, const String &, ReturnValue &); - static bool set_property(TContext, TObject, const String &, TValue); - static std::vector get_property_names(TContext, TObject); + static void get_property(ContextType, ObjectType, const String &, ReturnValue &); + static bool set_property(ContextType, ObjectType, const String &, ValueType); + static std::vector get_property_names(ContextType, ObjectType); }; template @@ -62,7 +62,7 @@ struct RealmObjectClass : ClassDefinition { }; template -typename T::Object RealmObject::create_instance(TContext ctx, realm::Object &realm_object) { +typename T::Object RealmObject::create_instance(ContextType ctx, realm::Object &realm_object) { static String prototype_string = "prototype"; auto delegate = get_delegate(realm_object.realm().get()); @@ -73,11 +73,11 @@ typename T::Object RealmObject::create_instance(TContext ctx, realm::Object & return object; } - TFunction constructor = delegate->m_constructors.at(name); - TObject prototype = Object::validated_get_object(ctx, constructor, prototype_string); + FunctionType constructor = delegate->m_constructors.at(name); + ObjectType prototype = Object::validated_get_object(ctx, constructor, prototype_string); Object::set_prototype(ctx, object, prototype); - TValue result = Function::call(ctx, constructor, object, 0, NULL); + ValueType result = Function::call(ctx, constructor, object, 0, NULL); if (result != object && !Value::is_null(ctx, result) && !Value::is_undefined(ctx, result)) { throw std::runtime_error("Realm object constructor must not return another value"); } @@ -86,10 +86,10 @@ typename T::Object RealmObject::create_instance(TContext ctx, realm::Object & } template -void RealmObject::get_property(TContext ctx, TObject object, const String &property, ReturnValue &return_value) { +void RealmObject::get_property(ContextType ctx, ObjectType object, const String &property, ReturnValue &return_value) { try { auto realm_object = get_internal>(object); - auto result = realm_object->template get_property_value(ctx, property); + auto result = realm_object->template get_property_value(ctx, property); return_value.set(result); } catch (InvalidPropertyException &ex) { // getters for nonexistent properties in JS should always return undefined @@ -97,14 +97,14 @@ void RealmObject::get_property(TContext ctx, TObject object, const String &pr } template -bool RealmObject::set_property(TContext ctx, TObject object, const String &property, TValue value) { +bool RealmObject::set_property(ContextType ctx, ObjectType object, const String &property, ValueType value) { auto realm_object = get_internal>(object); realm_object->set_property_value(ctx, property, value, true); return true; } template -std::vector> RealmObject::get_property_names(TContext ctx, TObject object) { +std::vector> RealmObject::get_property_names(ContextType ctx, ObjectType object) { auto realm_object = get_internal>(object); auto &properties = realm_object->get_object_schema().properties; diff --git a/src/js_results.hpp b/src/js_results.hpp index fb6a516a..92b72c45 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -31,31 +31,31 @@ namespace js { template class Results { - using TContext = typename T::Context; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using Object = Object; using Value = Value; using ReturnValue = ReturnValue; public: - static TObject create_instance(TContext, const realm::Results &, bool live = true); - static TObject create_instance(TContext, const realm::List &, bool live = true); - static TObject create_instance(TContext, SharedRealm, const std::string &type, bool live = true); - static TObject create_instance(TContext, SharedRealm, const ObjectSchema &, Query, bool live = true); + 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); + static ObjectType create_instance(ContextType, SharedRealm, const ObjectSchema &, Query, bool live = true); template - static TObject create_filtered(TContext, const U &, size_t, const TValue[]); + static ObjectType create_filtered(ContextType, const U &, size_t, const ValueType[]); template - static TObject create_sorted(TContext, const U &, size_t, const TValue[]); + static ObjectType create_sorted(ContextType, const U &, size_t, const ValueType[]); - static void get_length(TContext, TObject, ReturnValue &); - static void get_index(TContext, TObject, uint32_t, ReturnValue &); + static void get_length(ContextType, ObjectType, ReturnValue &); + static void get_index(ContextType, ObjectType, uint32_t, ReturnValue &); - static void snapshot(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void filtered(TContext, TObject, size_t, const TValue[], ReturnValue &); - static void sorted(TContext, TObject, size_t, const TValue[], ReturnValue &); + 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 @@ -78,7 +78,7 @@ struct ResultsClass : ClassDefinition> { }; template -typename T::Object Results::create_instance(TContext ctx, const realm::Results &results, bool live) { +typename T::Object Results::create_instance(ContextType ctx, const realm::Results &results, bool live) { auto new_results = new realm::Results(results); new_results->set_live(live); @@ -86,12 +86,12 @@ typename T::Object Results::create_instance(TContext ctx, const realm::Result } template -typename T::Object Results::create_instance(TContext ctx, const realm::List &list, bool live) { +typename T::Object Results::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(TContext ctx, SharedRealm realm, const std::string &type, bool live) { +typename T::Object Results::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 +107,7 @@ typename T::Object Results::create_instance(TContext ctx, SharedRealm realm, } template -typename T::Object Results::create_instance(TContext ctx, SharedRealm realm, const ObjectSchema &object_schema, Query query, bool live) { +typename T::Object Results::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,13 +116,13 @@ typename T::Object Results::create_instance(TContext ctx, SharedRealm realm, template template -typename T::Object Results::create_filtered(TContext ctx, const U &collection, size_t argc, const TValue arguments[]) { +typename T::Object Results::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(); auto const &object_schema = collection.get_object_schema(); - std::vector args; + std::vector args; args.reserve(argc - 1); for (size_t i = 1; i < argc; i++) { @@ -130,7 +130,7 @@ typename T::Object Results::create_filtered(TContext ctx, const U &collection } parser::Predicate predicate = parser::parse(query_string); - query_builder::ArgumentConverter converter(ctx, args); + query_builder::ArgumentConverter converter(ctx, args); query_builder::apply_predicate(query, predicate, converter, *realm->config().schema, object_schema.name); return create_instance(ctx, realm, object_schema, std::move(query)); @@ -138,7 +138,7 @@ typename T::Object Results::create_filtered(TContext ctx, const U &collection template template -typename T::Object Results::create_sorted(TContext ctx, const U &collection, size_t argc, const TValue arguments[]) { +typename T::Object Results::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; @@ -148,7 +148,7 @@ typename T::Object Results::create_sorted(TContext ctx, const U &collection, if (Value::is_array(ctx, arguments[0])) { validate_argument_count(argc, 1, "Second argument is not allowed if passed an array of sort descriptors"); - TObject js_prop_names = Value::validated_to_object(ctx, arguments[0]); + ObjectType js_prop_names = Value::validated_to_object(ctx, arguments[0]); prop_count = Object::validated_get_length(ctx, js_prop_names); if (!prop_count) { throw std::invalid_argument("Sort descriptor array must not be empty"); @@ -158,10 +158,10 @@ typename T::Object Results::create_sorted(TContext ctx, const U &collection, ascending.resize(prop_count); for (unsigned int i = 0; i < prop_count; i++) { - TValue value = Object::validated_get_property(ctx, js_prop_names, i); + ValueType value = Object::validated_get_property(ctx, js_prop_names, i); if (Value::is_array(ctx, value)) { - TObject array = Value::to_array(ctx, value); + ObjectType array = Value::to_array(ctx, value); prop_names[i] = Object::validated_get_string(ctx, array, 0); ascending[i] = !Object::validated_get_boolean(ctx, array, 1); } @@ -195,13 +195,13 @@ typename T::Object Results::create_sorted(TContext ctx, const U &collection, } template -void Results::get_length(TContext ctx, TObject object, ReturnValue &return_value) { +void Results::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(TContext ctx, TObject object, uint32_t index, ReturnValue &return_value) { +void Results::get_index(ContextType ctx, ObjectType object, uint32_t index, ReturnValue &return_value) { auto results = get_internal>(object); auto row = results->get(index); @@ -216,7 +216,7 @@ void Results::get_index(TContext ctx, TObject object, uint32_t index, ReturnV } template -void Results::snapshot(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Results::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); @@ -224,7 +224,7 @@ void Results::snapshot(TContext ctx, TObject this_object, size_t argc, const } template -void Results::filtered(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Results::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 +232,7 @@ void Results::filtered(TContext ctx, TObject this_object, size_t argc, const } template -void Results::sorted(TContext ctx, TObject this_object, size_t argc, const TValue arguments[], ReturnValue &return_value) { +void Results::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); diff --git a/src/js_schema.hpp b/src/js_schema.hpp index 75fc310f..31927abd 100644 --- a/src/js_schema.hpp +++ b/src/js_schema.hpp @@ -28,36 +28,36 @@ namespace js { template struct Schema { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; using String = String; using Object = Object; using Value = Value; - using ObjectDefaults = std::map>; + using ObjectDefaults = std::map>; using ObjectDefaultsMap = std::map; - using ConstructorMap = std::map>; + using ConstructorMap = std::map>; - static TObject dict_for_property_array(TContext, const ObjectSchema &, TObject); - static Property parse_property(TContext, TValue, std::string, ObjectDefaults &); - static ObjectSchema parse_object_schema(TContext, TObject, ObjectDefaultsMap &, ConstructorMap &); - static realm::Schema parse_schema(TContext, TObject, ObjectDefaultsMap &, ConstructorMap &); + static ObjectType dict_for_property_array(ContextType, const ObjectSchema &, ObjectType); + static Property parse_property(ContextType, ValueType, std::string, ObjectDefaults &); + static ObjectSchema parse_object_schema(ContextType, ObjectType, ObjectDefaultsMap &, ConstructorMap &); + static realm::Schema parse_schema(ContextType, ObjectType, ObjectDefaultsMap &, ConstructorMap &); }; template -typename T::Object Schema::dict_for_property_array(TContext ctx, const ObjectSchema &object_schema, TObject array) { +typename T::Object Schema::dict_for_property_array(ContextType ctx, const ObjectSchema &object_schema, ObjectType array) { size_t count = object_schema.properties.size(); if (count != Object::validated_get_length(ctx, array)) { throw std::runtime_error("Array must contain values for all object properties"); } - TObject dict = Object::create_empty(ctx); + ObjectType dict = Object::create_empty(ctx); for (uint32_t i = 0; i < count; i++) { - TValue value = Object::get_property(ctx, array, i); + ValueType value = Object::get_property(ctx, array, i); Object::set_property(ctx, dict, object_schema.properties[i].name, value); } @@ -65,7 +65,7 @@ typename T::Object Schema::dict_for_property_array(TContext ctx, const Object } template -Property Schema::parse_property(TContext ctx, TValue attributes, std::string property_name, ObjectDefaults &object_defaults) { +Property Schema::parse_property(ContextType ctx, ValueType attributes, std::string property_name, ObjectDefaults &object_defaults) { static const String default_string = "default"; static const String indexed_string = "indexed"; static const String type_string = "type"; @@ -75,14 +75,14 @@ Property Schema::parse_property(TContext ctx, TValue attributes, std::string Property prop; prop.name = property_name; - TObject property_object = {}; + ObjectType property_object = {}; std::string type; if (Value::is_object(ctx, attributes)) { property_object = Value::validated_to_object(ctx, attributes); type = Object::validated_get_string(ctx, property_object, type_string); - TValue optional_value = Object::get_property(ctx, property_object, optional_string); + ValueType optional_value = Object::get_property(ctx, property_object, optional_string); if (!Value::is_undefined(ctx, optional_value)) { prop.is_nullable = Value::validated_to_boolean(ctx, optional_value, "optional"); } @@ -136,12 +136,12 @@ Property Schema::parse_property(TContext ctx, TValue attributes, std::string } if (Value::is_valid(property_object)) { - TValue default_value = Object::get_property(ctx, property_object, default_string); + ValueType default_value = Object::get_property(ctx, property_object, default_string); if (!Value::is_undefined(ctx, default_value)) { - object_defaults.emplace(prop.name, Protected(ctx, default_value)); + object_defaults.emplace(prop.name, Protected(ctx, default_value)); } - TValue indexed_value = Object::get_property(ctx, property_object, indexed_string); + ValueType indexed_value = Object::get_property(ctx, property_object, indexed_string); if (!Value::is_undefined(ctx, indexed_value)) { prop.is_indexed = Value::validated_to_boolean(ctx, indexed_value); } @@ -151,13 +151,13 @@ Property Schema::parse_property(TContext ctx, TValue attributes, std::string } template -ObjectSchema Schema::parse_object_schema(TContext ctx, TObject object_schema_object, ObjectDefaultsMap &defaults, ConstructorMap &constructors) { +ObjectSchema Schema::parse_object_schema(ContextType ctx, ObjectType object_schema_object, ObjectDefaultsMap &defaults, ConstructorMap &constructors) { static const String name_string = "name"; static const String primary_string = "primaryKey"; static const String properties_string = "properties"; static const String schema_string = "schema"; - TFunction object_constructor = {}; + FunctionType object_constructor = {}; if (Value::is_constructor(ctx, object_schema_object)) { object_constructor = Value::to_constructor(ctx, object_schema_object); object_schema_object = Object::validated_get_object(ctx, object_constructor, schema_string, "Realm object constructor must have a 'schema' property."); @@ -167,11 +167,11 @@ ObjectSchema Schema::parse_object_schema(TContext ctx, TObject object_schema_ ObjectSchema object_schema; object_schema.name = Object::validated_get_string(ctx, object_schema_object, name_string); - TObject properties_object = Object::validated_get_object(ctx, object_schema_object, properties_string, "ObjectSchema must have a 'properties' object."); + ObjectType properties_object = Object::validated_get_object(ctx, object_schema_object, properties_string, "ObjectSchema must have a 'properties' object."); if (Value::is_array(ctx, properties_object)) { uint32_t length = Object::validated_get_length(ctx, properties_object); for (uint32_t i = 0; i < length; i++) { - TObject property_object = Object::validated_get_object(ctx, properties_object, i); + ObjectType property_object = Object::validated_get_object(ctx, properties_object, i); std::string property_name = Object::validated_get_string(ctx, property_object, name_string); object_schema.properties.emplace_back(parse_property(ctx, property_object, property_name, object_defaults)); } @@ -179,12 +179,12 @@ ObjectSchema Schema::parse_object_schema(TContext ctx, TObject object_schema_ else { auto property_names = Object::get_property_names(ctx, properties_object); for (auto &property_name : property_names) { - TValue property_value = Object::get_property(ctx, properties_object, property_name); + ValueType property_value = Object::get_property(ctx, properties_object, property_name); object_schema.properties.emplace_back(parse_property(ctx, property_value, property_name, object_defaults)); } } - TValue primary_value = Object::get_property(ctx, object_schema_object, primary_string); + ValueType primary_value = Object::get_property(ctx, object_schema_object, primary_string); if (!Value::is_undefined(ctx, primary_value)) { object_schema.primary_key = Value::validated_to_string(ctx, primary_value); Property *property = object_schema.primary_key_property(); @@ -196,7 +196,7 @@ ObjectSchema Schema::parse_object_schema(TContext ctx, TObject object_schema_ // Store prototype so that objects of this type will have their prototype set to this prototype object. if (Value::is_valid(object_constructor)) { - constructors.emplace(object_schema.name, Protected(ctx, object_constructor)); + constructors.emplace(object_schema.name, Protected(ctx, object_constructor)); } defaults.emplace(object_schema.name, std::move(object_defaults)); @@ -205,12 +205,12 @@ ObjectSchema Schema::parse_object_schema(TContext ctx, TObject object_schema_ } template -realm::Schema Schema::parse_schema(TContext ctx, TObject schema_object, ObjectDefaultsMap &defaults, ConstructorMap &constructors) { +realm::Schema Schema::parse_schema(ContextType ctx, ObjectType schema_object, ObjectDefaultsMap &defaults, ConstructorMap &constructors) { std::vector schema; uint32_t length = Object::validated_get_length(ctx, schema_object); for (uint32_t i = 0; i < length; i++) { - TObject object_schema_object = Object::validated_get_object(ctx, schema_object, i); + ObjectType object_schema_object = Object::validated_get_object(ctx, schema_object, i); ObjectSchema object_schema = parse_object_schema(ctx, object_schema_object, defaults, constructors); schema.emplace_back(std::move(object_schema)); } diff --git a/src/js_types.hpp b/src/js_types.hpp index 3bd81bf2..77e0db39 100644 --- a/src/js_types.hpp +++ b/src/js_types.hpp @@ -58,50 +58,50 @@ struct String { template struct Context { - using TContext = typename T::Context; - using GlobalTContext = typename T::GlobalContext; + using ContextType = typename T::Context; + using GlobalContextType = typename T::GlobalContext; - static GlobalTContext get_global_context(TContext); + static GlobalContextType get_global_context(ContextType); }; template struct Value { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; - static bool is_array(TContext, const TValue &); - static bool is_array_buffer(TContext, const TValue &); - static bool is_array_buffer_view(TContext, const TValue &); - static bool is_boolean(TContext, const TValue &); - static bool is_constructor(TContext, const TValue &); - static bool is_date(TContext, const TValue &); - static bool is_function(TContext, const TValue &); - static bool is_null(TContext, const TValue &); - static bool is_number(TContext, const TValue &); - static bool is_object(TContext, const TValue &); - static bool is_string(TContext, const TValue &); - static bool is_undefined(TContext, const TValue &); - static bool is_valid(const TValue &); + static bool is_array(ContextType, const ValueType &); + static bool is_array_buffer(ContextType, const ValueType &); + static bool is_array_buffer_view(ContextType, const ValueType &); + static bool is_boolean(ContextType, const ValueType &); + static bool is_constructor(ContextType, const ValueType &); + static bool is_date(ContextType, const ValueType &); + static bool is_function(ContextType, const ValueType &); + static bool is_null(ContextType, const ValueType &); + static bool is_number(ContextType, const ValueType &); + static bool is_object(ContextType, const ValueType &); + static bool is_string(ContextType, const ValueType &); + static bool is_undefined(ContextType, const ValueType &); + static bool is_valid(const ValueType &); - static TValue from_boolean(TContext, bool); - static TValue from_null(TContext); - static TValue from_number(TContext, double); - static TValue from_string(TContext, const String &); - static TValue from_undefined(TContext); + static ValueType from_boolean(ContextType, bool); + static ValueType from_null(ContextType); + static ValueType from_number(ContextType, double); + static ValueType from_string(ContextType, const String &); + static ValueType from_undefined(ContextType); - static TObject to_array(TContext, const TValue &); - static bool to_boolean(TContext, const TValue &); - static TFunction to_constructor(TContext, const TValue &); - static TObject to_date(TContext, const TValue &); - static TFunction to_function(TContext, const TValue &); - static double to_number(TContext, const TValue &); - static TObject to_object(TContext, const TValue &); - static String to_string(TContext, const TValue &); + static ObjectType to_array(ContextType, const ValueType &); + static bool to_boolean(ContextType, const ValueType &); + static FunctionType to_constructor(ContextType, const ValueType &); + static ObjectType to_date(ContextType, const ValueType &); + static FunctionType to_function(ContextType, const ValueType &); + static double to_number(ContextType, const ValueType &); + static ObjectType to_object(ContextType, const ValueType &); + static String to_string(ContextType, const ValueType &); #define VALIDATED(return_t, type) \ - static return_t validated_to_##type(TContext ctx, const TValue &value, const char *name = nullptr) { \ + static return_t validated_to_##type(ContextType ctx, const ValueType &value, const char *name = nullptr) { \ if (!is_##type(ctx, value)) { \ std::string prefix = name ? std::string("'") + name + "'" : "JS value"; \ throw std::invalid_argument(prefix + " must be: " #type); \ @@ -109,13 +109,13 @@ struct Value { return to_##type(ctx, value); \ } - VALIDATED(TObject, array) + VALIDATED(ObjectType, array) VALIDATED(bool, boolean) - VALIDATED(TFunction, constructor) - VALIDATED(TObject, date) - VALIDATED(TFunction, function) + VALIDATED(FunctionType, constructor) + VALIDATED(ObjectType, date) + VALIDATED(FunctionType, function) VALIDATED(double, number) - VALIDATED(TObject, object) + VALIDATED(ObjectType, object) VALIDATED(String, string) #undef VALIDATED @@ -123,56 +123,56 @@ struct Value { template struct Function { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; - static TValue call(TContext, const TFunction &, const TObject &, size_t, const TValue[]); - static TValue call(TContext ctx, const TFunction &function, const TObject &this_object, const std::vector &arguments) { + static ValueType call(ContextType, const FunctionType &, const ObjectType &, size_t, const ValueType[]); + static ValueType call(ContextType ctx, const FunctionType &function, const ObjectType &this_object, const std::vector &arguments) { return call(ctx, function, this_object, arguments.size(), arguments.data()); } - static TObject construct(TContext, const TFunction &, size_t, const TValue[]); - static TValue construct(TContext ctx, const TFunction &function, const std::vector &arguments) { + static ObjectType construct(ContextType, const FunctionType &, size_t, const ValueType[]); + static ValueType construct(ContextType ctx, const FunctionType &function, const std::vector &arguments) { return construct(ctx, function, arguments.size(), arguments.data()); } }; template struct Object { - using TContext = typename T::Context; - using TFunction = typename T::Function; - using TObject = typename T::Object; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using FunctionType = typename T::Function; + using ObjectType = typename T::Object; + using ValueType = typename T::Value; public: - static TValue get_prototype(TContext, const TObject &); - static void set_prototype(TContext, const TObject &, const TValue &); + static ValueType get_prototype(ContextType, const ObjectType &); + static void set_prototype(ContextType, const ObjectType &, const ValueType &); - static bool has_property(TContext, const TObject &, const String &); - static bool has_property(TContext, const TObject &, uint32_t); - static TValue get_property(TContext, const TObject &, const String &); - static TValue get_property(TContext, const TObject &, uint32_t); - static void set_property(TContext, const TObject &, const String &, const TValue &, PropertyAttributes attributes = None); - static void set_property(TContext, const TObject &, uint32_t, const TValue &); - static std::vector> get_property_names(TContext, const TObject &); + static bool has_property(ContextType, const ObjectType &, const String &); + static bool has_property(ContextType, const ObjectType &, uint32_t); + static ValueType get_property(ContextType, const ObjectType &, const String &); + static ValueType get_property(ContextType, const ObjectType &, uint32_t); + static void set_property(ContextType, const ObjectType &, const String &, const ValueType &, PropertyAttributes attributes = None); + static void set_property(ContextType, const ObjectType &, uint32_t, const ValueType &); + static std::vector> get_property_names(ContextType, const ObjectType &); template - static TValue validated_get_property(TContext ctx, const TObject &object, const P &property, const char *message = nullptr) { + static ValueType validated_get_property(ContextType ctx, const ObjectType &object, const P &property, const char *message = nullptr) { if (!has_property(ctx, object, property)) { throw std::out_of_range(message ?: "Object missing expected property: " + util::to_string(property)); } return get_property(ctx, object, property); } - static uint32_t validated_get_length(TContext ctx, const TObject &object) { + static uint32_t validated_get_length(ContextType ctx, const ObjectType &object) { static const String length_string = "length"; return Value::validated_to_number(ctx, get_property(ctx, object, length_string)); } #define VALIDATED(return_t, type) \ - static return_t validated_get_##type(TContext ctx, const TObject &object, const String &key, const char *message = nullptr) { \ + static return_t validated_get_##type(ContextType ctx, const ObjectType &object, const String &key, const char *message = nullptr) { \ try { \ return Value::validated_to_##type(ctx, get_property(ctx, object, key), std::string(key).c_str()); \ } \ @@ -180,7 +180,7 @@ struct Object { throw message ? std::invalid_argument(message) : e; \ } \ } \ - static return_t validated_get_##type(TContext ctx, const TObject &object, uint32_t index, const char *message = nullptr) { \ + static return_t validated_get_##type(ContextType ctx, const ObjectType &object, uint32_t index, const char *message = nullptr) { \ try { \ return Value::validated_to_##type(ctx, get_property(ctx, object, index)); \ } \ @@ -189,78 +189,78 @@ struct Object { } \ } - VALIDATED(TObject, array) + VALIDATED(ObjectType, array) VALIDATED(bool, boolean) - VALIDATED(TFunction, constructor) - VALIDATED(TObject, date) - VALIDATED(TFunction, function) + VALIDATED(FunctionType, constructor) + VALIDATED(ObjectType, date) + VALIDATED(FunctionType, function) VALIDATED(double, number) - VALIDATED(TObject, object) + VALIDATED(ObjectType, object) VALIDATED(String, string) #undef VALIDATED - static TValue call_method(TContext ctx, const TObject &object, const String &name, uint32_t argc, const TValue arguments[]) { - TFunction method = validated_get_function(ctx, object, name); + static ValueType call_method(ContextType ctx, const ObjectType &object, const String &name, uint32_t argc, const ValueType arguments[]) { + FunctionType method = validated_get_function(ctx, object, name); return Function::call(ctx, method, object, argc, arguments); } - static TValue call_method(TContext ctx, const TObject &object, const String &name, const std::vector &arguments) { + static ValueType call_method(ContextType ctx, const ObjectType &object, const String &name, const std::vector &arguments) { return call_method(ctx, object, name, (uint32_t)arguments.size(), arguments.data()); } - static TObject create_empty(TContext); - static TObject create_array(TContext, uint32_t, const TValue[]); + static ObjectType create_empty(ContextType); + static ObjectType create_array(ContextType, uint32_t, const ValueType[]); - static TObject create_array(TContext ctx, const std::vector &values) { + static ObjectType create_array(ContextType ctx, const std::vector &values) { return create_array(ctx, (uint32_t)values.size(), values.data()); } - static TObject create_array(TContext ctx) { + static ObjectType create_array(ContextType ctx) { return create_array(ctx, 0, nullptr); } - static TObject create_date(TContext, double); + static ObjectType create_date(ContextType, double); template - static TObject create_instance(TContext, typename ClassType::Internal*); + static ObjectType create_instance(ContextType, typename ClassType::Internal*); template - static bool is_instance(TContext, const TObject &); + static bool is_instance(ContextType, const ObjectType &); template - static typename ClassType::Internal* get_internal(const TObject &); + static typename ClassType::Internal* get_internal(const ObjectType &); template - static void set_internal(const TObject &, typename ClassType::Internal*); + static void set_internal(const ObjectType &, typename ClassType::Internal*); }; -template +template class Protected { - operator TValue() const; - bool operator==(const TValue &) const; - bool operator!=(const TValue &) const; - bool operator==(const Protected &) const; - bool operator!=(const Protected &) const; + operator ValueType() const; + bool operator==(const ValueType &) const; + bool operator!=(const ValueType &) const; + bool operator==(const Protected &) const; + bool operator!=(const Protected &) const; }; template struct Exception : public std::runtime_error { - using TContext = typename T::Context; - using TValue = typename T::Value; + using ContextType = typename T::Context; + using ValueType = typename T::Value; - const Protected m_value; + const Protected m_value; - Exception(TContext ctx, const std::string &message) + Exception(ContextType ctx, const std::string &message) : std::runtime_error(message), m_value(value(ctx, message)) {} - Exception(TContext ctx, const TValue &val) + Exception(ContextType ctx, const ValueType &val) : std::runtime_error(std::string(Value::to_string(ctx, val))), m_value(ctx, val) {} - operator TValue() const { + operator ValueType() const { return m_value; } - static TValue value(TContext ctx, const std::string &message); + static ValueType value(ContextType ctx, const std::string &message); - static TValue value(TContext ctx, const std::exception &exp) { + static ValueType value(ContextType ctx, const std::exception &exp) { if (const Exception *js_exp = dynamic_cast *>(&exp)) { return *js_exp; } @@ -270,9 +270,9 @@ struct Exception : public std::runtime_error { template struct ReturnValue { - using TValue = typename T::Value; + using ValueType = typename T::Value; - void set(const TValue &); + void set(const ValueType &); void set(const std::string &); void set(bool); void set(double);