Non-existent object getters shouldn't throw exceptions

This commit is contained in:
Scott Kyle 2015-10-27 03:13:21 -07:00 committed by Ari Lazier
parent 8e1eb661c5
commit 0511bade62
3 changed files with 4 additions and 4 deletions

View File

@ -34,9 +34,7 @@ JSValueRef ObjectGetProperty(JSContextRef ctx, JSObjectRef jsObject, JSStringRef
Object *obj = RJSGetInternal<Object *>(jsObject); Object *obj = RJSGetInternal<Object *>(jsObject);
return obj->get_property_value<JSValueRef>(ctx, RJSStringForJSString(jsPropertyName)); return obj->get_property_value<JSValueRef>(ctx, RJSStringForJSString(jsPropertyName));
} catch (std::exception &ex) { } catch (std::exception &ex) {
if (exception) { // getters for nonexistent properties in JS should always return undefined
*exception = RJSMakeError(ctx, ex);
}
return NULL; return NULL;
} }
} }

View File

@ -117,7 +117,7 @@ namespace realm {
{ {
const Property *prop = object_schema.property_for_name(prop_name); const Property *prop = object_schema.property_for_name(prop_name);
if (!prop) { if (!prop) {
throw std::runtime_error("Setting invalid property '" + prop_name + "' on object '" + object_schema.name + "'."); throw std::runtime_error("Getting invalid property '" + prop_name + "' on object '" + object_schema.name + "'.");
} }
return get_property_value_impl<ValueType>(ctx, *prop); return get_property_value_impl<ValueType>(ctx, *prop);
}; };

View File

@ -44,6 +44,8 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(object[prop.name], basicTypesValues[i]); TestCase.assertEqual(object[prop.name], basicTypesValues[i]);
} }
} }
TestCase.assertEqual(object.nonexistent, undefined);
}, },
testBasicTypesPropertySetters: function() { testBasicTypesPropertySetters: function() {
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA']; var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];