Add checks for removeListener

This commit is contained in:
Kristian Dupont 2016-12-07 15:34:53 +01:00 committed by Ari Lazier
parent 1d4bb7c2ad
commit 43d94d1b8b
2 changed files with 14 additions and 0 deletions

View File

@ -652,6 +652,9 @@ void RealmClass<T>::remove_listener(ContextType ctx, ObjectType this_object, siz
auto callback = Value::validated_to_function(ctx, arguments[1]);
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
if (realm->is_closed()) {
throw ClosedRealmException();
}
get_delegate<T>(realm.get())->remove_notification(callback);
}
@ -663,6 +666,9 @@ void RealmClass<T>::remove_all_listeners(ContextType ctx, ObjectType this_object
}
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
if (realm->is_closed()) {
throw ClosedRealmException();
}
get_delegate<T>(realm.get())->remove_all_notifications();
}

View File

@ -656,6 +656,8 @@ module.exports = {
});
var person = realm.objects('PersonObject')[0];
var listenerCallback = () => {};
realm.addListener('change', listenerCallback);
// The tests below assert that everthing throws when
// operating on a closed realm
@ -689,7 +691,13 @@ module.exports = {
realm.write(() => {});
});
TestCase.assertThrows(function() {
realm.removeListener('change', listenerCallback);
});
TestCase.assertThrows(function() {
realm.removeAllListeners();
});
},
testRealmObjectForPrimaryKey: function() {