diff --git a/src/RJSObject.mm b/src/RJSObject.mm index b0c9b41a..c4432cc0 100644 --- a/src/RJSObject.mm +++ b/src/RJSObject.mm @@ -86,7 +86,7 @@ template<> JSValueRef RJSAccessor::default_value_for_property(JSContextRef ctx, } template<> bool RJSAccessor::is_null(JSContextRef ctx, JSValueRef &val) { - return JSValueIsNull(ctx, val); + return JSValueIsNull(ctx, val) || JSValueIsUndefined(ctx, val); } template<> JSValueRef RJSAccessor::null_value(JSContextRef ctx) { return JSValueMakeNull(ctx); diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index b8778703..3f519e8b 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -146,17 +146,20 @@ module.exports = BaseTest.extend({ testNullableBasicTypesPropertySetters: function() { var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA']; var realm = new Realm({schema: [schemas.NullableBasicTypes]}); - var obj = null; + var obj, obj1; realm.write(function() { obj = realm.create('NullableBasicTypesObject', basicTypesValues); + obj1 = realm.create('NullableBasicTypesObject', basicTypesValues); for (var prop of schemas.NullableBasicTypes.properties) { obj[prop.name] = null; + obj1[prop.name] = undefined; } }); for (var prop of schemas.NullableBasicTypes.properties) { TestCase.assertEqual(obj[prop.name], null); + TestCase.assertEqual(obj1[prop.name], null); } realm.write(function() { @@ -166,28 +169,6 @@ module.exports = BaseTest.extend({ TestCase.assertThrows(function() { obj.intCol = 'dog'; }); - - TestCase.assertThrows(function() { - obj.boolCol = undefined; - }); - TestCase.assertThrows(function() { - obj.intCol = undefined; - }); - TestCase.assertThrows(function() { - obj.floatCol = undefined; - }); - TestCase.assertThrows(function() { - obj.doubleCol = undefined; - }); - TestCase.assertThrows(function() { - obj.stringCol = undefined; - }); - TestCase.assertThrows(function() { - obj.dateCol = undefined; - }); - TestCase.assertThrows(function() { - obj.dataCol = undefined; - }); }); TestCase.assertThrows(function() { diff --git a/tests/RealmTests.js b/tests/RealmTests.js index 5b1b5f45..e288dd7a 100644 --- a/tests/RealmTests.js +++ b/tests/RealmTests.js @@ -118,7 +118,7 @@ module.exports = BaseTest.extend({ TestCase.assertThrows(function() { realm.create('AllTypesObject', values); }); - realm.create('AllTypesObject', ['1', false, 2, 2.2, 2.11, '2', new Date(2), '2', null, [[2]]], true); + var obj1 = realm.create('AllTypesObject', ['1', false, 2, 2.2, 2.11, '2', new Date(2), '2', [0], [[2]]], true); var objects = realm.objects('AllTypesObject'); TestCase.assertEqual(objects.length, 2); @@ -135,7 +135,10 @@ module.exports = BaseTest.extend({ TestCase.assertEqual(obj0.arrayCol.length, 1); realm.create('AllTypesObject', { primaryCol: '0' }, true); + realm.create('AllTypesObject', { primaryCol: '1' }, true); TestCase.assertEqual(obj0.stringCol, '2'); + TestCase.assertEqual(obj0.objectCol, null); + TestCase.assertEqual(obj1.objectCol.doubleCol, 0); realm.create('AllTypesObject', { primaryCol: '0', stringCol: '3', objectCol: [0] }, true); TestCase.assertEqual(obj0.stringCol, '3'); @@ -147,6 +150,11 @@ module.exports = BaseTest.extend({ TestCase.assertEqual(obj0.dataCol, '2'); TestCase.assertEqual(obj0.objectCol.doubleCol, 0); TestCase.assertEqual(obj0.arrayCol.length, 1); + + realm.create('AllTypesObject', { primaryCol: '0', objectCol: undefined }, true); + realm.create('AllTypesObject', { primaryCol: '1', objectCol: null }, true); + TestCase.assertEqual(obj0.objectCol, null); + TestCase.assertEqual(obj1.objectCol, null); }); },