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:
|
||||
util.createMethods(Realm.prototype, objectTypes.REALM, [
|
||||
'close',
|
||||
'isValid',
|
||||
]);
|
||||
|
||||
// Mutating methods:
|
||||
|
|
|
@ -459,14 +459,15 @@ void Realm<T>::delete_all(ContextType ctx, ObjectType this_object, size_t argc,
|
|||
|
||||
template<typename T>
|
||||
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]);
|
||||
if (!Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
||||
throw std::runtime_error("Argument to Realm.isValid must be a 'RealmObject'");
|
||||
if (Object::template is_instance<RealmObjectClass<T>>(ctx, arg)) {
|
||||
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>
|
||||
|
|
|
@ -104,7 +104,7 @@ struct Value {
|
|||
static return_t validated_to_##type(ContextType ctx, const ValueType &value, const char *name = nullptr) { \
|
||||
if (!is_##type(ctx, value)) { \
|
||||
std::string prefix = name ? std::string("'") + name + "'" : "JS value"; \
|
||||
throw std::invalid_argument(prefix + " must be: " #type); \
|
||||
throw std::invalid_argument(prefix + " must be of type: " #type); \
|
||||
} \
|
||||
return to_##type(ctx, value); \
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "js_class.hpp"
|
||||
#include "js_util.hpp"
|
||||
|
||||
#include "results.hpp"
|
||||
|
||||
namespace realm {
|
||||
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.
|
||||
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 &) {
|
||||
// Property is not a number.
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "js_class.hpp"
|
||||
#include "js_util.hpp"
|
||||
|
||||
#include "results.hpp"
|
||||
|
||||
namespace realm {
|
||||
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.
|
||||
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) {
|
||||
Nan::ThrowError(node::Exception::value(isolate, e));
|
||||
}
|
||||
|
|
|
@ -342,8 +342,9 @@ namespace realm {
|
|||
|
||||
inline void Object::verify_attached() {
|
||||
if (!m_row.is_attached()) {
|
||||
throw InvalidatedObjectException("Accessing object of type " + m_object_schema->name + " which has been deleted",
|
||||
m_object_schema->name);
|
||||
throw InvalidatedObjectException(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() {
|
||||
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||
TestCase.assertEqual(realm.objects('PersonObject')[0], undefined);
|
||||
|
||||
realm.write(function() {
|
||||
realm.create('PersonObject', {name: 'name1', age: 1});
|
||||
realm.create('PersonObject', {name: 'name2', age: 2});
|
||||
|
|
Loading…
Reference in New Issue