From 196a0a15a4be616f068d92882db6c2a914f7811b Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 2 Nov 2015 10:08:23 -0800 Subject: [PATCH] allow setting nullable properties to undefined --- src/RJSObject.mm | 2 +- tests/ObjectTests.js | 27 ++++----------------------- 2 files changed, 5 insertions(+), 24 deletions(-) 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() {