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/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.mm index a44a8a55..0d82cc47 100644 --- a/src/RealmRPC.mm +++ b/src/RealmRPC.mm @@ -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"];