Expose RealmJS API as C functions

We're still using Objective-C to delete test files, so we can't rename the implementation file quite yet.
This commit is contained in:
Scott Kyle 2015-10-26 01:14:33 -07:00
parent 4d73c13466
commit 0843d69a4f
6 changed files with 16 additions and 18 deletions

View File

@ -134,7 +134,7 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
[executor executeBlockOnJavaScriptQueue:^{
JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true);
[RealmJS initializeContext:ctx];
RJSInitializeInContext(ctx);
}];
}

View File

@ -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;
}

View File

@ -16,13 +16,15 @@
//
////////////////////////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JavaScriptCore.h>
@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

View File

@ -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

View File

@ -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();
};
}

View File

@ -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"];