support encrypted realm when getting schemaVersion

This commit is contained in:
Ari Lazier 2016-03-18 10:04:35 -07:00
parent 836cfc1c6b
commit 4b2e47a861
2 changed files with 18 additions and 1 deletions

View File

@ -239,10 +239,16 @@ static const JSStaticValue RealmStaticProperties[] = {
JSValueRef RealmSchemaVersion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try {
RJSValidateArgumentCount(argumentCount, 1);
RJSValidateArgumentRange(argumentCount, 1, 2);
Realm::Config config;
config.path = RJSNormalizePath(RJSValidatedStringForValue(ctx, arguments[0]));
if (argumentCount == 2) {
JSValueRef encryptionKeyValue = arguments[1];
std::string encryptionKey = RJSAccessor::to_binary(ctx, encryptionKeyValue);
config.encryption_key = std::vector<char>(encryptionKey.begin(), encryptionKey.end());
}
auto version = Realm::get_schema_version(config);
if (version == ObjectStore::NotVersioned) {
return JSValueMakeNumber(ctx, -1);

View File

@ -125,6 +125,17 @@ module.exports = BaseTest.extend({
realm = new Realm({schema: [], schemaVersion: 2, path: 'another.realm'});
TestCase.assertEqual(Realm.schemaVersion('another.realm'), 2);
var encryptionKey = new Int8Array(64);
realm = new Realm({schema: [], schemaVersion: 3, path: 'encrypted.realm', encryptionKey: encryptionKey});
TestCase.assertEqual(Realm.schemaVersion('encrypted.realm', encryptionKey), 3);
TestCase.assertThrows(function() {
Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
});
TestCase.assertThrows(function() {
Realm.schemaVersion('encrypted.realm', 'asdf');
});
},
testRealmCreate: function() {