fix for array enumeration, test array.push
This commit is contained in:
parent
5ccd232b68
commit
e84c81542f
|
@ -100,9 +100,9 @@ JSObjectRef RJSArrayCreate(JSContextRef ctx, realm::ObjectArray *array) {
|
||||||
|
|
||||||
JSClassRef RJSArrayClass() {
|
JSClassRef RJSArrayClass() {
|
||||||
const JSStaticFunction arrayFuncs[] = {
|
const JSStaticFunction arrayFuncs[] = {
|
||||||
{"push", ArrayPush},
|
{"push", ArrayPush, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
static JSClassRef s_objectClass = RJSCreateWrapperClass<Object>("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames);
|
static JSClassRef s_arrayClass = RJSCreateWrapperClass<Object>("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames);
|
||||||
return s_objectClass;
|
return s_arrayClass;
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,11 +335,11 @@ void RJSNotificationFinalize(JSObjectRef object) {
|
||||||
|
|
||||||
JSClassRef RJSRealmClass() {
|
JSClassRef RJSRealmClass() {
|
||||||
const JSStaticFunction realmFuncs[] = {
|
const JSStaticFunction realmFuncs[] = {
|
||||||
{"objects", RealmObjects},
|
{"objects", RealmObjects, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{"create", RealmCreateObject},
|
{"create", RealmCreateObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{"delete", RealmDelete},
|
{"delete", RealmDelete, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{"write", RealmWrite},
|
{"write", RealmWrite, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{"addNotification", RealmAddNotification},
|
{"addNotification", RealmAddNotification, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, realmFuncs);
|
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, realmFuncs);
|
||||||
|
|
|
@ -89,7 +89,7 @@ var ArrayTests = {
|
||||||
|
|
||||||
var obj = realm.objects('LinkTypesObject')[0];
|
var obj = realm.objects('LinkTypesObject')[0];
|
||||||
for (var object in obj.arrayCol) {
|
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() {
|
realm.write(function() {
|
||||||
|
@ -106,6 +106,25 @@ var ArrayTests = {
|
||||||
},
|
},
|
||||||
|
|
||||||
testPush: function() {
|
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]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,9 +73,13 @@ var TestCase = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
assertTrue: function(condition) {
|
assertTrue: function(condition, errorMessage) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
throw 'Condition expected to be true';
|
|
||||||
|
if (errorMessage == undefined) {
|
||||||
|
errorMessage = 'Condition expected to be true';
|
||||||
|
}
|
||||||
|
throw errorMessage;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue