From e578b05058dfbec2f3ee827849314a696fa338a4 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 17 Feb 2016 20:39:29 -0800 Subject: [PATCH] pr feedback --- src/js_list.cpp | 14 ++------------ src/js_results.cpp | 28 ++++++++++++++++------------ src/js_results.hpp | 2 ++ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/js_list.cpp b/src/js_list.cpp index c5d35c71..673bcb0b 100644 --- a/src/js_list.cpp +++ b/src/js_list.cpp @@ -6,8 +6,8 @@ #include "js_object.hpp" #include "js_results.hpp" #include "js_util.hpp" -#include "object_accessor.hpp" +#include "object_accessor.hpp" #include "parser.hpp" #include "query_builder.hpp" @@ -210,18 +210,8 @@ JSValueRef ListFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef this RJSValidateArgumentCountIsAtLeast(argumentCount, 1); SharedRealm sharedRealm = *RJSGetInternal(thisObject); - std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate"); - std::vector args; - for (size_t i = 1; i < argumentCount; i++) { - args.push_back(arguments[i]); - } - - parser::Predicate predicate = parser::parse(queryString); - query_builder::ArgumentConverter arguments(ctx, args); Query query = list->get_query(); - query_builder::apply_predicate(query, predicate, arguments, *sharedRealm->config().schema, list->get_object_schema().name); - - return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), query); + return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), query, argumentCount, arguments); } catch (std::exception &exp) { if (jsException) { diff --git a/src/js_results.cpp b/src/js_results.cpp index f05d7b57..8fae5e7f 100644 --- a/src/js_results.cpp +++ b/src/js_results.cpp @@ -125,19 +125,8 @@ JSValueRef ResultsFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef t RJSValidateArgumentCountIsAtLeast(argumentCount, 1); SharedRealm sharedRealm = *RJSGetInternal(thisObject); - std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate"); - std::vector args; - for (size_t i = 1; i < argumentCount; i++) { - args.push_back(arguments[i]); - } - - parser::Predicate predicate = parser::parse(queryString); - query_builder::ArgumentConverter arguments(ctx, args); Query query = results->get_query(); - query_builder::apply_predicate(query, predicate, arguments, *sharedRealm->config().schema, - results->get_object_schema().name); - - return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), query); + return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), query, argumentCount, arguments); } catch (std::exception &exp) { if (jsException) { @@ -171,6 +160,21 @@ JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, std::string cl return RJSWrapObject(ctx, RJSResultsClass(), new Results(realm, *object_schema, std::move(query))); } +JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]) { + std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate"); + std::vector args(argumentCount-1); + for (size_t i = 1; i < argumentCount; i++) { + args[i-1] = arguments[i]; + } + + parser::Predicate predicate = parser::parse(queryString); + query_builder::ArgumentConverter queryArgs(ctx, args); + query_builder::apply_predicate(query, predicate, queryArgs, *realm->config().schema, + objectSchema.name); + + return RJSResultsCreate(ctx, realm, objectSchema, query); +} + JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, const ObjectSchema &objectSchema, const Query &query, bool live) { Results *results = new Results(realm, objectSchema, query); results->set_live(live); diff --git a/src/js_results.hpp b/src/js_results.hpp index 8f6c212b..cc4f0a8e 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -16,4 +16,6 @@ namespace realm { JSClassRef RJSResultsClass(); JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className); JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className, std::string query, std::vector args); +JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]); JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, const realm::Query &query, bool live = true); +