diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fd136d..f56922bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ x.x.x Release notes (yyyy-MM-dd) * Added `isValid()` method to `List` and `Results` to check for deleleted or invalidated objects ### Bugfixes -* None +* Fix for crash when setting object properties to objects from other Realms 0.13.2 Release notes (2016-5-26) ============================================================= diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index b6e8eb40..37448925 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -106,7 +106,10 @@ struct NativeAccessor { static size_t to_object_index(ContextType ctx, SharedRealm realm, ValueType &value, const std::string &type, bool try_update) { ObjectType object = Value::validated_to_object(ctx, value); if (Object::template is_instance>(ctx, object)) { - return get_internal>(object)->row().get_index(); + auto realm_object = get_internal>(object); + if (realm_object->realm() == realm) { + return realm_object->row().get_index(); + } } auto object_schema = realm->config().schema->find(type); diff --git a/tests/js/object-tests.js b/tests/js/object-tests.js index 86cb626a..a446f8f7 100644 --- a/tests/js/object-tests.js +++ b/tests/js/object-tests.js @@ -328,6 +328,17 @@ module.exports = { TestCase.assertEqual(obj.arrayCol[0].doubleCol, 3); TestCase.assertEqual(obj.arrayCol[1].doubleCol, 1); TestCase.assertEqual(obj.arrayCol[2].doubleCol, 2); + + // set object from another realm + var another = new Realm({path: 'another.realm', schema: realm.schema}); + var anotherObj; + another.write(function() { + anotherObj = another.create('TestObject', {doubleCol: 3}); + }); + realm.write(function() { + obj.objectCol = anotherObj; + }); + TestCase.assertEqual(obj.objectCol.doubleCol, 3); }, testEnumerablePropertyNames: function() { var realm = new Realm({schema: [schemas.BasicTypes]});