Revert "Fix Node.js 10 support (#1937)"
This reverts commit b5d7d8ceab
.
This commit is contained in:
parent
f1c9f8fe88
commit
5de2600133
File diff suppressed because it is too large
Load Diff
|
@ -83,7 +83,7 @@
|
|||
"deepmerge": "2.1.0",
|
||||
"fs-extra": "^4.0.2",
|
||||
"ini": "^1.3.4",
|
||||
"nan": "^2.10.0",
|
||||
"nan": "2.8.0",
|
||||
"node-fetch": "^1.6.3",
|
||||
"node-pre-gyp": "^0.6.36",
|
||||
"progress": "^2.0.0",
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
namespace realm {
|
||||
namespace js {
|
||||
|
||||
template<typename T>
|
||||
using ConstructorType = void(typename T::Context, typename T::Object, size_t, const typename T::Value[]);
|
||||
|
||||
template<typename T>
|
||||
using MethodType = void(typename T::Context, typename T::Function, typename T::Object, size_t, const typename T::Value[], ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
struct Arguments {
|
||||
const typename T::Context ctx;
|
||||
|
@ -46,24 +52,15 @@ struct Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
void validate_count(size_t expected) const {
|
||||
if (count != expected) {
|
||||
throw std::invalid_argument(util::format("Invalid arguments: %1 expected, but %2 supplied.", expected, count));
|
||||
}
|
||||
}
|
||||
|
||||
void validate_between(size_t min, size_t max) const {
|
||||
if (count < min || count > max) {
|
||||
throw std::invalid_argument(util::format("Invalid arguments: expected between %1 and %2, but %3 supplied.", min, max, count));
|
||||
void validate_count(size_t actual) const {
|
||||
if (count != actual) {
|
||||
throw std::invalid_argument(util::format("Invalid arguments: %1 expected, but %s supplied.", actual, count));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using ConstructorType = void(typename T::Context, typename T::Object, Arguments<T> &);
|
||||
|
||||
template<typename T>
|
||||
using ArgumentsMethodType = void(typename T::Context, typename T::Object, Arguments<T> &, ReturnValue<T> &);
|
||||
using ArgumentsMethodType = void(typename T::Context, typename T::Object, Arguments<T>, ReturnValue<T> &);
|
||||
|
||||
template<typename T>
|
||||
struct PropertyType {
|
||||
|
|
|
@ -65,22 +65,22 @@ struct ListClass : ClassDefinition<T, realm::js::List<T>, CollectionClass<T>> {
|
|||
static bool set_index(ContextType, ObjectType, uint32_t, ValueType);
|
||||
|
||||
// methods
|
||||
static void push(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void pop(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void unshift(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void shift(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void splice(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void snapshot(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void filtered(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void sorted(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_valid(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_empty(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void index_of(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void push(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void pop(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void unshift(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void shift(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void splice(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void snapshot(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void filtered(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void sorted(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void is_valid(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void is_empty(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void index_of(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
// observable
|
||||
static void add_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void add_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
std::string const name = "List";
|
||||
|
||||
|
@ -157,7 +157,7 @@ bool ListClass<T>::set_index(ContextType ctx, ObjectType object, uint32_t index,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::push(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::push(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
for (size_t i = 0; i < args.count; i++) {
|
||||
validate_value(ctx, *list, args[i]);
|
||||
|
@ -172,7 +172,7 @@ void ListClass<T>::push(ContextType ctx, ObjectType this_object, Arguments &args
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::pop(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::pop(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
|
@ -188,7 +188,7 @@ void ListClass<T>::pop(ContextType ctx, ObjectType this_object, Arguments &args,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::unshift(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::unshift(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
for (size_t i = 0; i < args.count; i++) {
|
||||
validate_value(ctx, *list, args[i]);
|
||||
|
@ -203,7 +203,7 @@ void ListClass<T>::unshift(ContextType ctx, ObjectType this_object, Arguments &a
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::shift(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::shift(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
|
@ -218,7 +218,7 @@ void ListClass<T>::shift(ContextType ctx, ObjectType this_object, Arguments &arg
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::splice(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::splice(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
size_t size = list->size();
|
||||
long index = std::min<long>(Value::to_number(ctx, args[0]), size);
|
||||
|
@ -251,36 +251,36 @@ void ListClass<T>::splice(ContextType ctx, ObjectType this_object, Arguments &ar
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::snapshot(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::snapshot(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
return_value.set(ResultsClass<T>::create_instance(ctx, list->snapshot()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::filtered(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::filtered(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
return_value.set(ResultsClass<T>::create_filtered(ctx, *list, args));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::sorted(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::sorted(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
return_value.set(ResultsClass<T>::create_instance(ctx, list->sort(ResultsClass<T>::get_keypaths(ctx, args))));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::is_valid(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::is_valid(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
return_value.set(get_internal<T, ListClass<T>>(this_object)->is_valid());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::is_empty(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::is_empty(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
return_value.set(get_internal<T, ListClass<T>>(this_object)->size() == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::index_of(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::index_of(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto fn = [&](auto&& row) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
NativeAccessor<T> accessor(ctx, *list);
|
||||
|
@ -290,19 +290,19 @@ void ListClass<T>::index_of(ContextType ctx, ObjectType this_object, Arguments &
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
ResultsClass<T>::add_listener(ctx, *list, this_object, args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
ResultsClass<T>::remove_listener(ctx, *list, this_object, args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ListClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
auto list = get_internal<T, ListClass<T>>(this_object);
|
||||
list->m_notification_tokens.clear();
|
||||
|
|
102
src/js_realm.hpp
102
src/js_realm.hpp
|
@ -218,25 +218,25 @@ public:
|
|||
static FunctionType create_constructor(ContextType);
|
||||
|
||||
// methods
|
||||
static void objects(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void object_for_primary_key(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void create(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void delete_one(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void delete_all(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void write(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void begin_transaction(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void commit_transaction(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void cancel_transaction(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void add_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void wait_for_download_completion(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void close(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void compact(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void writeCopyTo(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void delete_model(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void object_for_object_id(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void privileges(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void objects(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void object_for_primary_key(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void create(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void delete_one(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void delete_all(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void write(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void begin_transaction(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
static void commit_transaction(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
static void cancel_transaction(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
static void add_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void wait_for_download_completion(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void close(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void compact(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void writeCopyTo(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void delete_model(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void object_for_object_id(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
static void privileges(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
|
||||
// properties
|
||||
static void get_empty(ContextType, ObjectType, ReturnValue &);
|
||||
|
@ -252,13 +252,13 @@ public:
|
|||
#endif
|
||||
|
||||
// static methods
|
||||
static void constructor(ContextType, ObjectType, Arguments &);
|
||||
static void constructor(ContextType, ObjectType, size_t, const ValueType[]);
|
||||
static SharedRealm create_shared_realm(ContextType, realm::Realm::Config, bool, ObjectDefaultsMap &&, ConstructorMap &&);
|
||||
|
||||
static void schema_version(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void clear_test_state(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void copy_bundled_realm_files(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void delete_file(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void schema_version(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void clear_test_state(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void copy_bundled_realm_files(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void delete_file(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
// static properties
|
||||
static void get_default_path(ContextType, ObjectType, ReturnValue &);
|
||||
|
@ -434,17 +434,17 @@ static inline void convert_outdated_datetime_columns(const SharedRealm &realm) {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::constructor(ContextType ctx, ObjectType this_object, Arguments &args) {
|
||||
void RealmClass<T>::constructor(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[]) {
|
||||
realm::Realm::Config config;
|
||||
ObjectDefaultsMap defaults;
|
||||
ConstructorMap constructors;
|
||||
bool schema_updated = false;
|
||||
|
||||
if (args.count == 0) {
|
||||
if (argc == 0) {
|
||||
config.path = default_path();
|
||||
}
|
||||
else if (args.count == 1) {
|
||||
ValueType value = args[0];
|
||||
else if (argc == 1) {
|
||||
ValueType value = arguments[0];
|
||||
if (Value::is_string(ctx, value)) {
|
||||
config.path = Value::validated_to_string(ctx, value, "path");
|
||||
}
|
||||
|
@ -628,7 +628,7 @@ SharedRealm RealmClass<T>::create_shared_realm(ContextType ctx, realm::Realm::Co
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::schema_version(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::schema_version(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
realm::Realm::Config config;
|
||||
|
@ -649,19 +649,19 @@ void RealmClass<T>::schema_version(ContextType ctx, ObjectType this_object, Argu
|
|||
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
js::clear_test_state();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::copy_bundled_realm_files(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::copy_bundled_realm_files(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
realm::copy_bundled_realm_files();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::delete_file(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::delete_file(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
ValueType value = args[0];
|
||||
|
@ -692,7 +692,7 @@ void RealmClass<T>::delete_file(ContextType ctx, ObjectType this_object, Argumen
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::delete_model(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::delete_model(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
ValueType value = args[0];
|
||||
|
||||
|
@ -772,7 +772,7 @@ void RealmClass<T>::get_sync_session(ContextType ctx, ObjectType object, ReturnV
|
|||
|
||||
#if REALM_ENABLE_SYNC
|
||||
template<typename T>
|
||||
void RealmClass<T>::wait_for_download_completion(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::wait_for_download_completion(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
auto callback_function = Value::validated_to_function(ctx, args[0 + (args.count == 2)]);
|
||||
|
||||
|
@ -840,7 +840,7 @@ void RealmClass<T>::wait_for_download_completion(ContextType ctx, ObjectType thi
|
|||
#endif
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::objects(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::objects(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -849,7 +849,7 @@ void RealmClass<T>::objects(ContextType ctx, ObjectType this_object, Arguments &
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::object_for_primary_key(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::object_for_primary_key(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -867,7 +867,7 @@ void RealmClass<T>::object_for_primary_key(ContextType ctx, ObjectType this_obje
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::create(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::create(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(3);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -890,7 +890,7 @@ void RealmClass<T>::create(ContextType ctx, ObjectType this_object, Arguments &a
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::delete_one(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::delete_one(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -938,7 +938,7 @@ void RealmClass<T>::delete_one(ContextType ctx, ObjectType this_object, Argument
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::delete_all(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::delete_all(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -960,7 +960,7 @@ void RealmClass<T>::delete_all(ContextType ctx, ObjectType this_object, Argument
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::write(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::write(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -980,7 +980,7 @@ void RealmClass<T>::write(ContextType ctx, ObjectType this_object, Arguments &ar
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::begin_transaction(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::begin_transaction(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -988,7 +988,7 @@ void RealmClass<T>::begin_transaction(ContextType ctx, ObjectType this_object, A
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::commit_transaction(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::commit_transaction(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -996,7 +996,7 @@ void RealmClass<T>::commit_transaction(ContextType ctx, ObjectType this_object,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::cancel_transaction(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::cancel_transaction(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -1004,7 +1004,7 @@ void RealmClass<T>::cancel_transaction(ContextType ctx, ObjectType this_object,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
auto name = validated_notification_name(ctx, args[0]);
|
||||
|
@ -1021,7 +1021,7 @@ void RealmClass<T>::add_listener(ContextType ctx, ObjectType this_object, Argume
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
auto name = validated_notification_name(ctx, args[0]);
|
||||
|
@ -1038,7 +1038,7 @@ void RealmClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arg
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
std::string name = "change";
|
||||
if (args.count) {
|
||||
|
@ -1056,7 +1056,7 @@ void RealmClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::close(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::close(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -1064,7 +1064,7 @@ void RealmClass<T>::close(ContextType ctx, ObjectType this_object, Arguments &ar
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::compact(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::compact(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||
|
@ -1076,7 +1076,7 @@ void RealmClass<T>::compact(ContextType ctx, ObjectType this_object, Arguments &
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::writeCopyTo(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::writeCopyTo(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
if (args.count == 0) {
|
||||
|
@ -1106,7 +1106,7 @@ void RealmClass<T>::writeCopyTo(ContextType ctx, ObjectType this_object, Argumen
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::object_for_object_id(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue& return_value) {
|
||||
void RealmClass<T>::object_for_object_id(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue& return_value) {
|
||||
args.validate_count(2);
|
||||
|
||||
#if REALM_ENABLE_SYNC
|
||||
|
@ -1129,7 +1129,7 @@ void RealmClass<T>::object_for_object_id(ContextType ctx, ObjectType this_object
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmClass<T>::privileges(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void RealmClass<T>::privileges(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
using Privilege = realm::ComputedPrivileges;
|
||||
|
|
|
@ -50,13 +50,13 @@ struct RealmObjectClass : ClassDefinition<T, realm::Object> {
|
|||
static bool set_property(ContextType, ObjectType, const String &, ValueType);
|
||||
static std::vector<String> get_property_names(ContextType, ObjectType);
|
||||
|
||||
static void is_valid(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void get_object_schema(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void linking_objects(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void linking_objects_count(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void get_object_id(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_same_object(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void set_link(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_valid(ContextType, FunctionType, ObjectType, size_t, const ValueType [], ReturnValue &);
|
||||
static void get_object_schema(ContextType, FunctionType, ObjectType, size_t, const ValueType [], ReturnValue &);
|
||||
static void linking_objects(ContextType, FunctionType, ObjectType, size_t, const ValueType [], ReturnValue &);
|
||||
static void linking_objects_count(ContextType, FunctionType, ObjectType, size_t, const ValueType [], ReturnValue &);
|
||||
static void get_object_id(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void is_same_object(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void set_link(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
const std::string name = "RealmObject";
|
||||
|
||||
|
@ -78,12 +78,12 @@ struct RealmObjectClass : ClassDefinition<T, realm::Object> {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::is_valid(ContextType, ObjectType this_object, Arguments &, ReturnValue &return_value) {
|
||||
void RealmObjectClass<T>::is_valid(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
return_value.set(get_internal<T, RealmObjectClass<T>>(this_object)->is_valid());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::get_object_schema(ContextType ctx, ObjectType this_object, Arguments &, ReturnValue &return_value) {
|
||||
void RealmObjectClass<T>::get_object_schema(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
auto object = get_internal<T, RealmObjectClass<T>>(this_object);
|
||||
return_value.set(Schema<T>::object_for_object_schema(ctx, object->get_object_schema()));
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ bool RealmObjectClass<T>::set_property(ContextType ctx, ObjectType object, const
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::set_link(ContextType ctx, ObjectType object, Arguments &args, ReturnValue& return_value) {
|
||||
void RealmObjectClass<T>::set_link(ContextType ctx, ObjectType object, Arguments args, ReturnValue& return_value) {
|
||||
args.validate_count(2);
|
||||
|
||||
auto realm_object = get_internal<T, RealmObjectClass<T>>(object);
|
||||
|
@ -208,7 +208,7 @@ std::vector<String<T>> RealmObjectClass<T>::get_property_names(ContextType ctx,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::get_object_id(ContextType ctx, ObjectType object, Arguments &args, ReturnValue& return_value) {
|
||||
void RealmObjectClass<T>::get_object_id(ContextType ctx, ObjectType object, Arguments args, ReturnValue& return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
#if REALM_ENABLE_SYNC
|
||||
|
@ -226,7 +226,7 @@ void RealmObjectClass<T>::get_object_id(ContextType ctx, ObjectType object, Argu
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::is_same_object(ContextType ctx, ObjectType object, Arguments &args, ReturnValue& return_value) {
|
||||
void RealmObjectClass<T>::is_same_object(ContextType ctx, ObjectType object, Arguments args, ReturnValue& return_value) {
|
||||
args.validate_count(1);
|
||||
|
||||
ObjectType otherObject = Value::validated_to_object(ctx, args[0]);
|
||||
|
@ -253,7 +253,7 @@ void RealmObjectClass<T>::is_same_object(ContextType ctx, ObjectType object, Arg
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void RealmObjectClass<T>::linking_objects_count(ContextType, ObjectType object, Arguments &, ReturnValue &return_value) {
|
||||
void RealmObjectClass<T>::linking_objects_count(ContextType ctx, FunctionType, ObjectType object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
auto realm_object = get_internal<T, RealmObjectClass<T>>(object);
|
||||
const Row& row = realm_object->row();
|
||||
|
||||
|
@ -268,11 +268,11 @@ void RealmObjectClass<T>::linking_objects_count(ContextType, ObjectType object,
|
|||
#include "js_results.hpp"
|
||||
|
||||
template<typename T>
|
||||
void realm::js::RealmObjectClass<T>::linking_objects(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(2);
|
||||
void realm::js::RealmObjectClass<T>::linking_objects(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 2);
|
||||
|
||||
std::string object_type = Value::validated_to_string(ctx, args[0], "objectType");
|
||||
std::string property_name = Value::validated_to_string(ctx, args[1], "property");
|
||||
std::string object_type = Value::validated_to_string(ctx, arguments[0], "objectType");
|
||||
std::string property_name = Value::validated_to_string(ctx, arguments[1], "property");
|
||||
|
||||
auto object = get_internal<T, RealmObjectClass<T>>(this_object);
|
||||
|
||||
|
|
|
@ -74,40 +74,40 @@ struct ResultsClass : ClassDefinition<T, realm::js::Results<T>, CollectionClass<
|
|||
static ObjectType create_instance(ContextType, SharedRealm, const std::string &object_type);
|
||||
|
||||
template<typename U>
|
||||
static ObjectType create_filtered(ContextType, const U &, Arguments &);
|
||||
static ObjectType create_filtered(ContextType, const U &, Arguments);
|
||||
|
||||
static std::vector<std::pair<std::string, bool>> get_keypaths(ContextType, Arguments &);
|
||||
static std::vector<std::pair<std::string, bool>> get_keypaths(ContextType, Arguments);
|
||||
|
||||
static void get_length(ContextType, ObjectType, ReturnValue &);
|
||||
static void get_type(ContextType, ObjectType, ReturnValue &);
|
||||
static void get_optional(ContextType, ObjectType, ReturnValue &);
|
||||
static void get_index(ContextType, ObjectType, uint32_t, ReturnValue &);
|
||||
|
||||
static void snapshot(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void filtered(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void sorted(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_valid(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void is_empty(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void snapshot(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void filtered(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void sorted(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void is_valid(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void is_empty(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
#if REALM_ENABLE_SYNC
|
||||
static void subscribe(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void subscribe(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
#endif
|
||||
|
||||
static void index_of(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void index_of(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
template<typename Fn>
|
||||
static void index_of(ContextType, Fn&, Arguments &, ReturnValue &);
|
||||
static void index_of(ContextType, Fn&, Arguments, ReturnValue &);
|
||||
|
||||
static void update(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void update(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
|
||||
// observable
|
||||
static void add_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void add_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
template<typename U>
|
||||
static void add_listener(ContextType, U&, ObjectType, Arguments &);
|
||||
static void add_listener(ContextType, U&, ObjectType, Arguments);
|
||||
template<typename U>
|
||||
static void remove_listener(ContextType, U&, ObjectType, Arguments &);
|
||||
static void remove_listener(ContextType, U&, ObjectType, Arguments);
|
||||
|
||||
std::string const name = "Results";
|
||||
|
||||
|
@ -171,7 +171,7 @@ inline void alias_backlinks(parser::KeyPathMapping &mapping, const realm::Shared
|
|||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
typename T::Object ResultsClass<T>::create_filtered(ContextType ctx, const U &collection, Arguments &args) {
|
||||
typename T::Object ResultsClass<T>::create_filtered(ContextType ctx, const U &collection, Arguments args) {
|
||||
if (collection.get_type() != realm::PropertyType::Object) {
|
||||
throw std::runtime_error("Filtering non-object Lists and Results is not yet implemented.");
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ typename T::Object ResultsClass<T>::create_filtered(ContextType ctx, const U &co
|
|||
|
||||
template<typename T>
|
||||
std::vector<std::pair<std::string, bool>>
|
||||
ResultsClass<T>::get_keypaths(ContextType ctx, Arguments &args) {
|
||||
ResultsClass<T>::get_keypaths(ContextType ctx, Arguments args) {
|
||||
args.validate_maximum(2);
|
||||
|
||||
std::vector<std::pair<std::string, bool>> sort_order;
|
||||
|
@ -262,37 +262,37 @@ void ResultsClass<T>::get_index(ContextType ctx, ObjectType object, uint32_t ind
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::snapshot(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::snapshot(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
return_value.set(ResultsClass<T>::create_instance(ctx, results->snapshot()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::filtered(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::filtered(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
return_value.set(create_filtered(ctx, *results, args));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::sorted(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::sorted(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
return_value.set(ResultsClass<T>::create_instance(ctx, results->sort(ResultsClass<T>::get_keypaths(ctx, args))));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::is_valid(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::is_valid(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
return_value.set(get_internal<T, ResultsClass<T>>(this_object)->is_valid());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::is_empty(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::is_empty(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
return_value.set(get_internal<T, ResultsClass<T>>(this_object)->size() == 0);
|
||||
}
|
||||
|
||||
#if REALM_ENABLE_SYNC
|
||||
template<typename T>
|
||||
void ResultsClass<T>::subscribe(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::subscribe(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
|
@ -314,7 +314,7 @@ void ResultsClass<T>::subscribe(ContextType ctx, ObjectType this_object, Argumen
|
|||
|
||||
template<typename T>
|
||||
template<typename Fn>
|
||||
void ResultsClass<T>::index_of(ContextType ctx, Fn& fn, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::index_of(ContextType ctx, Fn& fn, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
size_t ndx;
|
||||
|
@ -337,10 +337,10 @@ void ResultsClass<T>::index_of(ContextType ctx, Fn& fn, Arguments &args, ReturnV
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::update(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_maximum(2);
|
||||
void ResultsClass<T>::update(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 2);
|
||||
|
||||
std::string property = Value::validated_to_string(ctx, args[0], "property");
|
||||
std::string property = Value::validated_to_string(ctx, arguments[0], "property");
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
|
||||
auto schema = results->get_object_schema();
|
||||
|
@ -358,13 +358,13 @@ void ResultsClass<T>::update(ContextType ctx, ObjectType this_object, Arguments
|
|||
for (auto i = results->size(); i > 0; i--) {
|
||||
auto realm_object = realm::Object(realm, schema, results->get(i - 1));
|
||||
auto obj = RealmObjectClass<T>::create_instance(ctx, realm_object);
|
||||
RealmObjectClass<T>::set_property(ctx, obj, property, args[1]);
|
||||
RealmObjectClass<T>::set_property(ctx, obj, property, arguments[1]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::index_of(ContextType ctx, ObjectType this_object,
|
||||
Arguments &args, ReturnValue &return_value) {
|
||||
Arguments args, ReturnValue &return_value) {
|
||||
auto fn = [&](auto&& row) {
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
NativeAccessor<T> accessor(ctx, *results);
|
||||
|
@ -375,7 +375,7 @@ void ResultsClass<T>::index_of(ContextType ctx, ObjectType this_object,
|
|||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void ResultsClass<T>::add_listener(ContextType ctx, U& collection, ObjectType this_object, Arguments &args) {
|
||||
void ResultsClass<T>::add_listener(ContextType ctx, U& collection, ObjectType this_object, Arguments args) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
auto callback = Value::validated_to_function(ctx, args[0]);
|
||||
|
@ -395,14 +395,14 @@ void ResultsClass<T>::add_listener(ContextType ctx, U& collection, ObjectType th
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
add_listener(ctx, *results, this_object, args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void ResultsClass<T>::remove_listener(ContextType ctx, U& collection, ObjectType this_object, Arguments &args) {
|
||||
void ResultsClass<T>::remove_listener(ContextType ctx, U& collection, ObjectType this_object, Arguments args) {
|
||||
args.validate_maximum(1);
|
||||
|
||||
auto callback = Value::validated_to_function(ctx, args[0]);
|
||||
|
@ -416,13 +416,13 @@ void ResultsClass<T>::remove_listener(ContextType ctx, U& collection, ObjectType
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
remove_listener(ctx, *results, this_object, args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ResultsClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void ResultsClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
|
||||
auto results = get_internal<T, ResultsClass<T>>(this_object);
|
||||
|
|
128
src/js_sync.hpp
128
src/js_sync.hpp
|
@ -89,9 +89,9 @@ public:
|
|||
{"isAdminToken", {wrap<is_admin_token>, nullptr}},
|
||||
};
|
||||
|
||||
static void create_user(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void admin_user(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void get_existing_user(ContextType, ObjectType, Arguments &, ReturnValue&);
|
||||
static void create_user(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void admin_user(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void get_existing_user(ContextType, ObjectType, Arguments, ReturnValue&);
|
||||
|
||||
MethodMap<T> const static_methods = {
|
||||
{"createUser", wrap<create_user>},
|
||||
|
@ -100,15 +100,15 @@ public:
|
|||
};
|
||||
|
||||
/*static void current_user(ContextType ctx, ObjectType object, ReturnValue &return_value);*/
|
||||
static void all_users(ContextType ctx, ObjectType object, ReturnValue &);
|
||||
static void all_users(ContextType ctx, ObjectType object, ReturnValue &return_value);
|
||||
|
||||
PropertyMap<T> const static_properties = {
|
||||
/*{"current", {wrap<current_user>, nullptr}},*/
|
||||
{"all", {wrap<all_users>, nullptr}},
|
||||
};
|
||||
|
||||
static void logout(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void session_for_on_disk_path(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void logout(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void session_for_on_disk_path(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
|
||||
MethodMap<T> const methods = {
|
||||
{"_logout", wrap<logout>},
|
||||
|
@ -145,39 +145,39 @@ void UserClass<T>::is_admin_token(ContextType ctx, ObjectType object, ReturnValu
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_between(3, 5);
|
||||
void UserClass<T>::create_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 3, 5);
|
||||
SyncUserIdentifier userIdentifier {
|
||||
Value::validated_to_string(ctx, args[1], "identity"),
|
||||
Value::validated_to_string(ctx, args[0], "authServerUrl")
|
||||
Value::validated_to_string(ctx, arguments[1], "identity"),
|
||||
Value::validated_to_string(ctx, arguments[0], "authServerUrl")
|
||||
};
|
||||
SharedUser *user = new SharedUser(syncManagerShared().get_user(
|
||||
userIdentifier,
|
||||
Value::validated_to_string(ctx, args[2], "refreshToken")
|
||||
Value::validated_to_string(ctx, arguments[2], "refreshToken")
|
||||
));
|
||||
|
||||
if (args.count == 5) {
|
||||
(*user)->set_is_admin(Value::validated_to_boolean(ctx, args[4], "isAdmin"));
|
||||
if (argc == 5) {
|
||||
(*user)->set_is_admin(Value::validated_to_boolean(ctx, arguments[4], "isAdmin"));
|
||||
}
|
||||
return_value.set(create_object<T, UserClass<T>>(ctx, user));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::admin_user(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(2);
|
||||
void UserClass<T>::admin_user(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 2, 2);
|
||||
SharedUser *user = new SharedUser(syncManagerShared().get_admin_token_user(
|
||||
Value::validated_to_string(ctx, args[0], "authServerUrl"),
|
||||
Value::validated_to_string(ctx, args[1], "refreshToken")
|
||||
Value::validated_to_string(ctx, arguments[0], "authServerUrl"),
|
||||
Value::validated_to_string(ctx, arguments[1], "refreshToken")
|
||||
));
|
||||
return_value.set(create_object<T, UserClass<T>>(ctx, user));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::get_existing_user(ContextType ctx, ObjectType, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(2);
|
||||
void UserClass<T>::get_existing_user(ContextType ctx, ObjectType, Arguments arguments, ReturnValue& return_value) {
|
||||
arguments.validate_count(2);
|
||||
if (auto user = syncManagerShared().get_existing_logged_in_user(SyncUserIdentifier{
|
||||
Value::validated_to_string(ctx, args[1], "identity"),
|
||||
Value::validated_to_string(ctx, args[0], "authServerUrl")})) {
|
||||
Value::validated_to_string(ctx, arguments[1], "identity"),
|
||||
Value::validated_to_string(ctx, arguments[0], "authServerUrl")})) {
|
||||
return_value.set(create_object<T, UserClass<T>>(ctx, new SharedUser(std::move(user))));
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &re
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::logout(ContextType, ObjectType this_object, Arguments &, ReturnValue &) {
|
||||
void UserClass<T>::logout(ContextType ctx, FunctionType, ObjectType this_object, size_t, const ValueType[], ReturnValue &) {
|
||||
get_internal<T, UserClass<T>>(this_object)->get()->log_out();
|
||||
}
|
||||
|
||||
|
@ -221,12 +221,12 @@ public:
|
|||
static void get_url(ContextType, ObjectType, ReturnValue &);
|
||||
static void get_state(ContextType, ObjectType, ReturnValue &);
|
||||
|
||||
static void simulate_error(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void refresh_access_token(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void add_progress_notification(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_progress_notification(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void simulate_error(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void refresh_access_token(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
||||
static void remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
|
||||
|
||||
static void override_server(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&);
|
||||
|
||||
PropertyMap<T> const properties = {
|
||||
{"config", {wrap<get_config>, nullptr}},
|
||||
|
@ -383,10 +383,9 @@ private:
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::session_for_on_disk_path(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(1);
|
||||
void UserClass<T>::session_for_on_disk_path(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
auto user = *get_internal<T, UserClass<T>>(this_object);
|
||||
if (auto session = user->session_for_on_disk_path(Value::validated_to_string(ctx, args[0]))) {
|
||||
if (auto session = user->session_for_on_disk_path(Value::validated_to_string(ctx, arguments[0]))) {
|
||||
return_value.set(create_object<T, SessionClass<T>>(ctx, new WeakSession(session)));
|
||||
} else {
|
||||
return_value.set_undefined();
|
||||
|
@ -456,38 +455,38 @@ void SessionClass<T>::get_state(ContextType ctx, ObjectType object, ReturnValue
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SessionClass<T>::simulate_error(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &) {
|
||||
args.validate_count(2);
|
||||
void SessionClass<T>::simulate_error(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &) {
|
||||
validate_argument_count(argc, 2);
|
||||
|
||||
if (auto session = get_internal<T, SessionClass<T>>(this_object)->lock()) {
|
||||
std::error_code error_code(Value::validated_to_number(ctx, args[0]), realm::sync::protocol_error_category());
|
||||
std::string message = Value::validated_to_string(ctx, args[1]);
|
||||
std::error_code error_code(Value::validated_to_number(ctx, arguments[0]), realm::sync::protocol_error_category());
|
||||
std::string message = Value::validated_to_string(ctx, arguments[1]);
|
||||
SyncSession::OnlyForTesting::handle_error(*session, SyncError(error_code, message, false));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SessionClass<T>::refresh_access_token(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &) {
|
||||
args.validate_count(3);
|
||||
void SessionClass<T>::refresh_access_token(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &) {
|
||||
validate_argument_count(argc, 3);
|
||||
|
||||
if (auto session = get_internal<T, SessionClass<T>>(this_object)->lock()) {
|
||||
std::string sync_label = Value::validated_to_string(ctx, args[2], "syncLabel");
|
||||
std::string sync_label = Value::validated_to_string(ctx, arguments[2], "syncLabel");
|
||||
session->set_multiplex_identifier(std::move(sync_label));
|
||||
|
||||
std::string access_token = Value::validated_to_string(ctx, args[0], "accessToken");
|
||||
std::string realm_url = Value::validated_to_string(ctx, args[1], "realmUrl");
|
||||
std::string access_token = Value::validated_to_string(ctx, arguments[0], "accessToken");
|
||||
std::string realm_url = Value::validated_to_string(ctx, arguments[1], "realmUrl");
|
||||
session->refresh_access_token(std::move(access_token), std::move(realm_url));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SessionClass<T>::add_progress_notification(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(3);
|
||||
void SessionClass<T>::add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 3);
|
||||
|
||||
if (auto session = get_internal<T, SessionClass<T>>(this_object)->lock()) {
|
||||
|
||||
std::string direction = Value::validated_to_string(ctx, args[0], "direction");
|
||||
std::string mode = Value::validated_to_string(ctx, args[1], "mode");
|
||||
std::string direction = Value::validated_to_string(ctx, arguments[0], "direction");
|
||||
std::string mode = Value::validated_to_string(ctx, arguments[1], "mode");
|
||||
SyncSession::NotifierType notifierType;
|
||||
if (direction == "download") {
|
||||
notifierType = SyncSession::NotifierType::download;
|
||||
|
@ -510,7 +509,7 @@ void SessionClass<T>::add_progress_notification(ContextType ctx, ObjectType this
|
|||
throw std::invalid_argument("Invalid argument 'mode'. Only 'reportIndefinitely' and 'forCurrentlyOutstandingWork' progress notification modes are supported");
|
||||
}
|
||||
|
||||
auto callback_function = Value::validated_to_function(ctx, args[2], "callback");
|
||||
auto callback_function = Value::validated_to_function(ctx, arguments[2], "callback");
|
||||
|
||||
Protected<FunctionType> protected_callback(ctx, callback_function);
|
||||
Protected<ObjectType> protected_this(ctx, this_object);
|
||||
|
@ -537,9 +536,9 @@ void SessionClass<T>::add_progress_notification(ContextType ctx, ObjectType this
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SessionClass<T>::remove_progress_notification(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(1);
|
||||
auto callback_function = Value::validated_to_function(ctx, args[0], "callback");
|
||||
void SessionClass<T>::remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 1);
|
||||
auto callback_function = Value::validated_to_function(ctx, arguments[0], "callback");
|
||||
auto syncSessionProp = Object::get_property(ctx, callback_function, "_syncSession");
|
||||
if (Value::is_undefined(ctx, syncSessionProp) || Value::is_null(ctx, syncSessionProp)) {
|
||||
return;
|
||||
|
@ -555,7 +554,7 @@ void SessionClass<T>::remove_progress_notification(ContextType ctx, ObjectType t
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SessionClass<T>::override_server(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue&) {
|
||||
void SessionClass<T>::override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&) {
|
||||
args.validate_count(2);
|
||||
|
||||
std::string address = Value::validated_to_string(ctx, args[0], "address");
|
||||
|
@ -603,10 +602,10 @@ public:
|
|||
static void get_state(ContextType, ObjectType, ReturnValue &);
|
||||
static void get_error(ContextType, ObjectType, ReturnValue &);
|
||||
|
||||
static void unsubscribe(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void add_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void unsubscribe(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void add_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_listener(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
static void remove_all_listeners(ContextType, ObjectType, Arguments, ReturnValue &);
|
||||
|
||||
PropertyMap<T> const properties = {
|
||||
{"state", {wrap<get_state>, nullptr}},
|
||||
|
@ -649,7 +648,7 @@ void SubscriptionClass<T>::get_error(ContextType ctx, ObjectType object, ReturnV
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SubscriptionClass<T>::unsubscribe(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void SubscriptionClass<T>::unsubscribe(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
auto subscription = get_internal<T, SubscriptionClass<T>>(this_object);
|
||||
partial_sync::unsubscribe(*subscription);
|
||||
|
@ -657,7 +656,7 @@ void SubscriptionClass<T>::unsubscribe(ContextType ctx, ObjectType this_object,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SubscriptionClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void SubscriptionClass<T>::add_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
auto subscription = get_internal<T, SubscriptionClass<T>>(this_object);
|
||||
|
||||
|
@ -679,7 +678,7 @@ void SubscriptionClass<T>::add_listener(ContextType ctx, ObjectType this_object,
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SubscriptionClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void SubscriptionClass<T>::remove_listener(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(1);
|
||||
auto subscription = get_internal<T, SubscriptionClass<T>>(this_object);
|
||||
|
||||
|
@ -694,7 +693,7 @@ void SubscriptionClass<T>::remove_listener(ContextType ctx, ObjectType this_obje
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SubscriptionClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
void SubscriptionClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||
args.validate_maximum(0);
|
||||
auto subscription = get_internal<T, SubscriptionClass<T>>(this_object);
|
||||
subscription->m_notification_tokens.clear();
|
||||
|
@ -712,15 +711,14 @@ class SyncClass : public ClassDefinition<T, void*> {
|
|||
using Value = js::Value<T>;
|
||||
using Function = js::Function<T>;
|
||||
using ReturnValue = js::ReturnValue<T>;
|
||||
using Arguments = js::Arguments<T>;
|
||||
|
||||
public:
|
||||
std::string const name = "Sync";
|
||||
|
||||
static FunctionType create_constructor(ContextType);
|
||||
|
||||
static void set_sync_log_level(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void initiate_client_reset(ContextType, ObjectType, Arguments &, ReturnValue &);
|
||||
static void set_sync_log_level(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void initiate_client_reset(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
|
||||
// private
|
||||
static std::function<SyncBindSessionHandler> session_bind_callback(ContextType ctx, ObjectType sync_constructor);
|
||||
|
@ -748,18 +746,18 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void SyncClass<T>::initiate_client_reset(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue & return_value) {
|
||||
args.validate_count(1);
|
||||
std::string path = Value::validated_to_string(ctx, args[0]);
|
||||
void SyncClass<T>::initiate_client_reset(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue & return_value) {
|
||||
validate_argument_count(argc, 1);
|
||||
std::string path = Value::validated_to_string(ctx, arguments[0]);
|
||||
if (!SyncManager::shared().immediately_run_file_actions(std::string(path))) {
|
||||
throw std::runtime_error(util::format("Realm was not configured correctly. Client Reset could not be run for Realm at: %1", path));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SyncClass<T>::set_sync_log_level(ContextType ctx, ObjectType this_object, Arguments &args, ReturnValue &return_value) {
|
||||
args.validate_count(1);
|
||||
std::string log_level = Value::validated_to_string(ctx, args[0]);
|
||||
void SyncClass<T>::set_sync_log_level(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 1);
|
||||
std::string log_level = Value::validated_to_string(ctx, arguments[0]);
|
||||
std::istringstream in(log_level); // Throws
|
||||
in.imbue(std::locale::classic()); // Throws
|
||||
in.unsetf(std::ios_base::skipws);
|
||||
|
|
|
@ -85,7 +85,7 @@ static inline void validate_argument_count_at_least(size_t count, size_t expecte
|
|||
|
||||
template<typename T, AggregateFunc func>
|
||||
void compute_aggregate_on_collection(typename T::ContextType ctx, typename T::ObjectType this_object,
|
||||
typename T::Arguments &args, typename T::ReturnValue &return_value) {
|
||||
typename T::Arguments args, typename T::ReturnValue &return_value) {
|
||||
|
||||
auto list = get_internal<typename T::Type, T>(this_object);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ using ClassDefinition = js::ClassDefinition<Types, T>;
|
|||
|
||||
using ConstructorType = js::ConstructorType<Types>;
|
||||
using ArgumentsMethodType = js::ArgumentsMethodType<Types>;
|
||||
using MethodType = js::MethodType<Types>;
|
||||
using Arguments = js::Arguments<Types>;
|
||||
using PropertyType = js::PropertyType<Types>;
|
||||
using IndexPropertyType = js::IndexPropertyType<Types>;
|
||||
|
@ -228,9 +229,8 @@ inline JSValueRef ObjectWrap<ClassType>::call(JSContextRef ctx, JSObjectRef func
|
|||
|
||||
// Classes without a constructor should still be subclassable.
|
||||
if (reinterpret_cast<void*>(s_class.constructor)) {
|
||||
jsc::Arguments args{ctx, argc, arguments};
|
||||
try {
|
||||
s_class.constructor(ctx, this_object, args);
|
||||
s_class.constructor(ctx, this_object, argc, arguments);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
*exception = jsc::Exception::value(ctx, e);
|
||||
|
@ -249,9 +249,8 @@ inline JSObjectRef ObjectWrap<ClassType>::construct(JSContextRef ctx, JSObjectRe
|
|||
}
|
||||
|
||||
JSObjectRef this_object = create_instance(ctx);
|
||||
jsc::Arguments args{ctx, argc, arguments};
|
||||
try {
|
||||
s_class.constructor(ctx, this_object, args);
|
||||
s_class.constructor(ctx, this_object, argc, arguments);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
*exception = jsc::Exception::value(ctx, e);
|
||||
|
@ -382,12 +381,24 @@ namespace js {
|
|||
template<typename ClassType>
|
||||
class ObjectWrap<jsc::Types, ClassType> : public jsc::ObjectWrap<ClassType> {};
|
||||
|
||||
template<jsc::ArgumentsMethodType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef, JSObjectRef this_object, size_t argc, const JSValueRef arguments[], JSValueRef* exception) {
|
||||
jsc::Arguments args{ctx, argc, arguments};
|
||||
template<jsc::MethodType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef function, JSObjectRef this_object, size_t argc, const JSValueRef arguments[], JSValueRef* exception) {
|
||||
jsc::ReturnValue return_value(ctx);
|
||||
try {
|
||||
F(ctx, this_object, args, return_value);
|
||||
F(ctx, function, this_object, argc, arguments, return_value);
|
||||
return return_value;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
*exception = jsc::Exception::value(ctx, e);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template<jsc::ArgumentsMethodType F>
|
||||
JSValueRef wrap(JSContextRef ctx, JSObjectRef, JSObjectRef this_object, size_t argc, const JSValueRef arguments[], JSValueRef* exception) {
|
||||
jsc::ReturnValue return_value(ctx);
|
||||
try {
|
||||
F(ctx, this_object, jsc::Arguments{ctx, argc, arguments}, return_value);
|
||||
return return_value;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
|
|
|
@ -30,6 +30,7 @@ template<typename T>
|
|||
using ClassDefinition = js::ClassDefinition<Types, T>;
|
||||
|
||||
using ConstructorType = js::ConstructorType<Types>;
|
||||
using MethodType = js::MethodType<Types>;
|
||||
using ArgumentsMethodType = js::ArgumentsMethodType<Types>;
|
||||
using Arguments = js::Arguments<Types>;
|
||||
using PropertyType = js::PropertyType<Types>;
|
||||
|
@ -50,7 +51,7 @@ class ObjectWrap : public Nan::ObjectWrap {
|
|||
return Nan::New(js_template);
|
||||
}
|
||||
|
||||
static void construct(const Nan::FunctionCallbackInfo<v8::Value>&);
|
||||
static void construct(const v8::FunctionCallbackInfo<v8::Value>&);
|
||||
|
||||
static bool has_instance(v8::Isolate* isolate, const v8::Local<v8::Value> &value) {
|
||||
return get_template()->HasInstance(value);
|
||||
|
@ -76,26 +77,26 @@ class ObjectWrap : public Nan::ObjectWrap {
|
|||
|
||||
static v8::Local<v8::FunctionTemplate> create_template();
|
||||
|
||||
static void setup_method(v8::Local<v8::FunctionTemplate>, const std::string &, Nan::FunctionCallback);
|
||||
static void setup_static_method(v8::Local<v8::FunctionTemplate>, const std::string &, Nan::FunctionCallback);
|
||||
static void setup_method(v8::Local<v8::FunctionTemplate>, const std::string &, v8::FunctionCallback);
|
||||
static void setup_static_method(v8::Local<v8::FunctionTemplate>, const std::string &, v8::FunctionCallback);
|
||||
|
||||
template<typename TargetType>
|
||||
static void setup_property(v8::Local<TargetType>, const std::string &, const PropertyType &);
|
||||
|
||||
static void get_indexes(const Nan::PropertyCallbackInfo<v8::Array>&);
|
||||
static void set_property(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&);
|
||||
static void get_indexes(const v8::PropertyCallbackInfo<v8::Array>&);
|
||||
static void set_property(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
|
||||
|
||||
static void set_readonly_property(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<void>& info) {
|
||||
static void set_readonly_property(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) {
|
||||
std::string message = std::string("Cannot assign to read only property '") + std::string(String(property)) + "'";
|
||||
Nan::ThrowError(message.c_str());
|
||||
}
|
||||
|
||||
static void set_readonly_index(uint32_t index, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
static void set_readonly_index(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
std::string message = std::string("Cannot assign to read only index ") + util::to_string(index);
|
||||
Nan::ThrowError(message.c_str());
|
||||
}
|
||||
|
||||
static void get_nonexistent_property(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&) {
|
||||
static void get_nonexistent_property(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&) {
|
||||
// Do nothing. This function exists only to prevent a crash where it is used.
|
||||
}
|
||||
};
|
||||
|
@ -111,7 +112,7 @@ class ObjectWrap<void> {
|
|||
};
|
||||
|
||||
// This helper function is needed outside the scope of the ObjectWrap class as well.
|
||||
static inline std::vector<v8::Local<v8::Value>> get_arguments(const Nan::FunctionCallbackInfo<v8::Value> &info) {
|
||||
static inline std::vector<v8::Local<v8::Value>> get_arguments(const v8::FunctionCallbackInfo<v8::Value> &info) {
|
||||
int count = info.Length();
|
||||
std::vector<v8::Local<v8::Value>> arguments;
|
||||
arguments.reserve(count);
|
||||
|
@ -158,7 +159,7 @@ template<typename ClassType>
|
|||
inline v8::Local<v8::FunctionTemplate> ObjectWrap<ClassType>::create_template() {
|
||||
Nan::EscapableHandleScope scope;
|
||||
|
||||
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(construct);
|
||||
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), construct);
|
||||
v8::Local<v8::ObjectTemplate> instance_tpl = tpl->InstanceTemplate();
|
||||
v8::Local<v8::String> name = Nan::New(s_class.name).ToLocalChecked();
|
||||
|
||||
|
@ -183,21 +184,21 @@ inline v8::Local<v8::FunctionTemplate> ObjectWrap<ClassType>::create_template()
|
|||
|
||||
if (s_class.index_accessor.getter) {
|
||||
auto &index_accessor = s_class.index_accessor;
|
||||
Nan::SetIndexedPropertyHandler(instance_tpl, index_accessor.getter, index_accessor.setter ? index_accessor.setter : set_readonly_index, 0, 0, get_indexes);
|
||||
instance_tpl->SetIndexedPropertyHandler(index_accessor.getter, index_accessor.setter ? index_accessor.setter : set_readonly_index, 0, 0, get_indexes);
|
||||
}
|
||||
if (s_class.string_accessor.getter || s_class.index_accessor.getter || s_class.index_accessor.setter) {
|
||||
// Use our own wrapper for the setter since we want to throw for negative indices.
|
||||
auto &string_accessor = s_class.string_accessor;
|
||||
Nan::SetNamedPropertyHandler(instance_tpl, string_accessor.getter ? string_accessor.getter : get_nonexistent_property, set_property, 0, 0, string_accessor.enumerator);
|
||||
instance_tpl->SetNamedPropertyHandler(string_accessor.getter ? string_accessor.getter : get_nonexistent_property, set_property, 0, 0, string_accessor.enumerator);
|
||||
}
|
||||
|
||||
return scope.Escape(tpl);
|
||||
}
|
||||
|
||||
template<typename ClassType>
|
||||
inline void ObjectWrap<ClassType>::setup_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, Nan::FunctionCallback callback) {
|
||||
inline void ObjectWrap<ClassType>::setup_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, v8::FunctionCallback callback) {
|
||||
v8::Local<v8::Signature> signature = Nan::New<v8::Signature>(tpl);
|
||||
v8::Local<v8::FunctionTemplate> fn_tpl = Nan::New<v8::FunctionTemplate>(callback, v8::Local<v8::Value>(), signature);
|
||||
v8::Local<v8::FunctionTemplate> fn_tpl = v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), callback, v8::Local<v8::Value>(), signature);
|
||||
v8::Local<v8::String> fn_name = Nan::New(name).ToLocalChecked();
|
||||
|
||||
// The reason we use this rather than Nan::SetPrototypeMethod is DontEnum.
|
||||
|
@ -206,8 +207,8 @@ inline void ObjectWrap<ClassType>::setup_method(v8::Local<v8::FunctionTemplate>
|
|||
}
|
||||
|
||||
template<typename ClassType>
|
||||
inline void ObjectWrap<ClassType>::setup_static_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, Nan::FunctionCallback callback) {
|
||||
v8::Local<v8::FunctionTemplate> fn_tpl = Nan::New<v8::FunctionTemplate>(callback);
|
||||
inline void ObjectWrap<ClassType>::setup_static_method(v8::Local<v8::FunctionTemplate> tpl, const std::string &name, v8::FunctionCallback callback) {
|
||||
v8::Local<v8::FunctionTemplate> fn_tpl = v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), callback);
|
||||
v8::Local<v8::String> fn_name = Nan::New(name).ToLocalChecked();
|
||||
|
||||
tpl->Set(fn_name, fn_tpl, v8::PropertyAttribute::DontEnum);
|
||||
|
@ -220,18 +221,17 @@ inline void ObjectWrap<ClassType>::setup_property(v8::Local<TargetType> target,
|
|||
v8::Local<v8::String> prop_name = Nan::New(name).ToLocalChecked();
|
||||
v8::PropertyAttribute attributes = v8::PropertyAttribute(v8::DontEnum | v8::DontDelete);
|
||||
|
||||
Nan::SetAccessor(target, prop_name, property.getter, property.setter ? property.setter : set_readonly_property, v8::Local<v8::Value>(), v8::DEFAULT, attributes);
|
||||
target->SetAccessor(prop_name, property.getter, property.setter ? property.setter : set_readonly_property, v8::Local<v8::Value>(), v8::DEFAULT, attributes);
|
||||
}
|
||||
|
||||
template<typename ClassType>
|
||||
inline void ObjectWrap<ClassType>::construct(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||
inline void ObjectWrap<ClassType>::construct(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||
if (!info.IsConstructCall()) {
|
||||
Nan::ThrowError("Constructor must be called with new");
|
||||
}
|
||||
if (reinterpret_cast<void*>(s_class.constructor)) {
|
||||
auto isolate = info.GetIsolate();
|
||||
auto arguments = get_arguments(info);
|
||||
node::Arguments args{isolate, arguments.size(), arguments.data()};
|
||||
v8::Local<v8::Object> this_object = info.This();
|
||||
info.GetReturnValue().Set(this_object);
|
||||
|
||||
|
@ -239,7 +239,7 @@ inline void ObjectWrap<ClassType>::construct(const Nan::FunctionCallbackInfo<v8:
|
|||
wrap->Wrap(this_object);
|
||||
|
||||
try {
|
||||
s_class.constructor(isolate, this_object, args);
|
||||
s_class.constructor(isolate, this_object, arguments.size(), arguments.data());
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
Nan::ThrowError(node::Exception::value(isolate, e));
|
||||
|
@ -251,7 +251,7 @@ inline void ObjectWrap<ClassType>::construct(const Nan::FunctionCallbackInfo<v8:
|
|||
}
|
||||
|
||||
template<typename ClassType>
|
||||
inline void ObjectWrap<ClassType>::get_indexes(const Nan::PropertyCallbackInfo<v8::Array>& info) {
|
||||
inline void ObjectWrap<ClassType>::get_indexes(const v8::PropertyCallbackInfo<v8::Array>& info) {
|
||||
uint32_t length;
|
||||
try {
|
||||
length = Object::validated_get_length(info.GetIsolate(), info.This());
|
||||
|
@ -270,7 +270,7 @@ inline void ObjectWrap<ClassType>::get_indexes(const Nan::PropertyCallbackInfo<v
|
|||
}
|
||||
|
||||
template<typename ClassType>
|
||||
inline void ObjectWrap<ClassType>::set_property(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
inline void ObjectWrap<ClassType>::set_property(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (s_class.index_accessor.getter || s_class.index_accessor.setter) {
|
||||
try {
|
||||
// Negative indices are passed into this string property interceptor, so check for them here.
|
||||
|
@ -296,15 +296,28 @@ namespace js {
|
|||
template<typename ClassType>
|
||||
class ObjectWrap<node::Types, ClassType> : public node::ObjectWrap<ClassType> {};
|
||||
|
||||
template<node::ArgumentsMethodType F>
|
||||
void wrap(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||
template<node::MethodType F>
|
||||
void wrap(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
auto arguments = node::get_arguments(info);
|
||||
node::Arguments args{isolate, arguments.size(), arguments.data()};
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
auto arguments = node::get_arguments(info);
|
||||
|
||||
try {
|
||||
F(isolate, info.This(), args, return_value);
|
||||
F(isolate, info.Callee(), info.This(), arguments.size(), arguments.data(), return_value);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
Nan::ThrowError(node::Exception::value(isolate, e));
|
||||
}
|
||||
}
|
||||
|
||||
template<node::ArgumentsMethodType F>
|
||||
void wrap(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
auto arguments = node::get_arguments(info);
|
||||
|
||||
try {
|
||||
F(isolate, info.This(), node::Arguments{isolate, arguments.size(), arguments.data()}, return_value);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
Nan::ThrowError(node::Exception::value(isolate, e));
|
||||
|
@ -313,7 +326,7 @@ void wrap(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|||
|
||||
|
||||
template<node::PropertyType::GetterType F>
|
||||
void wrap(v8::Local<v8::String> property, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void wrap(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
try {
|
||||
|
@ -325,7 +338,7 @@ void wrap(v8::Local<v8::String> property, const Nan::PropertyCallbackInfo<v8::Va
|
|||
}
|
||||
|
||||
template<node::PropertyType::SetterType F>
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<void>& info) {
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
F(isolate, info.This(), value);
|
||||
|
@ -336,7 +349,7 @@ void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan:
|
|||
}
|
||||
|
||||
template<node::IndexPropertyType::GetterType F>
|
||||
void wrap(uint32_t index, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void wrap(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
try {
|
||||
|
@ -352,7 +365,7 @@ void wrap(uint32_t index, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
|||
}
|
||||
|
||||
template<node::IndexPropertyType::SetterType F>
|
||||
void wrap(uint32_t index, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void wrap(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
if (F(isolate, info.This(), index, value)) {
|
||||
|
@ -366,7 +379,7 @@ void wrap(uint32_t index, v8::Local<v8::Value> value, const Nan::PropertyCallbac
|
|||
}
|
||||
|
||||
template<node::StringPropertyType::GetterType F>
|
||||
void wrap(v8::Local<v8::String> property, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void wrap(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
node::ReturnValue return_value(info.GetReturnValue());
|
||||
try {
|
||||
|
@ -378,7 +391,7 @@ void wrap(v8::Local<v8::String> property, const Nan::PropertyCallbackInfo<v8::Va
|
|||
}
|
||||
|
||||
template<node::StringPropertyType::SetterType F>
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
try {
|
||||
if (F(isolate, info.This(), property, value)) {
|
||||
|
@ -392,7 +405,7 @@ void wrap(v8::Local<v8::String> property, v8::Local<v8::Value> value, const Nan:
|
|||
}
|
||||
|
||||
template<node::StringPropertyType::EnumeratorType F>
|
||||
void wrap(const Nan::PropertyCallbackInfo<v8::Array>& info) {
|
||||
void wrap(const v8::PropertyCallbackInfo<v8::Array>& info) {
|
||||
auto names = F(info.GetIsolate(), info.This());
|
||||
int count = (int)names.size();
|
||||
v8::Local<v8::Array> array = Nan::New<v8::Array>(count);
|
||||
|
|
|
@ -25,10 +25,10 @@ namespace js {
|
|||
|
||||
template<>
|
||||
class ReturnValue<node::Types> {
|
||||
Nan::ReturnValue<v8::Value> m_value;
|
||||
v8::ReturnValue<v8::Value> m_value;
|
||||
|
||||
public:
|
||||
ReturnValue(Nan::ReturnValue<v8::Value> value) : m_value(value) {}
|
||||
ReturnValue(v8::ReturnValue<v8::Value> value) : m_value(value) {}
|
||||
|
||||
void set(const v8::Local<v8::Value> &value) {
|
||||
m_value.Set(value);
|
||||
|
|
|
@ -43,15 +43,15 @@ struct Types {
|
|||
using String = v8::Local<v8::String>;
|
||||
using Function = v8::Local<v8::Function>;
|
||||
|
||||
using ConstructorCallback = Nan::FunctionCallback;
|
||||
using FunctionCallback = Nan::FunctionCallback;
|
||||
using PropertyGetterCallback = Nan::GetterCallback;
|
||||
using PropertySetterCallback = Nan::SetterCallback;
|
||||
using IndexPropertyGetterCallback = Nan::IndexGetterCallback;
|
||||
using IndexPropertySetterCallback = Nan::IndexSetterCallback;
|
||||
using StringPropertyGetterCallback = Nan::PropertyGetterCallback;
|
||||
using StringPropertySetterCallback = Nan::PropertySetterCallback;
|
||||
using StringPropertyEnumeratorCallback = Nan::PropertyEnumeratorCallback;
|
||||
using ConstructorCallback = v8::FunctionCallback;
|
||||
using FunctionCallback = v8::FunctionCallback;
|
||||
using PropertyGetterCallback = v8::AccessorGetterCallback;
|
||||
using PropertySetterCallback = v8::AccessorSetterCallback;
|
||||
using IndexPropertyGetterCallback = v8::IndexedPropertyGetterCallback;
|
||||
using IndexPropertySetterCallback = v8::IndexedPropertySetterCallback;
|
||||
using StringPropertyGetterCallback = v8::NamedPropertyGetterCallback;
|
||||
using StringPropertySetterCallback = v8::NamedPropertySetterCallback;
|
||||
using StringPropertyEnumeratorCallback = v8::NamedPropertyEnumeratorCallback;
|
||||
};
|
||||
|
||||
template<typename ClassType>
|
||||
|
|
14
src/rpc.cpp
14
src/rpc.cpp
|
@ -365,10 +365,10 @@ RPCServer::~RPCServer() {
|
|||
JSGlobalContextRelease(m_context);
|
||||
}
|
||||
|
||||
JSValueRef RPCServer::run_callback(JSContextRef ctx, JSObjectRef function, JSObjectRef this_object, size_t argc, const JSValueRef arguments[], JSValueRef* exception) {
|
||||
void RPCServer::run_callback(JSContextRef ctx, JSObjectRef function, JSObjectRef this_object, size_t argc, const JSValueRef arguments[], jsc::ReturnValue &return_value) {
|
||||
RPCServer* server = get_rpc_server(JSContextGetGlobalContext(ctx));
|
||||
if (!server) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
u_int64_t counter = server->m_callback_call_counter++;
|
||||
|
@ -419,15 +419,11 @@ JSValueRef RPCServer::run_callback(JSContextRef ctx, JSObjectRef function, JSObj
|
|||
assert(callback_id == resultCallbackId.get<RPCObjectID>());
|
||||
|
||||
if (!error.is_null()) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(error.get<std::string>().c_str());
|
||||
JSValueRef arguments[] { JSValueMakeString(ctx, message) };
|
||||
JSStringRelease(message);
|
||||
|
||||
*exception = JSObjectMakeError(ctx, 1, arguments, nullptr);
|
||||
throw jsc::Exception(ctx, error.get<std::string>());
|
||||
}
|
||||
|
||||
|
||||
return server->deserialize_json_value(results["result"]);
|
||||
return_value.set(server->deserialize_json_value(results["result"]));
|
||||
|
||||
}
|
||||
|
||||
|
@ -653,7 +649,7 @@ JSValueRef RPCServer::deserialize_json_value(const json dict) {
|
|||
RPCObjectID callback_id = value.get<RPCObjectID>();
|
||||
|
||||
if (!m_callbacks.count(callback_id)) {
|
||||
JSObjectRef callback = JSObjectMakeFunctionWithCallback(m_context, nullptr, run_callback);
|
||||
JSObjectRef callback = JSObjectMakeFunctionWithCallback(m_context, nullptr, js::wrap<run_callback>);
|
||||
m_callbacks.emplace(callback_id, js::Protected<JSObjectRef>(m_context, callback));
|
||||
m_callback_ids.emplace(callback, callback_id);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class RPCServer {
|
|||
RPCWorker m_worker;
|
||||
u_int64_t m_callback_call_counter;
|
||||
|
||||
static JSValueRef run_callback(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef *exception);
|
||||
static void run_callback(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], jsc::ReturnValue &);
|
||||
|
||||
RPCObjectID store_object(JSObjectRef object);
|
||||
|
||||
|
|
Loading…
Reference in New Issue