From c308ab65ae888f51310c5cb16c32c947226d63b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Wed, 1 Dec 2021 20:16:06 +0100 Subject: [PATCH] Fix classes not extending `Realm.Object` (#4125) * Fixing custom classes not extending Realm.Object * Adding a note to the changelog * Update CHANGELOG.md Co-authored-by: FFranck Co-authored-by: FFranck --- CHANGELOG.md | 3 +-- src/jsi/jsi_class.hpp | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d56270cdbc..d1b41e85be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,7 @@ x.x.x Release notes (yyyy-MM-dd) * Catching missing libjsi.so when loading the librealm.so and rethrowing a more meaningful error, instructing users to upgrade their version of React Native. ### Fixed -* ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?) -* None. +* Fixed support of user defined classes that don't extend `Realm.Object`. ### Compatibility * MongoDB Realm Cloud. diff --git a/src/jsi/jsi_class.hpp b/src/jsi/jsi_class.hpp index dab474dfe0..615cfbcc1b 100644 --- a/src/jsi/jsi_class.hpp +++ b/src/jsi/jsi_class.hpp @@ -128,7 +128,7 @@ inline void copyProperty(JsiEnv env, const fbjsi::Object& from, const fbjsi::Obj { auto prop = ObjectGetOwnPropertyDescriptor(env, from, name); REALM_ASSERT_RELEASE(prop); - defineProperty(env, to, "name", *prop); + defineProperty(env, to, name, *prop); } inline constexpr const char g_internal_field[] = "__Realm_internal"; @@ -439,9 +439,10 @@ class ObjectWrap { return nullptr; throw fbjsi::JSError(env, "no internal field"); } - if (!JsiObj(object)->instanceOf(env, *s_ctor)) { - throw fbjsi::JSError(env, "calling method on wrong type of object"); - } + // The following check is disabled to support user defined classes that doesn't extend Realm.Object + // if (!JsiObj(object)->instanceOf(env, *s_ctor)) { + // throw fbjsi::JSError(env, "calling method on wrong type of object"); + // } return unwrapUnique(env, std::move(internal)); } static void set_internal(JsiEnv env, const JsiObj& object, Internal* data)