• 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

97.92
/src/realm/object-store/dictionary.hpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2020 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
#ifndef REALM_OS_DICTIONARY_HPP
20
#define REALM_OS_DICTIONARY_HPP
21

22
#include <realm/object-store/collection.hpp>
23
#include <realm/object-store/object.hpp>
24
#include <realm/dictionary.hpp>
25

26
namespace realm {
27

28
struct DictionaryChangeSet {
29
    DictionaryChangeSet(size_t max_keys)
30
    {
174✔
31
        m_string_store.reserve(max_keys);
174✔
32
    }
174✔
33
    DictionaryChangeSet()
34
        : DictionaryChangeSet(0)
42✔
35
    {
42✔
36
    }
42✔
37

38
    DictionaryChangeSet(const DictionaryChangeSet&);
39
    DictionaryChangeSet(DictionaryChangeSet&&) = default;
267✔
40

41
    DictionaryChangeSet& operator=(const DictionaryChangeSet&);
42
    DictionaryChangeSet& operator=(DictionaryChangeSet&&) = default;
43

44
    // Keys which were removed from the _old_ dictionary
45
    std::vector<Mixed> deletions;
46

47
    // Keys in the _new_ dictionary which are new insertions
48
    std::vector<Mixed> insertions;
49

50
    // Keys of objects/values which were modified
51
    std::vector<Mixed> modifications;
52

53
    bool collection_root_was_deleted = false;
54
    bool collection_was_cleared = false;
55

56
    void add_deletion(const Mixed& key)
57
    {
188✔
58
        add(deletions, key);
188✔
59
    }
188✔
60
    void add_insertion(const Mixed& key)
61
    {
24✔
62
        add(insertions, key);
24✔
63
    }
24✔
64
    void add_modification(const Mixed& key)
65
    {
21✔
66
        add(modifications, key);
21✔
67
    }
21✔
68

69
private:
70
    void add(std::vector<Mixed>& arr, const Mixed& key);
71
    std::vector<std::string> m_string_store;
72
};
73

74
namespace object_store {
75

76
class Dictionary : public object_store::Collection {
77
public:
78
    using Iterator = realm::Dictionary::Iterator;
79
    using Collection::Collection;
80
    Dictionary()
81
        : Collection(PropertyType::Dictionary)
94✔
82
    {
94✔
83
    }
94✔
84

85
    bool operator==(const Dictionary& rgt) const noexcept;
86
    bool operator!=(const Dictionary& rgt) const noexcept;
87

88
    template <typename T>
89
    void insert(StringData key, T value);
90
    std::pair<size_t, bool> insert_any(StringData key, Mixed value);
91

92
    template <typename T>
93
    T get(StringData key) const;
94

95
    Obj insert_embedded(StringData key);
96
    void erase(StringData key);
97
    bool try_erase(StringData key);
98
    void remove_all();
99
    Obj get_object(StringData key);
100
    Mixed get_any(StringData key);
101
    Mixed get_any(size_t ndx) const final;
102
    util::Optional<Mixed> try_get_any(StringData key) const;
103
    std::pair<StringData, Mixed> get_pair(size_t ndx) const;
104
    size_t find_any(Mixed value) const final;
105
    bool contains(StringData key) const;
106

107
    template <typename T, typename Context>
108
    void insert(Context&, StringData key, T&& value, CreatePolicy = CreatePolicy::SetLink);
109
    template <typename Context>
110
    auto get(Context&, StringData key) const;
111

112
    // Replace the values in this dictionary with the values from an map type object
113
    template <typename T, typename Context>
114
    void assign(Context&, T&& value, CreatePolicy = CreatePolicy::SetLink);
115

116
    Results snapshot() const;
117
    Dictionary freeze(const std::shared_ptr<Realm>& realm) const;
118
    Results get_keys() const;
119
    Results get_values() const;
120

121
    using CBFunc = util::UniqueFunction<void(DictionaryChangeSet)>;
122
    NotificationToken
123
    add_key_based_notification_callback(CBFunc cb, std::optional<KeyPathArray> key_path_array = std::nullopt) &;
124

125
    Iterator begin() const;
126
    Iterator end() const;
127

128
private:
129
    const char* type_name() const noexcept override
130
    {
108✔
131
        return "Dictionary";
108✔
132
    }
108✔
133

134
    realm::Dictionary& dict() const noexcept
135
    {
9,621✔
136
        REALM_ASSERT_DEBUG(dynamic_cast<realm::Dictionary*>(m_coll_base.get()));
9,621✔
137
        return static_cast<realm::Dictionary&>(*m_coll_base);
9,621✔
138
    }
9,621✔
139

140
    template <typename Fn>
141
    auto dispatch(Fn&&) const;
142
    Obj get_object(StringData key) const;
143
};
144

145
template <typename Fn>
146
auto Dictionary::dispatch(Fn&& fn) const
147
{
310✔
148
    verify_attached();
310✔
149
    return switch_on_type(get_type(), std::forward<Fn>(fn));
310✔
150
}
310✔
151

152
template <typename T>
153
void Dictionary::insert(StringData key, T value)
154
{
6,263✔
155
    verify_in_transaction();
6,263✔
156
    dict().insert(key, value);
6,263✔
157
}
6,263✔
158

159
template <typename T>
160
T Dictionary::get(StringData key) const
161
{
378✔
162
    auto res = dict().get(key);
378✔
163
    if (res.is_null()) {
378✔
164
        if constexpr (std::is_same_v<T, Decimal128>) {
44✔
165
            return Decimal128{realm::null()};
4✔
166
        }
167
        else {
40✔
168
            return T{};
40✔
169
        }
40✔
170
    }
44✔
171
    return res.get<T>();
×
172
}
378✔
173

174
template <>
175
inline Obj Dictionary::get<Obj>(StringData key) const
176
{
3✔
177
    return get_object(key);
3✔
178
}
3✔
179

180
} // namespace object_store
181
} // namespace realm
182

183
#endif /* REALM_OS_DICTIONARY_HPP */
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