Skip to content

Commit

Permalink
Fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth committed Feb 6, 2023
1 parent 14e1265 commit f8a6be4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Enhancements
* Converting flexible sync Realms to bundled and local realms is now supported. ([realm/realm-core#6076](https://github.com/realm/realm-core/pull/6076))
* For client reset mode `onRecoveryOrDiscard`, the `onDiscard` and `onRecovery` callbacks now have simple default values. ([#5288](https://github.com/realm/realm-js/pull/5288), since v11.1.0)

### Fixed
* Fixed possible segfault in sync client where async callback was using object after being deallocated. ([realm/realm-core#6053](https://github.com/realm/realm-core/issues/6053), since v10.11.0)
Expand Down
43 changes: 16 additions & 27 deletions src/js_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,34 +1303,23 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
}

case realm::ClientResyncMode::RecoverOrDiscard: {
FunctionType client_reset_discard_callback;
ValueType client_reset_discard_value =
Object::get_property(ctx, client_reset_object, "onDiscard");
if (Value::is_undefined(ctx, client_reset_discard_value)) {
auto realm = Value::validated_to_object(ctx, Object::get_global(ctx, "Realm"));
auto default_on_discard_callback = Value::validated_to_object(
ctx, Object::get_property(ctx, realm, "_defaultOnDiscardCallback"));
client_reset_discard_callback =
Value::validated_to_function(ctx, default_on_discard_callback);
}
else {
client_reset_discard_callback = Value::validated_to_function(ctx, client_reset_discard_value);
}
auto get_callback = [=](std::string callback_name, std::string default_callback_name) {
ValueType callback_value = Object::get_property(ctx, client_reset_object, callback_name);
if (Value::is_undefined(ctx, callback_value)) {
auto realm = Value::validated_to_object(ctx, Object::get_global(ctx, "Realm"));
auto default_callback_value = Value::validated_to_object(
ctx, Object::get_property(ctx, realm, default_callback_name));
return Value::validated_to_function(ctx, default_callback_value);
}
else {
return Value::validated_to_function(ctx, callback_value);
}
};

FunctionType client_reset_recovery_callback;
ValueType client_reset_recovery_value =
Object::get_property(ctx, client_reset_object, "onRecovery");
if (Value::is_undefined(ctx, client_reset_recovery_value)) {
auto realm = Value::validated_to_object(ctx, Object::get_global(ctx, "Realm"));
auto default_on_recovery_callback = Value::validated_to_object(
ctx, Object::get_property(ctx, realm, "_defaultOnRecoveryCallback"));
client_reset_recovery_callback =
Value::validated_to_function(ctx, default_on_recovery_callback);
}
else {
client_reset_recovery_callback =
Value::validated_to_function(ctx, client_reset_recovery_value);
}
FunctionType client_reset_discard_callback =
get_callback("onDiscard", "_defaultOnDiscardCallback");
FunctionType client_reset_recovery_callback =
get_callback("onRecovery", "_defaultOnRecoveryCallback");

auto client_reset_after_handler =
util::EventLoopDispatcher<void(SharedRealm, ThreadSafeReference, bool)>(
Expand Down

0 comments on commit f8a6be4

Please sign in to comment.