diff --git a/src/RJSArray.cpp b/src/RJSArray.cpp index 38004fe9..b32ad848 100644 --- a/src/RJSArray.cpp +++ b/src/RJSArray.cpp @@ -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("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames); - return s_objectClass; + static JSClassRef s_arrayClass = RJSCreateWrapperClass("RealmArray", ArrayGetProperty, NULL, arrayFuncs, NULL, ArrayPropertyNames); + return s_arrayClass; } diff --git a/src/RJSRealm.mm b/src/RJSRealm.mm index a2712777..8138e560 100644 --- a/src/RJSRealm.mm +++ b/src/RJSRealm.mm @@ -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("Realm", RealmGetProperty, NULL, realmFuncs); diff --git a/tests/ArrayTests.js b/tests/ArrayTests.js index 6deda1a3..c4023300 100644 --- a/tests/ArrayTests.js +++ b/tests/ArrayTests.js @@ -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]); + }); } }; diff --git a/tests/TestCase.js b/tests/TestCase.js index 6e69b166..4fd25eb1 100644 --- a/tests/TestCase.js +++ b/tests/TestCase.js @@ -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; }; }, }