store ObjectSchema as a pointer rather than a reference
This commit is contained in:
parent
aa5e1bef7d
commit
df901c636f
|
@ -21,7 +21,7 @@ JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pro
|
||||||
return JSValueMakeNumber(ctx, size);
|
return JSValueMakeNumber(ctx, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(RJSValidatedPositiveIndex(indexStr))));
|
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(RJSValidatedPositiveIndex(indexStr))));
|
||||||
}
|
}
|
||||||
catch (std::out_of_range &exp) {
|
catch (std::out_of_range &exp) {
|
||||||
// getters for nonexistent properties in JS should always return undefined
|
// getters for nonexistent properties in JS should always return undefined
|
||||||
|
@ -103,7 +103,7 @@ JSValueRef ListPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObjec
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
size_t index = size - 1;
|
size_t index = size - 1;
|
||||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
|
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
|
||||||
list->remove(index);
|
list->remove(index);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ JSValueRef ListShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj
|
||||||
list->verify_in_tranaction();
|
list->verify_in_tranaction();
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(0)));
|
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(0)));
|
||||||
list->remove(0);
|
list->remove(0);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb
|
||||||
|
|
||||||
std::vector<JSObjectRef> removedObjects(remove);
|
std::vector<JSObjectRef> removedObjects(remove);
|
||||||
for (size_t i = 0; i < remove; i++) {
|
for (size_t i = 0; i < remove; i++) {
|
||||||
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
|
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
|
||||||
list->remove(index);
|
list->remove(index);
|
||||||
}
|
}
|
||||||
for (size_t i = 2; i < argumentCount; i++) {
|
for (size_t i = 2; i < argumentCount; i++) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef
|
||||||
}
|
}
|
||||||
|
|
||||||
return RJSObjectCreate(ctx, Object(results->get_realm(),
|
return RJSObjectCreate(ctx, Object(results->get_realm(),
|
||||||
results->object_schema,
|
results->object_schema(),
|
||||||
results->get(RJSValidatedPositiveIndex(indexStr))));
|
results->get(RJSValidatedPositiveIndex(indexStr))));
|
||||||
}
|
}
|
||||||
catch (std::out_of_range &exp) {
|
catch (std::out_of_range &exp) {
|
||||||
|
@ -76,9 +76,9 @@ JSValueRef SortByProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef th
|
||||||
Results *results = RJSGetInternal<Results *>(thisObject);
|
Results *results = RJSGetInternal<Results *>(thisObject);
|
||||||
RJSValidateArgumentRange(argumentCount, 1, 2);
|
RJSValidateArgumentRange(argumentCount, 1, 2);
|
||||||
std::string propName = RJSValidatedStringForValue(ctx, arguments[0]);
|
std::string propName = RJSValidatedStringForValue(ctx, arguments[0]);
|
||||||
const Property *prop = results->object_schema.property_for_name(propName);
|
const Property *prop = results->object_schema().property_for_name(propName);
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->object_schema.name + "'");
|
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->object_schema().name + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ascending = true;
|
bool ascending = true;
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
namespace realm {
|
namespace realm {
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), object_schema(s), m_link_view(l) {}
|
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {}
|
||||||
|
|
||||||
const ObjectSchema &object_schema;
|
const ObjectSchema &object_schema() const { return *m_object_schema; }
|
||||||
SharedRealm realm() { return m_realm; }
|
SharedRealm realm() { return m_realm; }
|
||||||
|
|
||||||
size_t size();
|
size_t size();
|
||||||
|
@ -53,6 +53,7 @@ namespace realm {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedRealm m_realm;
|
SharedRealm m_realm;
|
||||||
|
const ObjectSchema *m_object_schema;
|
||||||
LinkViewRef m_link_view;
|
LinkViewRef m_link_view;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,19 +308,19 @@ namespace realm {
|
||||||
template<typename ValueType, typename ContextType>
|
template<typename ValueType, typename ContextType>
|
||||||
void List::add(ContextType ctx, ValueType value)
|
void List::add(ContextType ctx, ValueType value)
|
||||||
{
|
{
|
||||||
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ValueType, typename ContextType>
|
template<typename ValueType, typename ContextType>
|
||||||
void List::insert(ContextType ctx, ValueType value, size_t list_ndx)
|
void List::insert(ContextType ctx, ValueType value, size_t list_ndx)
|
||||||
{
|
{
|
||||||
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ValueType, typename ContextType>
|
template<typename ValueType, typename ContextType>
|
||||||
void List::set(ContextType ctx, ValueType value, size_t list_ndx)
|
void List::set(ContextType ctx, ValueType value, size_t list_ndx)
|
||||||
{
|
{
|
||||||
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
|
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s)
|
||||||
, m_table(m_query.get_table().get())
|
, m_table(m_query.get_table().get())
|
||||||
, m_sort(std::move(s))
|
, m_sort(std::move(s))
|
||||||
, m_mode(Mode::Query)
|
, m_mode(Mode::Query)
|
||||||
, object_schema(o)
|
, m_object_schema(&o)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,21 +48,10 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Table& table)
|
||||||
: m_realm(std::move(r))
|
: m_realm(std::move(r))
|
||||||
, m_table(&table)
|
, m_table(&table)
|
||||||
, m_mode(Mode::Table)
|
, m_mode(Mode::Table)
|
||||||
, object_schema(o)
|
, m_object_schema(&o)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Results& Results::operator=(Results const& r)
|
|
||||||
{
|
|
||||||
m_realm = r.m_realm;
|
|
||||||
m_table = r.m_table;
|
|
||||||
m_sort = r.m_sort;
|
|
||||||
m_query = r.get_query();
|
|
||||||
m_mode = Mode::Query;
|
|
||||||
const_cast<ObjectSchema &>(object_schema) = r.object_schema;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Results::validate_read() const
|
void Results::validate_read() const
|
||||||
{
|
{
|
||||||
if (m_realm)
|
if (m_realm)
|
||||||
|
@ -171,7 +160,7 @@ size_t Results::index_of(Row const& row)
|
||||||
throw DetatchedAccessorException{};
|
throw DetatchedAccessorException{};
|
||||||
}
|
}
|
||||||
if (m_table && row.get_table() != m_table) {
|
if (m_table && row.get_table() != m_table) {
|
||||||
throw IncorrectTableException(object_schema.name,
|
throw IncorrectTableException(m_object_schema->name,
|
||||||
ObjectStore::object_type_for_table_name(row.get_table()->get_name()),
|
ObjectStore::object_type_for_table_name(row.get_table()->get_name()),
|
||||||
"Attempting to get the index of a Row of the wrong type"
|
"Attempting to get the index of a Row of the wrong type"
|
||||||
);
|
);
|
||||||
|
@ -326,12 +315,12 @@ TableView Results::get_tableview()
|
||||||
|
|
||||||
Results Results::sort(realm::SortOrder&& sort) const
|
Results Results::sort(realm::SortOrder&& sort) const
|
||||||
{
|
{
|
||||||
return Results(m_realm, object_schema, get_query(), std::move(sort));
|
return Results(m_realm, object_schema(), get_query(), std::move(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
Results Results::filter(Query&& q) const
|
Results Results::filter(Query&& q) const
|
||||||
{
|
{
|
||||||
return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort());
|
return Results(m_realm, object_schema(), get_query().and_query(std::move(q)), get_sort());
|
||||||
}
|
}
|
||||||
|
|
||||||
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table)
|
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table)
|
||||||
|
|
|
@ -53,13 +53,13 @@ public:
|
||||||
Results(Results const&) = default;
|
Results(Results const&) = default;
|
||||||
Results(Results&&) = default;
|
Results(Results&&) = default;
|
||||||
Results& operator=(Results&&) = default;
|
Results& operator=(Results&&) = default;
|
||||||
Results& operator=(Results const&);
|
Results& operator=(Results const&) = default;
|
||||||
|
|
||||||
// Get the Realm
|
// Get the Realm
|
||||||
SharedRealm get_realm() const { return m_realm; }
|
SharedRealm get_realm() const { return m_realm; }
|
||||||
|
|
||||||
// Object schema describing the vendored object type
|
// Object schema describing the vendored object type
|
||||||
const ObjectSchema &object_schema;
|
const ObjectSchema &object_schema() const { return *m_object_schema; }
|
||||||
|
|
||||||
// Get a query which will match the same rows as is contained in this Results
|
// Get a query which will match the same rows as is contained in this Results
|
||||||
// Returned query will not be valid if the current mode is Empty
|
// Returned query will not be valid if the current mode is Empty
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
TableView get_tableview();
|
TableView get_tableview();
|
||||||
|
|
||||||
// Get the object type which will be returned by get()
|
// Get the object type which will be returned by get()
|
||||||
StringData get_object_type() const noexcept { return object_schema.name; }
|
StringData get_object_type() const noexcept { return object_schema().name; }
|
||||||
|
|
||||||
// Get the size of this results
|
// Get the size of this results
|
||||||
// Can be either O(1) or O(N) depending on the state of things
|
// Can be either O(1) or O(N) depending on the state of things
|
||||||
|
@ -163,6 +163,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedRealm m_realm;
|
SharedRealm m_realm;
|
||||||
|
const ObjectSchema *m_object_schema;
|
||||||
Query m_query;
|
Query m_query;
|
||||||
TableView m_table_view;
|
TableView m_table_view;
|
||||||
Table* m_table = nullptr;
|
Table* m_table = nullptr;
|
||||||
|
|
|
@ -229,7 +229,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
|
||||||
{"type", RJSTypeGet(realm::PropertyTypeArray)},
|
{"type", RJSTypeGet(realm::PropertyTypeArray)},
|
||||||
{"id", store_object(js_object)},
|
{"id", store_object(js_object)},
|
||||||
{"size", list->size()},
|
{"size", list->size()},
|
||||||
{"schema", serialize_object_schema(list->object_schema)}
|
{"schema", serialize_object_schema(list->object_schema())}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (JSValueIsObjectOfClass(m_context, value, RJSResultsClass())) {
|
else if (JSValueIsObjectOfClass(m_context, value, RJSResultsClass())) {
|
||||||
|
@ -238,7 +238,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
|
||||||
{"type", RealmObjectTypesResults},
|
{"type", RealmObjectTypesResults},
|
||||||
{"id", store_object(js_object)},
|
{"id", store_object(js_object)},
|
||||||
{"size", results->size()},
|
{"size", results->size()},
|
||||||
{"schema", serialize_object_schema(results->object_schema)}
|
{"schema", serialize_object_schema(results->object_schema())}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (RJSIsValueArray(m_context, value)) {
|
else if (RJSIsValueArray(m_context, value)) {
|
||||||
|
|
Loading…
Reference in New Issue