fix for array enumeration, test array.push

This commit is contained in:
Ari Lazier 2015-08-27 13:33:20 -07:00
parent 5ccd232b68
commit e84c81542f
4 changed files with 35 additions and 12 deletions

View File

@ -100,9 +100,9 @@ JSObjectRef RJSArrayCreate(JSContextRef ctx, realm::ObjectArray *array) {
JSClassRef RJSArrayClass() {
const JSStaticFunction arrayFuncs[] = {
{"push", ArrayPush},
{"push", ArrayPush, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL},
};
static JSClassRef s_objectClass = RJSCreateWrapperClass<Object>("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames);
return s_objectClass;
static JSClassRef s_arrayClass = RJSCreateWrapperClass<Object>("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames);
return s_arrayClass;
}

View File

@ -335,11 +335,11 @@ void RJSNotificationFinalize(JSObjectRef object) {
JSClassRef RJSRealmClass() {
const JSStaticFunction realmFuncs[] = {
{"objects", RealmObjects},
{"create", RealmCreateObject},
{"delete", RealmDelete},
{"write", RealmWrite},
{"addNotification", RealmAddNotification},
{"objects", RealmObjects, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"create", RealmCreateObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"delete", RealmDelete, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"write", RealmWrite, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"addNotification", RealmAddNotification, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL},
};
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, realmFuncs);

View File

@ -89,7 +89,7 @@ var ArrayTests = {
var obj = realm.objects('LinkTypesObject')[0];
for (var object in obj.arrayCol) {
TestCase.assertTrue(false, "No objects should have been enumerated");
TestCase.assertTrue(false, "No objects should have been enumerated: " + object);
}
realm.write(function() {
@ -106,6 +106,25 @@ var ArrayTests = {
},
testPush: function() {
var realm = new Realm({schema: [LinkTypesObjectSchema, TestObjectSchema]});
var array;
realm.write(function() {
var obj = realm.create('LinkTypesObject', [[1], [2], [[3]]]);
TestCase.assertEqual(obj.arrayCol.length, 1);
array = obj.arrayCol;
array.push([4]);
TestCase.assertEqual(array.length, 2);
TestCase.assertEqual(array[1].doubleCol, 4);
array.push(obj.objectCol);
TestCase.assertEqual(array.length, 3);
TestCase.assertEqual(array[2].doubleCol, 1);
});
TestCase.assertEqual(array.length, 3);
TestCase.assertThrows(function() {
array.push([1]);
});
}
};

View File

@ -73,9 +73,13 @@ var TestCase = {
};
},
assertTrue: function(condition) {
assertTrue: function(condition, errorMessage) {
if (!condition) {
throw 'Condition expected to be true';
if (errorMessage == undefined) {
errorMessage = 'Condition expected to be true';
}
throw errorMessage;
};
},
}