From 2b48ebb30ab0dafc254bb4df22b96223ddb2c782 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 13 Jun 2016 14:07:50 -0700 Subject: [PATCH] negate if statements --- src/js_object_accessor.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index cccf6e23..bcfc06fb 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -122,14 +122,16 @@ struct NativeAccessor { } static size_t to_existing_object_index(ContextType ctx, SharedRealm realm, ValueType &value) { ObjectType object = Value::validated_to_object(ctx, value); - if (Object::template is_instance>(ctx, object)) { - auto realm_object = get_internal>(object); - if (realm_object->realm() == realm) { - return realm_object->row().get_index(); - } - throw std::runtime_error("Realm object is from another Realm"); + if (!Object::template is_instance>(ctx, object)) { + throw std::runtime_error("object is not a Realm Object"); } - throw std::runtime_error("object is not a Realm Object"); + + auto realm_object = get_internal>(object); + if (realm_object->realm() != realm) { + throw std::runtime_error("Realm object is from another Realm"); + + } + return realm_object->row().get_index(); } static ValueType from_object(ContextType ctx, realm::Object realm_object) { return RealmObjectClass::create_instance(ctx, std::move(realm_object));