mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-17 09:06:26 +00:00
compact property getter/setter types
This commit is contained in:
parent
0b2a75bdc3
commit
84559316d8
@ -33,41 +33,30 @@ using ConstructorType = void(typename T::Context, typename T::Object, size_t, co
|
||||
template<typename T>
|
||||
using MethodType = void(typename T::Context, typename T::Object, size_t, const typename T::Value[], ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
using PropertyGetterType = void(typename T::Context, typename T::Object, ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
using PropertySetterType = void(typename T::Context, typename T::Object, typename T::Value);
|
||||
|
||||
template<typename T>
|
||||
using IndexPropertyGetterType = void(typename T::Context, typename T::Object, uint32_t, ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
using IndexPropertySetterType = bool(typename T::Context, typename T::Object, uint32_t, typename T::Value);
|
||||
|
||||
template<typename T>
|
||||
using StringPropertyGetterType = void(typename T::Context, typename T::Object, const String<T> &, ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
using StringPropertySetterType = bool(typename T::Context, typename T::Object, const String<T> &, typename T::Value);
|
||||
|
||||
template<typename T>
|
||||
using StringPropertyEnumeratorType = std::vector<String<T>>(typename T::Context, typename T::Object);
|
||||
|
||||
template<typename T>
|
||||
struct PropertyType {
|
||||
using GetterType = void(typename T::Context, typename T::Object, ReturnValue<T> &);
|
||||
using SetterType = void(typename T::Context, typename T::Object, typename T::Value);
|
||||
|
||||
typename T::PropertyGetterCallback getter;
|
||||
typename T::PropertySetterCallback setter;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct IndexPropertyType {
|
||||
using GetterType = void(typename T::Context, typename T::Object, uint32_t, ReturnValue<T> &);
|
||||
using SetterType = bool(typename T::Context, typename T::Object, uint32_t, typename T::Value);
|
||||
|
||||
typename T::IndexPropertyGetterCallback getter;
|
||||
typename T::IndexPropertySetterCallback setter;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct StringPropertyType {
|
||||
using GetterType = void(typename T::Context, typename T::Object, const String<T> &, ReturnValue<T> &);
|
||||
using SetterType = bool(typename T::Context, typename T::Object, const String<T> &, typename T::Value);
|
||||
using EnumeratorType = std::vector<String<T>>(typename T::Context, typename T::Object);
|
||||
|
||||
typename T::StringPropertyGetterCallback getter;
|
||||
typename T::StringPropertySetterCallback setter;
|
||||
typename T::StringPropertyEnumeratorCallback enumerator;
|
||||
|
@ -26,14 +26,13 @@ namespace realm {
|
||||
namespace js {
|
||||
|
||||
template<typename T>
|
||||
class NativeAccessor {
|
||||
struct NativeAccessor {
|
||||
using TContext = typename T::Context;
|
||||
using TObject = typename T::Object;
|
||||
using TValue = typename T::Value;
|
||||
using Object = Object<T>;
|
||||
using Value = Value<T>;
|
||||
|
||||
public:
|
||||
static bool dict_has_value_for_key(TContext ctx, TValue dict, const std::string &prop_name) {
|
||||
TObject object = Value::validated_to_object(ctx, dict);
|
||||
return Object::has_property(ctx, object, prop_name);
|
||||
|
@ -31,13 +31,9 @@ using ObjectClass = js::ObjectClass<Types, T>;
|
||||
using BaseObjectClass = js::BaseObjectClass<Types>;
|
||||
using ConstructorType = js::ConstructorType<Types>;
|
||||
using MethodType = js::MethodType<Types>;
|
||||
using PropertyGetterType = js::PropertyGetterType<Types>;
|
||||
using PropertySetterType = js::PropertySetterType<Types>;
|
||||
using IndexPropertyGetterType = js::IndexPropertyGetterType<Types>;
|
||||
using IndexPropertySetterType = js::IndexPropertySetterType<Types>;
|
||||
using StringPropertyGetterType = js::StringPropertyGetterType<Types>;
|
||||
using StringPropertySetterType = js::StringPropertySetterType<Types>;
|
||||
using StringPropertyEnumeratorType = js::StringPropertyEnumeratorType<Types>;
|
||||
using PropertyType = js::PropertyType<Types>;
|
||||
using IndexPropertyType = js::IndexPropertyType<Types>;
|
||||
using StringPropertyType = js::StringPropertyType<Types>;
|
||||
using MethodMap = js::MethodMap<Types>;
|
||||
using PropertyMap = js::PropertyMap<Types>;
|
||||
|
||||
@ -314,7 +310,7 @@ JSValueRef wrap(JSContextRef ctx, JSObjectRef function, JSObjectRef this_object,
|
||||
return return_value;
|
||||
}
|
||||
|
||||
template<jsc::PropertyGetterType F>
|
||||
template<jsc::PropertyType::GetterType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception) {
|
||||
jsc::ReturnValue return_value(ctx);
|
||||
try {
|
||||
@ -326,7 +322,7 @@ JSValueRef wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSVa
|
||||
return return_value;
|
||||
}
|
||||
|
||||
template<jsc::PropertySetterType F>
|
||||
template<jsc::PropertyType::SetterType F>
|
||||
bool wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef* exception) {
|
||||
try {
|
||||
F(ctx, object, value);
|
||||
@ -338,7 +334,7 @@ bool wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef
|
||||
return false;
|
||||
}
|
||||
|
||||
template<jsc::IndexPropertyGetterType F>
|
||||
template<jsc::IndexPropertyType::GetterType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef object, uint32_t index, JSValueRef* exception) {
|
||||
jsc::ReturnValue return_value(ctx);
|
||||
try {
|
||||
@ -354,7 +350,7 @@ JSValueRef wrap(JSContextRef ctx, JSObjectRef object, uint32_t index, JSValueRef
|
||||
return return_value;
|
||||
}
|
||||
|
||||
template<jsc::IndexPropertySetterType F>
|
||||
template<jsc::IndexPropertyType::SetterType F>
|
||||
bool wrap(JSContextRef ctx, JSObjectRef object, uint32_t index, JSValueRef value, JSValueRef* exception) {
|
||||
try {
|
||||
return F(ctx, object, index, value);
|
||||
@ -365,7 +361,7 @@ bool wrap(JSContextRef ctx, JSObjectRef object, uint32_t index, JSValueRef value
|
||||
return false;
|
||||
}
|
||||
|
||||
template<jsc::StringPropertyGetterType F>
|
||||
template<jsc::StringPropertyType::GetterType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception) {
|
||||
jsc::ReturnValue return_value(ctx);
|
||||
try {
|
||||
@ -377,7 +373,7 @@ JSValueRef wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSVa
|
||||
return return_value;
|
||||
}
|
||||
|
||||
template<jsc::StringPropertySetterType F>
|
||||
template<jsc::StringPropertyType::SetterType F>
|
||||
bool wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef* exception) {
|
||||
try {
|
||||
return F(ctx, object, property, value);
|
||||
@ -388,7 +384,7 @@ bool wrap(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef
|
||||
return false;
|
||||
}
|
||||
|
||||
template<jsc::StringPropertyEnumeratorType F>
|
||||
template<jsc::StringPropertyType::EnumeratorType F>
|
||||
void wrap(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator) {
|
||||
auto names = F(ctx, object);
|
||||
for (auto &name : names) {
|
||||
|
@ -29,14 +29,9 @@ using ObjectClass = js::ObjectClass<Types, T>;
|
||||
|
||||
using ConstructorType = js::ConstructorType<Types>;
|
||||
using MethodType = js::MethodType<Types>;
|
||||
using PropertyGetterType = js::PropertyGetterType<Types>;
|
||||
using PropertySetterType = js::PropertySetterType<Types>;
|
||||
using IndexPropertyGetterType = js::IndexPropertyGetterType<Types>;
|
||||
using IndexPropertySetterType = js::IndexPropertySetterType<Types>;
|
||||
using StringPropertyGetterType = js::StringPropertyGetterType<Types>;
|
||||
using StringPropertySetterType = js::StringPropertySetterType<Types>;
|
||||
using StringPropertyEnumeratorType = js::StringPropertyEnumeratorType<Types>;
|
||||
using PropertyType = js::PropertyType<Types>;
|
||||
using IndexPropertyType = js::IndexPropertyType<Types>;
|
||||
using StringPropertyType = js::StringPropertyType<Types>;
|
||||
|
||||
static inline std::vector<v8::Local<v8::Value>> get_arguments(const Nan::FunctionCallbackInfo<v8::Value> &info) {
|
||||
int count = info.Length();
|
||||
@ -195,7 +190,7 @@ void wrap(Nan::NAN_METHOD_ARGS_TYPE info) {
|
||||
}
|
||||
}
|
||||
|
||||
template<node::PropertyGetterType F>
|
||||
Type::template<node::PropertyType::GetterType F>
|
||||
void wrap(v8::Local<v8::String> property, Nan::NAN_GETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
@ -207,7 +202,7 @@ void wrap(v8::Local<v8::String> property, Nan::NAN_GETTER_ARGS_TYPE info) {
|
||||
}
|
||||
}
|
||||
|
||||
template<node::PropertySetterType F>
|
||||
template<node::PropertyType::SetterType F>
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, Nan::NAN_SETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
@ -218,7 +213,7 @@ void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, Nan::NAN_S
|
||||
}
|
||||
}
|
||||
|
||||
template<node::IndexPropertyGetterType F>
|
||||
template<node::IndexPropertyType::GetterType F>
|
||||
void wrap(uint32_t index, Nan::NAN_INDEX_GETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
@ -230,7 +225,7 @@ void wrap(uint32_t index, Nan::NAN_INDEX_GETTER_ARGS_TYPE info) {
|
||||
}
|
||||
}
|
||||
|
||||
template<node::IndexPropertySetterType F>
|
||||
template<node::IndexPropertyType::SetterType F>
|
||||
void wrap(uint32_t index, v8::Local<v8::Value> value, Nan::NAN_INDEX_SETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
@ -241,7 +236,7 @@ void wrap(uint32_t index, v8::Local<v8::Value> value, Nan::NAN_INDEX_SETTER_ARGS
|
||||
}
|
||||
}
|
||||
|
||||
template<node::StringPropertyGetterType F>
|
||||
template<node::StringPropertyType::GetterType F>
|
||||
void wrap(v8::Local<v8::String> property, Nan::NAN_PROPERTY_GETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
@ -253,7 +248,7 @@ void wrap(v8::Local<v8::String> property, Nan::NAN_PROPERTY_GETTER_ARGS_TYPE inf
|
||||
}
|
||||
}
|
||||
|
||||
template<node::StringPropertySetterType F>
|
||||
template<node::StringPropertyType::SetterType F>
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, Nan::NAN_PROPERTY_SETTER_ARGS_TYPE info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
@ -264,7 +259,7 @@ void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, Nan::NAN_P
|
||||
}
|
||||
}
|
||||
|
||||
template<node::StringPropertyEnumeratorType F>
|
||||
template<node::StringPropertyType::EnumeratorType F>
|
||||
void wrap(Nan::NAN_PROPERTY_ENUMERATOR_ARGS_TYPE info) {
|
||||
auto names = F(info.GetIsolate(), info.This());
|
||||
int count = (int)names.size();
|
||||
|
Loading…
x
Reference in New Issue
Block a user