allow setting nullable properties to undefined

This commit is contained in:
Ari Lazier 2015-11-02 10:08:23 -08:00
parent 36a5a9710a
commit 196a0a15a4
2 changed files with 5 additions and 24 deletions

View File

@ -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);

View File

@ -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() {