diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index cccf6e23..bcfc06fb 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -122,14 +122,16 @@ struct NativeAccessor { } static size_t to_existing_object_index(ContextType ctx, SharedRealm realm, ValueType &value) { ObjectType object = Value::validated_to_object(ctx, value); - if (Object::template is_instance>(ctx, object)) { - auto realm_object = get_internal>(object); - if (realm_object->realm() == realm) { - return realm_object->row().get_index(); - } - throw std::runtime_error("Realm object is from another Realm"); + if (!Object::template is_instance>(ctx, object)) { + throw std::runtime_error("object is not a Realm Object"); } - throw std::runtime_error("object is not a Realm Object"); + + auto realm_object = get_internal>(object); + if (realm_object->realm() != realm) { + throw std::runtime_error("Realm object is from another Realm"); + + } + return realm_object->row().get_index(); } static ValueType from_object(ContextType ctx, realm::Object realm_object) { return RealmObjectClass::create_instance(ctx, std::move(realm_object));