mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 14:54:33 +00:00
Non-existent object getters shouldn't throw exceptions
This commit is contained in:
parent
8e1eb661c5
commit
0511bade62
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
};
|
};
|
||||||
|
@ -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'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user