• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / github_pull_request_312964

19 Feb 2025 07:31PM UTC coverage: 90.814% (-0.3%) from 91.119%
github_pull_request_312964

Pull #8071

Evergreen

web-flow
Bump serialize-javascript and mocha

Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) to 6.0.2 and updates ancestor dependency [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `serialize-javascript` from 6.0.0 to 6.0.2
- [Release notes](https://github.com/yahoo/serialize-javascript/releases)
- [Commits](https://github.com/yahoo/serialize-javascript/compare/v6.0.0...v6.0.2)

Updates `mocha` from 10.2.0 to 10.8.2
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v10.2.0...v10.8.2)

---
updated-dependencies:
- dependency-name: serialize-javascript
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #8071: Bump serialize-javascript and mocha

96552 of 179126 branches covered (53.9%)

212672 of 234185 relevant lines covered (90.81%)

3115802.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.28
/src/realm/object-store/object.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2017 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <realm/object-store/object.hpp>
20

21
#include <realm/object-store/impl/object_notifier.hpp>
22
#include <realm/object-store/impl/realm_coordinator.hpp>
23
#include <realm/object-store/object_schema.hpp>
24
#include <realm/object-store/object_store.hpp>
25
#include <realm/object-store/audit.hpp>
26

27
#include <realm/table.hpp>
28

29
using namespace realm;
30

31
/* The nice syntax is not supported by MSVC */
32
CreatePolicy CreatePolicy::Skip = {/*.create =*/false, /*.copy =*/false, /*.update =*/false, /*.diff =*/false};
33
CreatePolicy CreatePolicy::ForceCreate = {/*.create =*/true, /*.copy =*/true, /*.update =*/false, /*.diff =*/false};
34
CreatePolicy CreatePolicy::UpdateAll = {/*.create =*/true, /*.copy =*/true, /*.update =*/true, /*.diff =*/false};
35
CreatePolicy CreatePolicy::UpdateModified = {/*.create =*/true, /*.copy =*/true, /*.update =*/true, /*.diff =*/true};
36
CreatePolicy CreatePolicy::SetLink = {/*.create =*/true, /*.copy =*/false, /*.update =*/false, /*.diff =*/false};
37

38
Object Object::freeze(std::shared_ptr<Realm> frozen_realm) const
39
{
7✔
40
    return Object(frozen_realm, frozen_realm->import_copy_of(m_obj));
7✔
41
}
7✔
42

43
bool Object::is_frozen() const noexcept
44
{
5✔
45
    return m_realm->is_frozen();
5✔
46
}
5✔
47

48
InvalidatedObjectException::InvalidatedObjectException(const std::string& object_type)
49
    : LogicError(ErrorCodes::InvalidatedObject,
6✔
50
                 "Accessing object of type " + object_type + " which has been invalidated or deleted")
6✔
51
    , object_type(object_type)
6✔
52
{
6✔
53
}
6✔
54

55
InvalidPropertyException::InvalidPropertyException(const std::string& object_type, const std::string& property_name)
56
    : LogicError(ErrorCodes::InvalidProperty,
7✔
57
                 util::format("Property '%1.%2' does not exist", object_type, property_name))
7✔
58
    , object_type(object_type)
7✔
59
    , property_name(property_name)
7✔
60
{
7✔
61
}
7✔
62

63
MissingPropertyValueException::MissingPropertyValueException(const std::string& object_type,
64
                                                             const std::string& property_name)
65
    : LogicError(ErrorCodes::MissingPropertyValue,
1✔
66
                 util::format("Missing value for property '%1.%2'", object_type, property_name))
1✔
67
    , object_type(object_type)
1✔
68
    , property_name(property_name)
1✔
69
{
1✔
70
}
1✔
71

72
MissingPrimaryKeyException::MissingPrimaryKeyException(const std::string& object_type)
73
    : LogicError(ErrorCodes::MissingPrimaryKey, util::format("'%1' does not have a primary key defined", object_type))
1✔
74
    , object_type(object_type)
1✔
75
{
1✔
76
}
1✔
77

78
ReadOnlyPropertyException::ReadOnlyPropertyException(const std::string& object_type, const std::string& property_name)
79
    : LogicError(ErrorCodes::ReadOnlyProperty,
1✔
80
                 util::format("Cannot modify read-only property '%1.%2'", object_type, property_name))
1✔
81
    , object_type(object_type)
1✔
82
    , property_name(property_name)
1✔
83
{
1✔
84
}
1✔
85

86
ModifyPrimaryKeyException::ModifyPrimaryKeyException(const std::string& object_type, const std::string& property_name)
87
    : LogicError(ErrorCodes::ModifyPrimaryKey,
2✔
88
                 util::format("Cannot modify primary key after creation: '%1.%2'", object_type, property_name))
2✔
89
    , object_type(object_type)
2✔
90
    , property_name(property_name)
2✔
91
{
2✔
92
}
2✔
93

94
template <typename Key>
95
static const ObjectSchema* find_object_schema(Realm& realm, Key key)
96
{
299✔
97
    auto object_schema = realm.schema().find(key);
299✔
98
    REALM_ASSERT(object_schema != realm.schema().end());
299✔
99
    return &*object_schema;
299✔
100
}
299✔
101

102
static const ObjectSchema* find_object_schema(Realm& realm, Obj const& o)
103
{
2,408✔
104
    auto table = o.get_table();
2,408✔
105
    if (!table) {
2,408✔
106
        return nullptr;
1✔
107
    }
1✔
108
    REALM_ASSERT(&realm.read_group() == _impl::TableFriend::get_parent_group(*table));
2,407✔
109
    auto object_schema = realm.schema().find(ObjectStore::object_type_for_table_name(table->get_name()));
2,407✔
110
    REALM_ASSERT(object_schema != realm.schema().end());
2,407✔
111
    return &*object_schema;
2,407✔
112
}
2,408✔
113

114
Object::Object(std::shared_ptr<Realm> r, const ObjectSchema* s, Obj const& o, Obj const& parent,
115
               ColKey incoming_column)
116
    : m_realm(std::move(r))
10,876✔
117
    , m_obj(o)
10,876✔
118
    , m_object_schema(s)
10,876✔
119
{
10,876✔
120
    if (auto audit = m_realm->audit_context())
10,876✔
121
        audit->record_read(m_realm->read_transaction_version(), m_obj, parent, incoming_column);
×
122
}
10,876✔
123

124
Object::Object(const std::shared_ptr<Realm>& r, ObjectSchema const& s, Obj const& o, Obj const& parent,
125
               ColKey incoming_column)
126
    : Object(r, &s, o, parent, incoming_column)
8,171✔
127
{
8,171✔
128
}
8,171✔
129

130
Object::Object(const std::shared_ptr<Realm>& r, Obj const& o)
131
    : Object(r, find_object_schema(*r, o), o)
2,408✔
132
{
2,408✔
133
}
2,408✔
134

135
template <typename Key>
136
Object::Object(const std::shared_ptr<Realm>& r, const ObjectSchema* s, Key key)
137
    : Object(r, s, r->read_group().get_table(s->table_key)->get_object(key))
32✔
138
{
32✔
139
}
32✔
140

141
Object::Object(const std::shared_ptr<Realm>& r, StringData object_type, ObjKey key)
142
    : Object(r, find_object_schema(*r, object_type), key)
27✔
143
{
27✔
144
}
27✔
145

146
Object::Object(const std::shared_ptr<Realm>& r, StringData object_type, size_t index)
147
    : Object(r, find_object_schema(*r, object_type), index)
5✔
148
{
5✔
149
}
5✔
150

151
Object::Object(const std::shared_ptr<Realm>& r, ObjLink link)
152
    : Object(r, find_object_schema(*r, link.get_table_key()), r->read_group().get_object(link))
267✔
153
{
267✔
154
}
267✔
155

156
Object::Object() = default;
1,949✔
157
Object::~Object() = default;
21,941✔
158
Object::Object(Object const&) = default;
211✔
159
Object::Object(Object&&) = default;
8,905✔
160
Object& Object::operator=(Object const&) = default;
×
161
Object& Object::operator=(Object&&) = default;
1,757✔
162

163
NotificationToken Object::add_notification_callback(CollectionChangeCallback callback,
164
                                                    std::optional<KeyPathArray> key_path_array) &
165
{
1,734✔
166
    verify_attached();
1,734✔
167
    m_realm->verify_notifications_available();
1,734✔
168
    if (!m_notifier) {
1,734✔
169
        m_notifier = std::make_shared<_impl::ObjectNotifier>(m_realm, m_obj);
1,724✔
170
        _impl::RealmCoordinator::register_notifier(m_notifier);
1,724✔
171
    }
1,724✔
172
    return {m_notifier, m_notifier->add_callback(std::move(callback), std::move(key_path_array))};
1,734✔
173
}
1,734✔
174

175
void Object::verify_attached() const
176
{
2,952✔
177
    m_realm->verify_thread();
2,952✔
178
    if (!m_obj.is_valid()) {
2,952✔
179
        throw InvalidatedObjectException(m_object_schema->name);
6✔
180
    }
6✔
181
}
2,952✔
182

183
Property const& Object::property_for_name(StringData prop_name) const
184
{
481✔
185
    auto prop = m_object_schema->property_for_name(prop_name);
481✔
186
    if (!prop) {
481✔
187
        throw InvalidPropertyException(m_object_schema->name, prop_name);
6✔
188
    }
6✔
189
    return *prop;
475✔
190
}
481✔
191

192
void Object::validate_property_for_setter(Property const& property) const
193
{
191✔
194
    verify_attached();
191✔
195
    m_realm->verify_in_write();
191✔
196

197
    // Modifying primary keys is allowed in migrations to make it possible to
198
    // add a new primary key to a type (or change the property type), but it
199
    // is otherwise considered the immutable identity of the row
200
    if (property.is_primary) {
191✔
201
        if (!m_realm->is_in_migration())
64✔
202
            throw ModifyPrimaryKeyException(m_object_schema->name, property.name);
1✔
203
        // Modifying the PK property while it's the PK will corrupt the table,
204
        // so remove it and then restore it at the end of the migration (which will rebuild the table)
205
        m_obj.get_table()->set_primary_key_column({});
63✔
206
    }
63✔
207
}
191✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc