From 665e63aa6fa9e12b4e91d6cfc0e4962ad1fab720 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 8 Oct 2015 15:30:29 -0700 Subject: [PATCH] Handle exceptions when getting size through RPC --- src/RealmRPC.mm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/RealmRPC.mm b/src/RealmRPC.mm index f1bba068..d50d7e9a 100644 --- a/src/RealmRPC.mm +++ b/src/RealmRPC.mm @@ -114,8 +114,12 @@ using RPCRequest = std::function; JSValueRef exception = NULL; static JSStringRef lengthPropertyName = JSStringCreateWithUTF8CString("length"); JSValueRef lengthValue = ResultsGetProperty(_context, _objects[resultsId], lengthPropertyName, &exception); - - return @{@"result": @(JSValueToNumber(_context, lengthValue, &exception))}; + size_t length = JSValueToNumber(_context, lengthValue, &exception); + + if (exception) { + return @{@"error": @(RJSStringForValue(_context, exception).c_str())}; + } + return @{@"result": @(length)}; }; _requests["/get_results_item"] = [=](NSDictionary *dict) { RPCObjectID resultsId = [dict[@"resultsId"] unsignedLongValue]; @@ -129,7 +133,6 @@ using RPCRequest = std::function; if (exception) { return @{@"error": @(RJSStringForValue(_context, exception).c_str())}; } - return @{@"result": [self resultForJSValue:objectValue]}; }; _requests["/get_list_size"] = [=](NSDictionary *dict) { @@ -138,7 +141,12 @@ using RPCRequest = std::function; JSValueRef exception = NULL; static JSStringRef lengthPropertyName = JSStringCreateWithUTF8CString("length"); JSValueRef lengthValue = ArrayGetProperty(_context, _objects[listId], lengthPropertyName, &exception); - return @{@"result": @(JSValueToNumber(_context, lengthValue, &exception))}; + size_t length = JSValueToNumber(_context, lengthValue, &exception); + + if (exception) { + return @{@"error": @(RJSStringForValue(_context, exception).c_str())}; + } + return @{@"result": @(length)}; }; _requests["/get_list_item"] = [=](NSDictionary *dict) { RPCObjectID listId = [dict[@"listId"] unsignedLongValue];