Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix classes not extending Realm.Object #4125

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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