diff --git a/ReactNative/RealmReact.mm b/ReactNative/RealmReact.mm index 84e24119..14bd7525 100644 --- a/ReactNative/RealmReact.mm +++ b/ReactNative/RealmReact.mm @@ -134,7 +134,7 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre [executor executeBlockOnJavaScriptQueue:^{ JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true); - [RealmJS initializeContext:ctx]; + RJSInitializeInContext(ctx); }]; } diff --git a/RealmJS.xcodeproj/project.pbxproj b/RealmJS.xcodeproj/project.pbxproj index c0a97443..69826c17 100644 --- a/RealmJS.xcodeproj/project.pbxproj +++ b/RealmJS.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 02258FB31BC6E2D00075F13A /* RealmRPC.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02258FB11BC6E2D00075F13A /* RealmRPC.hpp */; settings = {ATTRIBUTES = (Public, ); }; }; - 02258FB41BC6E2D00075F13A /* RealmRPC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02258FB21BC6E2D00075F13A /* RealmRPC.mm */; }; + 02258FB41BC6E2D00075F13A /* RealmRPC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02258FB21BC6E2D00075F13A /* RealmRPC.cpp */; }; 02409DC21BCF11D6005F3B3E /* RealmJSCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */; settings = {ASSET_TAGS = (); }; }; 02601F031BA0F0C4007C91FF /* external_commit_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F011BA0F0C4007C91FF /* external_commit_helper.cpp */; }; 02601F041BA0F0C4007C91FF /* external_commit_helper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */; }; @@ -158,7 +158,7 @@ /* Begin PBXFileReference section */ 02258FB11BC6E2D00075F13A /* RealmRPC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RealmRPC.hpp; path = src/RealmRPC.hpp; sourceTree = ""; }; - 02258FB21BC6E2D00075F13A /* RealmRPC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmRPC.mm; path = src/RealmRPC.mm; sourceTree = ""; }; + 02258FB21BC6E2D00075F13A /* RealmRPC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RealmRPC.cpp; path = src/RealmRPC.cpp; sourceTree = ""; }; 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmJSCoreTests.m; path = tests/RealmJSCoreTests.m; sourceTree = SOURCE_ROOT; }; 02601F011BA0F0C4007C91FF /* external_commit_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = external_commit_helper.cpp; path = "src/object-store/apple/external_commit_helper.cpp"; sourceTree = ""; }; 02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = external_commit_helper.hpp; path = "src/object-store/apple/external_commit_helper.hpp"; sourceTree = ""; }; @@ -279,7 +279,7 @@ 0270BC3E1B7CFC0D00010E03 /* RealmJS.h */, 0270BC3F1B7CFC0D00010E03 /* RealmJS.mm */, 02258FB11BC6E2D00075F13A /* RealmRPC.hpp */, - 02258FB21BC6E2D00075F13A /* RealmRPC.mm */, + 02258FB21BC6E2D00075F13A /* RealmRPC.cpp */, 0270BC401B7CFC0D00010E03 /* RJSList.cpp */, 0270BC411B7CFC0D00010E03 /* RJSList.hpp */, 0270BC421B7CFC0D00010E03 /* RJSObject.hpp */, @@ -643,7 +643,7 @@ 0270BC511B7CFC0D00010E03 /* RJSObject.mm in Sources */, 0270BC4D1B7CFC0D00010E03 /* RealmJS.mm in Sources */, 02601F081BA0F0CD007C91FF /* index_set.cpp in Sources */, - 02258FB41BC6E2D00075F13A /* RealmRPC.mm in Sources */, + 02258FB41BC6E2D00075F13A /* RealmRPC.cpp in Sources */, 02601F111BA10228007C91FF /* transact_log_handler.cpp in Sources */, 0270BC591B7CFC0D00010E03 /* RJSUtil.mm in Sources */, 0270BC551B7CFC0D00010E03 /* RJSResults.mm in Sources */, diff --git a/examples/cordova/platforms/ios/RealmExample/Classes/AppDelegate.m b/examples/cordova/platforms/ios/RealmExample/Classes/AppDelegate.m index 7d4d03e9..ea67d9f7 100644 --- a/examples/cordova/platforms/ios/RealmExample/Classes/AppDelegate.m +++ b/examples/cordova/platforms/ios/RealmExample/Classes/AppDelegate.m @@ -90,7 +90,7 @@ [self.window makeKeyAndVisible]; JSContext *ctx = [self.viewController.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; - [RealmJS initializeContext:ctx.JSGlobalContextRef]; + RJSInitializeInContext(ctx.JSGlobalContextRef); return YES; } diff --git a/src/RealmJS.h b/src/RealmJS.h index 880d478e..a6bb8759 100644 --- a/src/RealmJS.h +++ b/src/RealmJS.h @@ -16,13 +16,15 @@ // //////////////////////////////////////////////////////////////////////////// -#import #import -@interface RealmJS : NSObject +#ifdef __cplusplus +extern "C" { +#endif -// add realm apis to the given js context -+ (void)initializeContext:(JSContextRef)ctx; -+ (void)clearTestState; +void RJSInitializeInContext(JSContextRef ctx); +void RJSClearTestState(void); -@end +#ifdef __cplusplus +} +#endif diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 59699320..c87d9969 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -57,13 +57,11 @@ NSString *RealmFileDirectory() { } static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { - [RealmJS clearTestState]; + RJSClearTestState(); return NULL; } -@implementation RealmJS - -+ (void)initializeContext:(JSContextRef)ctx { +void RJSInitializeInContext(JSContextRef ctx) { JSValueRef exception = NULL; JSObjectRef globalObject = JSContextGetGlobalObject(ctx); @@ -82,7 +80,7 @@ static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjec assert(!exception); } -+ (void)clearTestState { +void RJSClearTestState() { realm::Realm::s_global_cache.close_all(); realm::Realm::s_global_cache.clear(); @@ -94,5 +92,3 @@ static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjec } } } - -@end diff --git a/src/RealmRPC.mm b/src/RealmRPC.cpp similarity index 99% rename from src/RealmRPC.mm rename to src/RealmRPC.cpp index a44a8a55..0d82cc47 100644 --- a/src/RealmRPC.mm +++ b/src/RealmRPC.cpp @@ -49,7 +49,7 @@ RPCServer::RPCServer() { } m_requests["/create_session"] = [this](const json dict) { - [RealmJS initializeContext:m_context]; + RJSInitializeInContext(m_context); JSStringRef realm_string = RJSStringForString("Realm"); JSObjectRef realm_constructor = RJSValidatedObjectProperty(m_context, JSContextGetGlobalObject(m_context), realm_string); @@ -173,7 +173,7 @@ RPCServer::RPCServer() { m_objects.erase(object.first); } JSGarbageCollect(m_context); - [RealmJS clearTestState]; + RJSClearTestState(); return json::object(); }; } diff --git a/tests/RealmJSCoreTests.m b/tests/RealmJSCoreTests.m index 964aaf3b..11df0a58 100644 --- a/tests/RealmJSCoreTests.m +++ b/tests/RealmJSCoreTests.m @@ -34,7 +34,7 @@ RJSModuleLoader *moduleLoader = [[RJSModuleLoader alloc] initWithContext:context]; NSURL *scriptURL = [[NSBundle bundleForClass:self] URLForResource:@"index" withExtension:@"js"]; - [RealmJS initializeContext:context.JSGlobalContextRef]; + RJSInitializeInContext(context.JSGlobalContextRef); // Expose the global Realm object as a global 'realm' CommonJS module. [moduleLoader addGlobalModuleObject:context[@"Realm"] forName:@"realm"];