rename some methods for clarity - try to cleanup js objects

This commit is contained in:
Ari Lazier 2015-10-15 18:48:13 -07:00
parent 45a3c89605
commit 5ccc03eeb7
6 changed files with 21 additions and 16 deletions

View File

@ -83,9 +83,9 @@ class Realm {
Object.defineProperty(Realm, 'Types', {value: types});
Object.defineProperty(Realm, 'deleteTestFiles', {
Object.defineProperty(Realm, 'clearTestState', {
value: function() {
rpc.deleteTestFiles();
rpc.clearTestState();
}
});

View File

@ -37,7 +37,7 @@ exports.beginTransaction = beginTransaction;
exports.cancelTransaction = cancelTransaction;
exports.commitTransaction = commitTransaction;
exports.deleteTestFiles = deleteTestFiles;
exports.clearTestState = clearTestState;
function registerTypeConverter(type, handler) {
typeConverters[type] = handler;
@ -113,8 +113,8 @@ function commitTransaction(realmId) {
sendRequest('commit_transaction', {realmId});
}
function deleteTestFiles() {
sendRequest('delete_test_files');
function clearTestState() {
sendRequest('clear_test_state');
}
function serialize(realmId, value) {

View File

@ -25,6 +25,6 @@
// add realm apis to the given js context
+ (void)initializeContext:(JSContextRef)ctx;
+ (void)deleteTestFiles;
+ (void)clearTestState;
@end

View File

@ -55,8 +55,8 @@ NSString *RealmFileDirectory() {
#endif
}
static JSValueRef DeleteTestFiles(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
[RealmJS deleteTestFiles];
static JSValueRef ClearTestState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
[RealmJS clearTestState];
return NULL;
}
@ -73,15 +73,15 @@ static JSValueRef DeleteTestFiles(JSContextRef ctx, JSObjectRef function, JSObje
JSObjectSetProperty(ctx, globalRealmObject, typeString, typesObject, attributes, &exception);
JSStringRelease(typeString);
JSStringRef deleteTestFilesString = JSStringCreateWithUTF8CString("deleteTestFiles");
JSObjectRef deleteTestFilesFunction = JSObjectMakeFunctionWithCallback(ctx, deleteTestFilesString, DeleteTestFiles);
JSObjectSetProperty(ctx, globalRealmObject, deleteTestFilesString, deleteTestFilesFunction, attributes, &exception);
JSStringRelease(deleteTestFilesString);
JSStringRef clearTestStateString = JSStringCreateWithUTF8CString("clearTestState");
JSObjectRef clearTestStateFunction = JSObjectMakeFunctionWithCallback(ctx, clearTestStateString, ClearTestState);
JSObjectSetProperty(ctx, globalRealmObject, clearTestStateString, clearTestStateFunction, attributes, &exception);
JSStringRelease(clearTestStateString);
assert(!exception);
}
+ (void)deleteTestFiles {
+ (void)clearTestState {
realm::Realm::s_global_cache.invalidate_all();
realm::Realm::s_global_cache.clear();

View File

@ -195,8 +195,13 @@ using RPCRequest = std::function<NSDictionary *(NSDictionary *dictionary)>;
args:dict[@"arguments"]
objectId:[dict[@"listId"] unsignedLongValue]];
};
_requests["/delete_test_files"] = [=](NSDictionary *dict) {
[RealmJS deleteTestFiles];
_requests["/clear_test_state"] = [=](NSDictionary *dict) {
for (auto object : _objects) {
JSValueUnprotect(_context, object.second);
}
_objects.clear();
JSGarbageCollect(_context);
[RealmJS clearTestState];
return nil;
};
}

View File

@ -35,7 +35,7 @@ Object.defineProperties(prototype, {
afterEach: {
value: function() {
Realm.deleteTestFiles();
Realm.clearTestState();
}
}
});