• 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

93.08
/src/realm/collection_parent.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2023 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/collection_parent.hpp>
20
#include "realm/list.hpp"
21
#include "realm/set.hpp"
22
#include "realm/dictionary.hpp"
23
#include "realm/util/overload.hpp"
24

25
#include <random>
26
#include <mutex>
27

28
namespace realm {
29

30
std::ostream& operator<<(std::ostream& ostr, const PathElement& elem)
31
{
110,088✔
32
    if (elem.is_ndx()) {
110,088✔
33
        size_t ndx = elem.get_ndx();
23,175✔
34
        if (ndx == 0) {
23,175✔
35
            ostr << "FIRST";
7,857✔
36
        }
7,857✔
37
        else if (ndx == size_t(-1)) {
15,318✔
38
            ostr << "LAST";
165✔
39
        }
165✔
40
        else {
15,153✔
41
            ostr << elem.get_ndx();
15,153✔
42
        }
15,153✔
43
    }
23,175✔
44
    else if (elem.is_col_key()) {
86,913✔
45
        ostr << elem.get_col_key();
×
46
    }
×
47
    else if (elem.is_key()) {
86,913✔
48
        ostr << "'" << elem.get_key() << "'";
86,841✔
49
    }
86,841✔
50
    else if (elem.is_all()) {
72✔
51
        ostr << '*';
72✔
52
    }
72✔
53

54
    return ostr;
110,088✔
55
}
110,088✔
56

57
std::ostream& operator<<(std::ostream& ostr, const Path& path)
58
{
47,034✔
59
    for (auto& elem : path) {
109,560✔
60
        ostr << '[' << elem << ']';
109,560✔
61
    }
109,560✔
62
    return ostr;
47,034✔
63
}
47,034✔
64

65
bool StablePath::is_prefix_of(const StablePath& other) const noexcept
66
{
5,307✔
67
    if (size() > other.size())
5,307✔
68
        return false;
93✔
69
    return std::equal(begin(), end(), other.begin());
5,214✔
70
}
5,307✔
71

72
/***************************** CollectionParent ******************************/
73

74
CollectionParent::~CollectionParent() {}
2,564,070✔
75

76
void CollectionParent::check_level() const
77
{
50,649✔
78
    if (size_t(m_level) + 1 > s_max_level) {
50,649✔
79
        throw LogicError(ErrorCodes::LimitExceeded, "Max nesting level reached");
3✔
80
    }
3✔
81
}
50,649✔
82

83
template <typename Base, template <typename> typename Collection, typename LinkCol>
84
std::unique_ptr<Base> create_collection(ColKey col_key, uint8_t level)
85
{
234,615✔
86
    bool nullable = col_key.get_attrs().test(col_attr_Nullable);
234,615✔
87
    switch (col_key.get_type()) {
234,615✔
88
        case col_type_Int:
13,287✔
89
            if (nullable)
13,287✔
90
                return std::make_unique<Collection<util::Optional<Int>>>(col_key);
2,586✔
91
            return std::make_unique<Collection<Int>>(col_key);
10,701✔
92
        case col_type_Bool:
4,524✔
93
            if (nullable)
4,524✔
94
                return std::make_unique<Collection<util::Optional<Bool>>>(col_key);
2,352✔
95
            return std::make_unique<Collection<Bool>>(col_key);
2,172✔
96
        case col_type_Float:
4,920✔
97
            if (nullable)
4,920✔
98
                return std::make_unique<Collection<util::Optional<Float>>>(col_key);
2,559✔
99
            return std::make_unique<Collection<Float>>(col_key);
2,361✔
100
        case col_type_Double:
5,049✔
101
            if (nullable)
5,049✔
102
                return std::make_unique<Collection<util::Optional<Double>>>(col_key);
2,559✔
103
            return std::make_unique<Collection<Double>>(col_key);
2,490✔
104
        case col_type_String:
138,282✔
105
            return std::make_unique<Collection<String>>(col_key);
138,282✔
106
        case col_type_Binary:
4,833✔
107
            return std::make_unique<Collection<Binary>>(col_key);
4,833✔
108
        case col_type_Timestamp:
4,881✔
109
            return std::make_unique<Collection<Timestamp>>(col_key);
4,881✔
110
        case col_type_Decimal:
4,674✔
111
            return std::make_unique<Collection<Decimal128>>(col_key);
4,674✔
112
        case col_type_ObjectId:
9,099✔
113
            if (nullable)
9,099✔
114
                return std::make_unique<Collection<util::Optional<ObjectId>>>(col_key);
6,918✔
115
            return std::make_unique<Collection<ObjectId>>(col_key);
2,181✔
116
        case col_type_UUID:
4,545✔
117
            if (nullable)
4,545✔
118
                return std::make_unique<Collection<util::Optional<UUID>>>(col_key);
2,370✔
119
            return std::make_unique<Collection<UUID>>(col_key);
2,175✔
120
        case col_type_TypedLink:
✔
121
            return std::make_unique<Collection<ObjLink>>(col_key);
×
122
        case col_type_Mixed:
8,349✔
123
            return std::make_unique<Collection<Mixed>>(col_key, level + 1);
8,349✔
124
        case col_type_Link:
32,172✔
125
            return std::make_unique<LinkCol>(col_key);
32,172✔
126
        default:
✔
127
            REALM_TERMINATE("Unsupported column type.");
128
    }
234,615✔
129
}
234,615✔
130

131
LstBasePtr CollectionParent::get_listbase_ptr(ColKey col_key, uint8_t level)
132
{
175,881✔
133
    REALM_ASSERT(col_key.get_attrs().test(col_attr_List) || col_key.get_type() == col_type_Mixed);
175,881!
134
    return create_collection<LstBase, Lst, LnkLst>(col_key, level);
175,881✔
135
}
175,881✔
136

137
SetBasePtr CollectionParent::get_setbase_ptr(ColKey col_key, uint8_t level)
138
{
58,734✔
139
    REALM_ASSERT(col_key.get_attrs().test(col_attr_Set));
58,734✔
140
    return create_collection<SetBase, Set, LnkSet>(col_key, level);
58,734✔
141
}
58,734✔
142

143
CollectionBasePtr CollectionParent::get_collection_ptr(ColKey col_key, uint8_t level)
144
{
63,405✔
145
    if (col_key.is_list()) {
63,405✔
146
        return get_listbase_ptr(col_key, level);
11,553✔
147
    }
11,553✔
148
    else if (col_key.is_set()) {
51,852✔
149
        return get_setbase_ptr(col_key, level);
36,960✔
150
    }
36,960✔
151
    else if (col_key.is_dictionary()) {
14,892✔
152
        return std::make_unique<Dictionary>(col_key, level + 1);
14,892✔
153
    }
14,892✔
154
    return {};
×
155
}
63,405✔
156

157
int64_t CollectionParent::generate_key(size_t sz)
158
{
124,131✔
159
    static std::mt19937 gen32;
124,131✔
160
    static std::mutex mutex;
124,131✔
161

162
    int64_t key;
124,131✔
163
    const std::lock_guard<std::mutex> lock(mutex);
124,131✔
164
    do {
124,323✔
165
        if (sz < 0x10) {
124,323✔
166
            key = int8_t(gen32());
50,634✔
167
        }
50,634✔
168
        else if (sz < 0x1000) {
73,689✔
169
            key = int16_t(gen32());
73,689✔
170
        }
73,689✔
171
        else {
×
172
            key = int32_t(gen32());
×
173
        }
×
174
    } while (key == 0);
124,323✔
175

176
    return key;
124,131✔
177
}
124,131✔
178

179
void CollectionParent::set_key(BPlusTreeMixed& tree, size_t index)
180
{
50,442✔
181
    int64_t key = generate_key(tree.size());
50,442✔
182
    while (tree.find_key(key) != realm::not_found) {
50,490✔
183
        key++;
48✔
184
    }
48✔
185
    tree.set_key(index, key);
50,442✔
186
}
50,442✔
187

188
} // namespace realm
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

© 2026 Coveralls, Inc