Merge pull request #96 from realm/sk-realmjs-api

Change RealmJS to provide a C API
This commit is contained in:
Scott Kyle 2015-10-26 12:08:42 -07:00
commit 6d4b8d1e7b
7 changed files with 20 additions and 22 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

@ -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 = "<group>"; };
02258FB21BC6E2D00075F13A /* RealmRPC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmRPC.mm; path = src/RealmRPC.mm; sourceTree = "<group>"; };
02258FB21BC6E2D00075F13A /* RealmRPC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RealmRPC.cpp; path = src/RealmRPC.cpp; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@ -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 */,

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