diff --git a/RealmJS.xcodeproj/project.pbxproj b/RealmJS.xcodeproj/project.pbxproj index ed68d7e6..0a1c544e 100644 --- a/RealmJS.xcodeproj/project.pbxproj +++ b/RealmJS.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 02409DC21BCF11D6005F3B3E /* RealmJSCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */; }; 02601F081BA0F0CD007C91FF /* index_set.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F051BA0F0CD007C91FF /* index_set.cpp */; }; 02601F091BA0F0CD007C91FF /* index_set.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F061BA0F0CD007C91FF /* index_set.hpp */; }; - 02601F0A1BA0F0CD007C91FF /* realm_delegate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F071BA0F0CD007C91FF /* realm_delegate.hpp */; }; 02601F0D1BA0F3A7007C91FF /* schema.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F0B1BA0F3A7007C91FF /* schema.cpp */; }; 02601F0E1BA0F3A7007C91FF /* schema.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F0C1BA0F3A7007C91FF /* schema.hpp */; }; 0270BC4C1B7CFC0D00010E03 /* RealmJS.h in Headers */ = {isa = PBXBuildFile; fileRef = 0270BC3E1B7CFC0D00010E03 /* RealmJS.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -56,6 +55,7 @@ 02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; 02C0864E1BCDB27000942F9C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02C0864C1BCDB27000942F9C /* list.cpp */; }; 02C0864F1BCDB27000942F9C /* list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02C0864D1BCDB27000942F9C /* list.hpp */; }; + 02D0F23B1BF6C95200B4FC45 /* binding_context.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02D0F23A1BF6C95200B4FC45 /* binding_context.hpp */; }; 02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; }; 02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; F636F6C81BCDB3570023F35C /* RealmReact.h in Headers */ = {isa = PBXBuildFile; fileRef = 0270BCCF1B7D067300010E03 /* RealmReact.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -161,7 +161,6 @@ 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmJSCoreTests.m; path = tests/RealmJSCoreTests.m; sourceTree = SOURCE_ROOT; }; 02601F051BA0F0CD007C91FF /* index_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = index_set.cpp; path = "src/object-store/index_set.cpp"; sourceTree = ""; }; 02601F061BA0F0CD007C91FF /* index_set.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = index_set.hpp; path = "src/object-store/index_set.hpp"; sourceTree = ""; }; - 02601F071BA0F0CD007C91FF /* realm_delegate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = realm_delegate.hpp; path = "src/object-store/realm_delegate.hpp"; sourceTree = ""; }; 02601F0B1BA0F3A7007C91FF /* schema.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = schema.cpp; path = "src/object-store/schema.cpp"; sourceTree = ""; }; 02601F0C1BA0F3A7007C91FF /* schema.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = schema.hpp; path = "src/object-store/schema.hpp"; sourceTree = ""; }; 0270BC3E1B7CFC0D00010E03 /* RealmJS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmJS.h; path = src/RealmJS.h; sourceTree = ""; }; @@ -211,6 +210,7 @@ 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 02C0864C1BCDB27000942F9C /* list.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = list.cpp; path = "src/object-store/list.cpp"; sourceTree = ""; }; 02C0864D1BCDB27000942F9C /* list.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = list.hpp; path = "src/object-store/list.hpp"; sourceTree = ""; }; + 02D0F23A1BF6C95200B4FC45 /* binding_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = binding_context.hpp; path = "src/object-store/binding_context.hpp"; sourceTree = ""; }; 02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; }; 02EE6D781BD87E310016A82E /* ReactTests.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ReactTests.xcodeproj; path = tests/ReactTests/ios/ReactTests.xcodeproj; sourceTree = ""; }; F64E1EF01BC3510E00E0E150 /* util.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = util.js; path = tests/util.js; sourceTree = SOURCE_ROOT; }; @@ -263,13 +263,13 @@ 0270BC641B7CFC1C00010E03 /* results.hpp */, 0270BC651B7CFC1C00010E03 /* shared_realm.cpp */, 0270BC661B7CFC1C00010E03 /* shared_realm.hpp */, + 02D0F23A1BF6C95200B4FC45 /* binding_context.hpp */, 02601F051BA0F0CD007C91FF /* index_set.cpp */, 02601F061BA0F0CD007C91FF /* index_set.hpp */, 02C0864C1BCDB27000942F9C /* list.cpp */, 02C0864D1BCDB27000942F9C /* list.hpp */, 02601F0B1BA0F3A7007C91FF /* schema.cpp */, 02601F0C1BA0F3A7007C91FF /* schema.hpp */, - 02601F071BA0F0CD007C91FF /* realm_delegate.hpp */, 029445911BDEDF40006D1617 /* transact_log_handler.cpp */, 029445921BDEDF40006D1617 /* transact_log_handler.hpp */, 029445951BDEDF46006D1617 /* external_commit_helper.cpp */, @@ -390,13 +390,13 @@ 02258FB31BC6E2D00075F13A /* RealmRPC.hpp in Headers */, 0270BC4F1B7CFC0D00010E03 /* RJSList.hpp in Headers */, 0270BC541B7CFC0D00010E03 /* RJSResults.hpp in Headers */, + 02D0F23B1BF6C95200B4FC45 /* binding_context.hpp in Headers */, 0270BC581B7CFC0D00010E03 /* RJSUtil.hpp in Headers */, 0270BC561B7CFC0D00010E03 /* RJSSchema.hpp in Headers */, 0270BC521B7CFC0D00010E03 /* RJSRealm.hpp in Headers */, 0270BC501B7CFC0D00010E03 /* RJSObject.hpp in Headers */, 02601F0E1BA0F3A7007C91FF /* schema.hpp in Headers */, 0270BC6C1B7CFC1C00010E03 /* object_store.hpp in Headers */, - 02601F0A1BA0F0CD007C91FF /* realm_delegate.hpp in Headers */, 0270BC681B7CFC1C00010E03 /* object_accessor.hpp in Headers */, 029445941BDEDF40006D1617 /* transact_log_handler.hpp in Headers */, 0270BC711B7CFC1C00010E03 /* shared_realm.hpp in Headers */, @@ -617,7 +617,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = ": ${REALM_CORE_VERSION:=0.94.3} # set to \"current\" to always use the current build\n\necho \"Downloading dependency: core ${REALM_CORE_VERSION}\"\nTMP_DIR=\"$TMPDIR/core_bin\"\nmkdir -p \"${TMP_DIR}\"\nCORE_TMP_TAR=\"${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp\"\nCORE_TAR=\"${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2\"\nif [ ! -f \"${CORE_TAR}\" ]; then\ncurl -f -L -s \"http://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2\" -o \"${CORE_TMP_TAR}\" ||\n(echo \"Downloading core failed. Please try again once you have an Internet connection.\" && exit 1)\nmv \"${CORE_TMP_TAR}\" \"${CORE_TAR}\"\nfi\n\n(\ncd \"${TMP_DIR}\"\nrm -rf core\ntar xjf \"${CORE_TAR}\"\nmv core core-${REALM_CORE_VERSION}\n)\n\nrm -rf core-${REALM_CORE_VERSION} core\nmv ${TMP_DIR}/core-${REALM_CORE_VERSION} .\nln -s core-${REALM_CORE_VERSION} core"; + shellScript = ": ${REALM_CORE_VERSION:=0.94.4} # set to \"current\" to always use the current build\n\necho \"Downloading dependency: core ${REALM_CORE_VERSION}\"\nTMP_DIR=\"$TMPDIR/core_bin\"\nmkdir -p \"${TMP_DIR}\"\nCORE_TMP_TAR=\"${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp\"\nCORE_TAR=\"${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2\"\nif [ ! -f \"${CORE_TAR}\" ]; then\ncurl -f -L -s \"http://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2\" -o \"${CORE_TMP_TAR}\" ||\n(echo \"Downloading core failed. Please try again once you have an Internet connection.\" && exit 1)\nmv \"${CORE_TMP_TAR}\" \"${CORE_TAR}\"\nfi\n\n(\ncd \"${TMP_DIR}\"\nrm -rf core\ntar xjf \"${CORE_TAR}\"\nmv core core-${REALM_CORE_VERSION}\n)\n\nrm -rf core-${REALM_CORE_VERSION} core\nmv ${TMP_DIR}/core-${REALM_CORE_VERSION} .\nln -s core-${REALM_CORE_VERSION} core"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/src/RJSRealm.mm b/src/RJSRealm.mm index 82f3edaf..6b98dc3a 100644 --- a/src/RJSRealm.mm +++ b/src/RJSRealm.mm @@ -10,13 +10,13 @@ #import "shared_realm.hpp" #import "object_accessor.hpp" -#import "realm_delegate.hpp" +#import "binding_context.hpp" #import using namespace realm; -class RJSRealmDelegate : public RealmDelegate { +class RJSRealmDelegate : public BindingContext { public: virtual void changes_available() { assert(0); @@ -96,11 +96,11 @@ public: }; std::map &RJSDefaults(Realm *realm) { - return static_cast(realm->m_delegate.get())->m_defaults; + return static_cast(realm->m_binding_context.get())->m_defaults; } std::map &RJSPrototypes(Realm *realm) { - return static_cast(realm->m_delegate.get())->m_prototypes; + return static_cast(realm->m_binding_context.get())->m_prototypes; } std::string writeablePathForFile(const std::string &fileName) { @@ -216,8 +216,8 @@ JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t a } ensureDirectoryForFile(config.path); SharedRealm realm = Realm::get_shared_realm(config); - if (!realm->m_delegate) { - realm->m_delegate = std::make_unique(realm, JSContextGetGlobalContext(ctx)); + if (!realm->m_binding_context) { + realm->m_binding_context = std::make_unique(realm, JSContextGetGlobalContext(ctx)); } RJSDefaults(realm.get()) = defaults; RJSPrototypes(realm.get()) = prototypes; @@ -442,7 +442,7 @@ JSValueRef RealmAddListener(JSContextRef ctx, JSObjectRef function, JSObjectRef JSObjectRef callback = RJSValidatedValueToFunction(ctx, arguments[1]); SharedRealm realm = *RJSGetInternal(thisObject); - static_cast(realm->m_delegate.get())->add_notification(callback); + static_cast(realm->m_binding_context.get())->add_notification(callback); return NULL; } catch (std::exception &exp) { @@ -460,7 +460,7 @@ JSValueRef RealmRemoveListener(JSContextRef ctx, JSObjectRef function, JSObjectR JSObjectRef callback = RJSValidatedValueToFunction(ctx, arguments[1]); SharedRealm realm = *RJSGetInternal(thisObject); - static_cast(realm->m_delegate.get())->remove_notification(callback); + static_cast(realm->m_binding_context.get())->remove_notification(callback); return NULL; } catch (std::exception &exp) { @@ -479,7 +479,7 @@ JSValueRef RealmRemoveAllListeners(JSContextRef ctx, JSObjectRef function, JSObj } SharedRealm realm = *RJSGetInternal(thisObject); - static_cast(realm->m_delegate.get())->remove_all_notifications(); + static_cast(realm->m_binding_context.get())->remove_all_notifications(); return NULL; } catch (std::exception &exp) { diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 913a03c7..df166946 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -81,7 +81,6 @@ void RJSInitializeInContext(JSContextRef ctx) { } void RJSClearTestState() { - realm::Realm::s_global_cache.close_all(); realm::Realm::s_global_cache.clear(); NSFileManager *manager = [NSFileManager defaultManager]; diff --git a/src/object-store/impl/transact_log_handler.cpp b/src/object-store/impl/transact_log_handler.cpp index fba97129..2deba2fd 100644 --- a/src/object-store/impl/transact_log_handler.cpp +++ b/src/object-store/impl/transact_log_handler.cpp @@ -18,25 +18,23 @@ #include "transact_log_handler.hpp" -#include "../realm_binding_context.hpp" +#include "../binding_context.hpp" #include #include #include -using namespace realm; - -namespace { +namespace realm { class TransactLogHandler { - using ColumnInfo = RealmBindingContext::ColumnInfo; - using ObserverState = RealmBindingContext::ObserverState; + using ColumnInfo = BindingContext::ColumnInfo; + using ObserverState = BindingContext::ObserverState; // Observed table rows which need change information std::vector m_observers; // Userdata pointers for rows which have been deleted std::vector invalidated; // Delegate to send change information to - RealmBindingContext* m_binding_context; + BindingContext* m_binding_context; // Index of currently selected table size_t m_current_table = 0; @@ -84,7 +82,7 @@ class TransactLogHandler { public: template - TransactLogHandler(RealmBindingContext* binding_context, SharedGroup& sg, Func&& func) + TransactLogHandler(BindingContext* binding_context, SharedGroup& sg, Func&& func) : m_binding_context(binding_context) { if (!binding_context) { @@ -325,19 +323,19 @@ public: namespace realm { namespace _impl { namespace transaction { -void advance(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) { +void advance(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context) { TransactLogHandler(binding_context, sg, [&](auto&&... args) { LangBindHelper::advance_read(sg, history, std::move(args)...); }); } -void begin(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) { +void begin(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context) { TransactLogHandler(binding_context, sg, [&](auto&&... args) { LangBindHelper::promote_to_write(sg, history, std::move(args)...); }); } -void commit(SharedGroup& sg, ClientHistory&, RealmBindingContext* binding_context) { +void commit(SharedGroup& sg, ClientHistory&, BindingContext* binding_context) { LangBindHelper::commit_and_continue_as_read(sg); if (binding_context) { @@ -345,7 +343,7 @@ void commit(SharedGroup& sg, ClientHistory&, RealmBindingContext* binding_contex } } -void cancel(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context) { +void cancel(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context) { TransactLogHandler(binding_context, sg, [&](auto&&... args) { LangBindHelper::rollback_and_continue_as_read(sg, history, std::move(args)...); }); diff --git a/src/object-store/impl/transact_log_handler.hpp b/src/object-store/impl/transact_log_handler.hpp index 321a67c9..40ddf3f6 100644 --- a/src/object-store/impl/transact_log_handler.hpp +++ b/src/object-store/impl/transact_log_handler.hpp @@ -20,7 +20,7 @@ #define REALM_TRANSACT_LOG_HANDLER_HPP namespace realm { -class RealmBindingContext; +class BindingContext; class SharedGroup; class ClientHistory; @@ -28,19 +28,19 @@ namespace _impl { namespace transaction { // Advance the read transaction version, with change notifications sent to delegate // Must not be called from within a write transaction. -void advance(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context); +void advance(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context); // Begin a write transaction // If the read transaction version is not up to date, will first advance to the // most recent read transaction and sent notifications to delegate -void begin(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context); +void begin(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context); // Commit a write transaction -void commit(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context); +void commit(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context); // Cancel a write transaction and roll back all changes, with change notifications // for reverting to the old values sent to delegate -void cancel(SharedGroup& sg, ClientHistory& history, RealmBindingContext* binding_context); +void cancel(SharedGroup& sg, ClientHistory& history, BindingContext* binding_context); } // namespace transaction } // namespace _impl } // namespace realm diff --git a/src/object-store/shared_realm.cpp b/src/object-store/shared_realm.cpp index c87dd5d4..09b4d188 100644 --- a/src/object-store/shared_realm.cpp +++ b/src/object-store/shared_realm.cpp @@ -203,7 +203,9 @@ bool Realm::update_schema(std::unique_ptr schema, uint64_t version) auto migration_function = [&](Group*, Schema&) { SharedRealm old_realm(new Realm(old_config)); auto updated_realm = shared_from_this(); - m_config.migration_function(old_realm, updated_realm); + if (m_config.migration_function) { + m_config.migration_function(old_realm, updated_realm); + } }; try {