support encrypted realm when getting schemaVersion
This commit is contained in:
parent
836cfc1c6b
commit
4b2e47a861
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue