Merge pull request #403 from realm/sk-invalidation-test
Fix crash inside detached Results and add tests
This commit is contained in:
commit
2374f434d1
|
@ -9,7 +9,8 @@ x.x.x Release notes (yyyy-MM-dd)
|
|||
|
||||
### Bugfixes
|
||||
* When accessing an empty Results `undefined` is returned rather than throwing an exception
|
||||
* Accessing a deleted object throws a javascript exception rather than crashing
|
||||
* Accessing a deleted object throws a JS exception rather than crashing
|
||||
* Accessing an invalidated Results snapshot throws a JS exception rather than crashing
|
||||
|
||||
0.11.1 Release notes (2016-3-29)
|
||||
=============================================================
|
||||
|
|
|
@ -203,14 +203,14 @@ ObjectSchema Schema<T>::parse_object_schema(ContextType ctx, ObjectType object_s
|
|||
|
||||
return object_schema;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
realm::Schema Schema<T>::parse_schema(ContextType ctx, ObjectType schema_object, ObjectDefaultsMap &defaults, ConstructorMap &constructors) {
|
||||
std::vector<ObjectSchema> schema;
|
||||
uint32_t length = Object::validated_get_length(ctx, schema_object);
|
||||
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
ObjectType object_schema_object = Object::validated_get_object(ctx, schema_object, i);
|
||||
ObjectType object_schema_object = Object::validated_get_object(ctx, schema_object, i, "ObjectSchema");
|
||||
ObjectSchema object_schema = parse_object_schema(ctx, object_schema_object, defaults, constructors);
|
||||
schema.emplace_back(std::move(object_schema));
|
||||
}
|
||||
|
|
|
@ -505,7 +505,7 @@ bool ObjectStore::is_empty(const Group *group) {
|
|||
InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) :
|
||||
m_old_version(old_version), m_new_version(new_version)
|
||||
{
|
||||
m_what = "Provided schema version " + util::to_string(old_version) + " is less than last set version " + util::to_string(new_version) + ".";
|
||||
m_what = "Provided schema version " + util::to_string(new_version) + " is less than last set version " + util::to_string(old_version) + ".";
|
||||
}
|
||||
|
||||
DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) :
|
||||
|
|
|
@ -82,6 +82,8 @@ void Results::validate_write() const
|
|||
|
||||
void Results::set_live(bool live)
|
||||
{
|
||||
validate_read();
|
||||
|
||||
if (!live && m_mode == Mode::Table) {
|
||||
m_query = m_table->where();
|
||||
m_mode = Mode::Query;
|
||||
|
|
|
@ -51,7 +51,7 @@ 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});
|
||||
|
@ -119,7 +119,7 @@ module.exports = BaseTest.extend({
|
|||
for (var index in objects) {
|
||||
TestCase.assertEqual(count++, +index);
|
||||
TestCase.assertEqual(keys[index], index);
|
||||
}
|
||||
}
|
||||
|
||||
TestCase.assertEqual(count, 1);
|
||||
TestCase.assertEqual(keys.length, 1);
|
||||
|
@ -278,5 +278,32 @@ module.exports = BaseTest.extend({
|
|||
TestCase.assertEqual(objects[0].boolCol, true, 'first element descending for boolCol');
|
||||
TestCase.assertEqual(objects[1].boolCol, false, 'second element descending for boolCol');
|
||||
TestCase.assertEqual(objects[2].boolCol, false, 'third element descending for boolCol');
|
||||
},
|
||||
|
||||
testResultsInvalidation: function() {
|
||||
var realm = new Realm({schema: [schemas.TestObject]});
|
||||
var testObjects = realm.objects('TestObject');
|
||||
var filteredObjects = testObjects.filtered('doubleCol > 1');
|
||||
var sortedObjects = testObjects.sorted('doubleCol');
|
||||
var snapshotObjects = testObjects.snapshot();
|
||||
|
||||
realm.close();
|
||||
|
||||
realm = new Realm({
|
||||
schemaVersion: 1,
|
||||
schema: [schemas.TestObject, schemas.BasicTypes]
|
||||
});
|
||||
|
||||
[
|
||||
testObjects,
|
||||
filteredObjects,
|
||||
sortedObjects,
|
||||
snapshotObjects,
|
||||
].forEach(function(objects) {
|
||||
TestCase.assertThrows(function() { objects[0]; });
|
||||
TestCase.assertThrows(function() { objects.filtered('doubleCol < 42'); });
|
||||
TestCase.assertThrows(function() { objects.sorted('doubleCol', true); });
|
||||
TestCase.assertThrows(function() { objects.snapshot(); });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue