Skip to content

Commit

Permalink
Fix classes not extending Realm.Object (#4125)
Browse files Browse the repository at this point in the history
* Fixing custom classes not extending Realm.Object

* Adding a note to the changelog

* Update CHANGELOG.md

Co-authored-by: FFranck <[email protected]>

Co-authored-by: FFranck <[email protected]>
  • Loading branch information
kraenhansen and FFranck committed Dec 21, 2021
1 parent 1ae4802 commit 1735e4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <How to hit and notice issue? what was the impact?> ([#????](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.
Expand Down
9 changes: 5 additions & 4 deletions src/jsi/jsi_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<Internal>(env, std::move(internal));
}
static void set_internal(JsiEnv env, const JsiObj& object, Internal* data)
Expand Down

0 comments on commit 1735e4f

Please sign in to comment.