From 5ccc03eeb739bc149fbc9823a83a1f951dbc29d0 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Thu, 15 Oct 2015 18:48:13 -0700 Subject: [PATCH] rename some methods for clarity - try to cleanup js objects --- lib/realm.js | 4 ++-- lib/rpc.js | 6 +++--- src/RealmJS.h | 2 +- src/RealmJS.mm | 14 +++++++------- src/RealmRPC.mm | 9 +++++++-- tests/base-test.js | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/realm.js b/lib/realm.js index 3110ec0a..ca56e2f6 100644 --- a/lib/realm.js +++ b/lib/realm.js @@ -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(); } }); diff --git a/lib/rpc.js b/lib/rpc.js index 5b489085..7bf4f65f 100644 --- a/lib/rpc.js +++ b/lib/rpc.js @@ -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) { diff --git a/src/RealmJS.h b/src/RealmJS.h index f10133ff..ad65e68b 100644 --- a/src/RealmJS.h +++ b/src/RealmJS.h @@ -25,6 +25,6 @@ // add realm apis to the given js context + (void)initializeContext:(JSContextRef)ctx; -+ (void)deleteTestFiles; ++ (void)clearTestState; @end diff --git a/src/RealmJS.mm b/src/RealmJS.mm index 5fb5a7d1..589ae7a4 100644 --- a/src/RealmJS.mm +++ b/src/RealmJS.mm @@ -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(); diff --git a/src/RealmRPC.mm b/src/RealmRPC.mm index 226ea192..fe95b778 100644 --- a/src/RealmRPC.mm +++ b/src/RealmRPC.mm @@ -195,8 +195,13 @@ using RPCRequest = std::function; 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; }; } diff --git a/tests/base-test.js b/tests/base-test.js index 99e382d9..b299e70e 100644 --- a/tests/base-test.js +++ b/tests/base-test.js @@ -35,7 +35,7 @@ Object.defineProperties(prototype, { afterEach: { value: function() { - Realm.deleteTestFiles(); + Realm.clearTestState(); } } });