mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Merge branch 'sk-test-suite' of https://github.com/realm/realm-js into sk-test-suite
This commit is contained in:
commit
430b2a29e5
@ -65,6 +65,13 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor) {
|
|||||||
id executor = object_getIvar(bridge, executorIvar);
|
id executor = object_getIvar(bridge, executorIvar);
|
||||||
Ivar contextIvar = class_getInstanceVariable([executor class], "_context");
|
Ivar contextIvar = class_getInstanceVariable([executor class], "_context");
|
||||||
|
|
||||||
|
static GCDWebServer *s_webServer;
|
||||||
|
if (s_webServer) {
|
||||||
|
[s_webServer stop];
|
||||||
|
[s_webServer removeAllHandlers];
|
||||||
|
s_webServer = nil;
|
||||||
|
}
|
||||||
|
|
||||||
// The executor could be a RCTWebSocketExecutor, in which case it won't have a JS context.
|
// The executor could be a RCTWebSocketExecutor, in which case it won't have a JS context.
|
||||||
if (!contextIvar) {
|
if (!contextIvar) {
|
||||||
[GCDWebServer setLogLevel:3];
|
[GCDWebServer setLogLevel:3];
|
||||||
@ -90,9 +97,11 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor) {
|
|||||||
|
|
||||||
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
|
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
|
||||||
return response;
|
return response;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[webServer startWithPort:8082 bonjourName:nil];
|
[webServer startWithPort:8082 bonjourName:nil];
|
||||||
|
|
||||||
|
s_webServer = webServer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,3 +31,4 @@ realm::Schema RJSParseSchema(JSContextRef ctx, JSObjectRef jsonObject);
|
|||||||
|
|
||||||
JSValueRef RJSPrototypeForClassName(const std::string &className);
|
JSValueRef RJSPrototypeForClassName(const std::string &className);
|
||||||
realm::ObjectDefaults &RJSDefaultsForClassName(const std::string &className);
|
realm::ObjectDefaults &RJSDefaultsForClassName(const std::string &className);
|
||||||
|
void RJSSchemaClearState(JSContextRef ctx);
|
@ -55,6 +55,20 @@ JSValueRef RJSPrototypeForClassName(const std::string &className) {
|
|||||||
return s_prototypes[className];
|
return s_prototypes[className];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RJSSchemaClearState(JSContextRef ctx) {
|
||||||
|
for (auto prototype : s_prototypes) {
|
||||||
|
JSValueUnprotect(ctx, prototype.second);
|
||||||
|
}
|
||||||
|
s_prototypes.clear();
|
||||||
|
|
||||||
|
for (auto defaults : s_defaults) {
|
||||||
|
for (auto value : defaults.second) {
|
||||||
|
JSValueUnprotect(ctx, value.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s_defaults.clear();
|
||||||
|
}
|
||||||
|
|
||||||
static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyObject) {
|
static inline Property RJSParseProperty(JSContextRef ctx, JSObjectRef propertyObject) {
|
||||||
static JSStringRef nameString = JSStringCreateWithUTF8CString("name");
|
static JSStringRef nameString = JSStringCreateWithUTF8CString("name");
|
||||||
static JSStringRef typeString = JSStringCreateWithUTF8CString("type");
|
static JSStringRef typeString = JSStringCreateWithUTF8CString("type");
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#import "RJSRealm.hpp"
|
#import "RJSRealm.hpp"
|
||||||
#import "RJSObject.hpp"
|
#import "RJSObject.hpp"
|
||||||
#import "RJSUtil.hpp"
|
#import "RJSUtil.hpp"
|
||||||
|
#import "RJSSchema.hpp"
|
||||||
|
|
||||||
#include "shared_realm.hpp"
|
#include "shared_realm.hpp"
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ NSString *RealmFileDirectory() {
|
|||||||
|
|
||||||
static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
|
static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
|
||||||
[RealmJS clearTestState];
|
[RealmJS clearTestState];
|
||||||
|
RJSSchemaClearState(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +41,23 @@ using RPCRequest = std::function<NSDictionary *(NSDictionary *dictionary)>;
|
|||||||
std::map<RPCObjectID, JSObjectRef> _objects;
|
std::map<RPCObjectID, JSObjectRef> _objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
for (auto item : _objects) {
|
||||||
|
JSValueUnprotect(_context, item.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSGlobalContextRelease(_context);
|
||||||
|
_requests.clear();
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
_context = JSGlobalContextCreate(NULL);
|
_context = JSGlobalContextCreate(NULL);
|
||||||
|
|
||||||
|
id _self = self;
|
||||||
|
__weak __typeof__(self) self = _self;
|
||||||
|
|
||||||
_requests["/create_realm"] = [=](NSDictionary *dict) {
|
_requests["/create_realm"] = [=](NSDictionary *dict) {
|
||||||
NSArray *args = dict[@"arguments"];
|
NSArray *args = dict[@"arguments"];
|
||||||
NSUInteger argCount = args.count;
|
NSUInteger argCount = args.count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user