bugfix for empty results, fix for realm.isValid
This commit is contained in:
parent
6072061463
commit
3509caedd5
|
@ -151,6 +151,7 @@ export default class Realm {
|
||||||
// Non-mutating methods:
|
// Non-mutating methods:
|
||||||
util.createMethods(Realm.prototype, objectTypes.REALM, [
|
util.createMethods(Realm.prototype, objectTypes.REALM, [
|
||||||
'close',
|
'close',
|
||||||
|
'isValid',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Mutating methods:
|
// Mutating methods:
|
||||||
|
|
|
@ -459,14 +459,15 @@ void Realm<T>::delete_all(ContextType ctx, ObjectType this_object, size_t argc,
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Realm<T>::is_object_valid(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
void Realm<T>::is_object_valid(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||||
validate_argument_count(argc, 0);
|
validate_argument_count(argc, 1);
|
||||||
|
|
||||||
ObjectType arg = Value::validated_to_object(ctx, arguments[0]);
|
ObjectType arg = Value::validated_to_object(ctx, arguments[0]);
|
||||||
if (!Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
if (Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
||||||
throw std::runtime_error("Argument to Realm.isValid must be a 'RealmObject'");
|
return_value.set(get_internal<T, RealmObjectClass<T>>(arg)->is_valid());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw std::runtime_error("Object is not a Realm Object");
|
||||||
}
|
}
|
||||||
auto object = get_internal<T, RealmObjectClass<T>>(arg);
|
|
||||||
return_value.set(object->is_valid());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -104,7 +104,7 @@ struct Value {
|
||||||
static return_t validated_to_##type(ContextType ctx, const ValueType &value, const char *name = nullptr) { \
|
static return_t validated_to_##type(ContextType ctx, const ValueType &value, const char *name = nullptr) { \
|
||||||
if (!is_##type(ctx, value)) { \
|
if (!is_##type(ctx, value)) { \
|
||||||
std::string prefix = name ? std::string("'") + name + "'" : "JS value"; \
|
std::string prefix = name ? std::string("'") + name + "'" : "JS value"; \
|
||||||
throw std::invalid_argument(prefix + " must be: " #type); \
|
throw std::invalid_argument(prefix + " must be of type: " #type); \
|
||||||
} \
|
} \
|
||||||
return to_##type(ctx, value); \
|
return to_##type(ctx, value); \
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "js_class.hpp"
|
#include "js_class.hpp"
|
||||||
#include "js_util.hpp"
|
#include "js_util.hpp"
|
||||||
|
|
||||||
|
#include "results.hpp"
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
namespace jsc {
|
namespace jsc {
|
||||||
|
|
||||||
|
@ -276,6 +278,10 @@ inline JSValueRef ObjectWrap<ClassType>::get_property(JSContextRef ctx, JSObject
|
||||||
// Out-of-bounds index getters should just return undefined in JS.
|
// Out-of-bounds index getters should just return undefined in JS.
|
||||||
return Value::from_undefined(ctx);
|
return Value::from_undefined(ctx);
|
||||||
}
|
}
|
||||||
|
catch (Results::OutOfBoundsIndexException &) {
|
||||||
|
// Out-of-bounds index getters should just return undefined in JS.
|
||||||
|
return Value::from_undefined(ctx);
|
||||||
|
}
|
||||||
catch (std::invalid_argument &) {
|
catch (std::invalid_argument &) {
|
||||||
// Property is not a number.
|
// Property is not a number.
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "js_class.hpp"
|
#include "js_class.hpp"
|
||||||
#include "js_util.hpp"
|
#include "js_util.hpp"
|
||||||
|
|
||||||
|
#include "results.hpp"
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
|
@ -342,6 +344,10 @@ void wrap(uint32_t index, Nan::NAN_INDEX_GETTER_ARGS_TYPE info) {
|
||||||
// Out-of-bounds index getters should just return undefined in JS.
|
// Out-of-bounds index getters should just return undefined in JS.
|
||||||
return_value.set_undefined();
|
return_value.set_undefined();
|
||||||
}
|
}
|
||||||
|
catch (Results::OutOfBoundsIndexException &) {
|
||||||
|
// Out-of-bounds index getters should just return undefined in JS.
|
||||||
|
return_value.set_undefined();
|
||||||
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
Nan::ThrowError(node::Exception::value(isolate, e));
|
Nan::ThrowError(node::Exception::value(isolate, e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,8 +342,9 @@ namespace realm {
|
||||||
|
|
||||||
inline void Object::verify_attached() {
|
inline void Object::verify_attached() {
|
||||||
if (!m_row.is_attached()) {
|
if (!m_row.is_attached()) {
|
||||||
throw InvalidatedObjectException("Accessing object of type " + m_object_schema->name + " which has been deleted",
|
throw InvalidatedObjectException(m_object_schema->name,
|
||||||
m_object_schema->name);
|
"Accessing object of type " + m_object_schema->name + " which has been deleted"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ module.exports = BaseTest.extend({
|
||||||
|
|
||||||
testResultsSubscript: function() {
|
testResultsSubscript: function() {
|
||||||
var realm = new Realm({schema: [schemas.PersonObject]});
|
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||||
|
TestCase.assertEqual(realm.objects('PersonObject')[0], undefined);
|
||||||
|
|
||||||
realm.write(function() {
|
realm.write(function() {
|
||||||
realm.create('PersonObject', {name: 'name1', age: 1});
|
realm.create('PersonObject', {name: 'name1', age: 1});
|
||||||
realm.create('PersonObject', {name: 'name2', age: 2});
|
realm.create('PersonObject', {name: 'name2', age: 2});
|
||||||
|
|
Loading…
Reference in New Issue