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, 'Types', {value: types});
Object.defineProperty(Realm, 'deleteTestFiles', { Object.defineProperty(Realm, 'clearTestState', {
value: function() { value: function() {
rpc.deleteTestFiles(); rpc.clearTestState();
} }
}); });

View File

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

View File

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

View File

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

View File

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

View File

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