From 0511bade62c32344d4e99a82d2610fbce0d514ff Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Tue, 27 Oct 2015 03:13:21 -0700 Subject: [PATCH] Non-existent object getters shouldn't throw exceptions --- src/RJSObject.mm | 4 +--- src/object-store/object_accessor.hpp | 2 +- tests/ObjectTests.js | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RJSObject.mm b/src/RJSObject.mm index c5f77bef..528a449d 100644 --- a/src/RJSObject.mm +++ b/src/RJSObject.mm @@ -34,9 +34,7 @@ JSValueRef ObjectGetProperty(JSContextRef ctx, JSObjectRef jsObject, JSStringRef Object *obj = RJSGetInternal(jsObject); return obj->get_property_value(ctx, RJSStringForJSString(jsPropertyName)); } catch (std::exception &ex) { - if (exception) { - *exception = RJSMakeError(ctx, ex); - } + // getters for nonexistent properties in JS should always return undefined return NULL; } } diff --git a/src/object-store/object_accessor.hpp b/src/object-store/object_accessor.hpp index 5636a2cb..1afdf772 100644 --- a/src/object-store/object_accessor.hpp +++ b/src/object-store/object_accessor.hpp @@ -117,7 +117,7 @@ namespace realm { { const Property *prop = object_schema.property_for_name(prop_name); 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(ctx, *prop); }; diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index 51f35e92..47aab7ab 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -44,6 +44,8 @@ module.exports = BaseTest.extend({ TestCase.assertEqual(object[prop.name], basicTypesValues[i]); } } + + TestCase.assertEqual(object.nonexistent, undefined); }, testBasicTypesPropertySetters: function() { var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];