• 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.58
/src/realm/array_blobs_big.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 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 <algorithm>
20

21
#include <realm/array_blobs_big.hpp>
22
#include <realm/column_integer.hpp>
23

24

25
using namespace realm;
26

27
BinaryData ArrayBigBlobs::get_at(size_t ndx, size_t& pos) const noexcept
28
{
236,502✔
29
    ref_type ref = get_as_ref(ndx);
236,502✔
30
    if (ref == 0)
236,502✔
31
        return {}; // realm::null();
67,554✔
32

33
    ArrayBlob blob(m_alloc);
168,948✔
34
    blob.init_from_ref(ref);
168,948✔
35

36
    return blob.get_at(pos);
168,948✔
37
}
236,502✔
38

39

40
void ArrayBigBlobs::add(BinaryData value, bool add_zero_term)
41
{
42,765✔
42
    REALM_ASSERT_7(value.size(), ==, 0, ||, value.data(), !=, 0);
42,765✔
43

44
    if (value.is_null()) {
42,765✔
45
        Array::add(0); // Throws
18,141✔
46
    }
18,141✔
47
    else {
24,624✔
48
        ArrayBlob new_blob(m_alloc);
24,624✔
49
        new_blob.create();                                                      // Throws
24,624✔
50
        ref_type ref = new_blob.add(value.data(), value.size(), add_zero_term); // Throws
24,624✔
51
        Array::add(from_ref(ref));                                              // Throws
24,624✔
52
    }
24,624✔
53
}
42,765✔
54

55

56
void ArrayBigBlobs::set(size_t ndx, BinaryData value, bool add_zero_term)
57
{
2,740,809✔
58
    REALM_ASSERT_3(ndx, <, size());
2,740,809✔
59
    REALM_ASSERT_7(value.size(), ==, 0, ||, value.data(), !=, 0);
2,740,809✔
60

61
    ref_type ref = get_as_ref(ndx);
2,740,809✔
62

63
    if (ref == 0 && value.is_null()) {
2,740,809✔
64
        return;
981✔
65
    }
981✔
66
    else if (ref == 0 && value.data() != nullptr) {
2,739,828✔
67
        ArrayBlob new_blob(m_alloc);
696,183✔
68
        new_blob.create();                                             // Throws
696,183✔
69
        ref = new_blob.add(value.data(), value.size(), add_zero_term); // Throws
696,183✔
70
        Array::set_as_ref(ndx, ref);
696,183✔
71
        return;
696,183✔
72
    }
696,183✔
73
    else if (ref != 0 && value.data() != nullptr) {
2,044,995✔
74
        char* header = m_alloc.translate(ref);
2,040,996✔
75
        if (Array::get_context_flag_from_header(header)) {
2,040,996✔
76
            Array arr(m_alloc);
3✔
77
            arr.init_from_mem(MemRef(header, ref, m_alloc));
3✔
78
            arr.set_parent(this, ndx);
3✔
79
            ref_type new_ref =
3✔
80
                arr.blob_replace(0, arr.blob_size(), value.data(), value.size(), add_zero_term); // Throws
3✔
81
            if (new_ref != ref) {
3✔
82
                Array::set_as_ref(ndx, new_ref);
×
83
            }
×
84
        }
3✔
85
        else {
2,040,993✔
86
            ArrayBlob blob(m_alloc);
2,040,993✔
87
            blob.init_from_mem(MemRef(header, ref, m_alloc));
2,040,993✔
88
            blob.set_parent(this, ndx);
2,040,993✔
89
            ref_type new_ref = blob.replace(0, blob.blob_size(), value.data(), value.size(), add_zero_term); // Throws
2,040,993✔
90
            if (new_ref != ref) {
2,040,993✔
91
                Array::set_as_ref(ndx, new_ref);
1,856,958✔
92
            }
1,856,958✔
93
        }
2,040,993✔
94
        return;
2,040,996✔
95
    }
2,040,996✔
96
    else if (ref != 0 && value.is_null()) {
3,978✔
97
        Array::destroy_deep(ref, get_alloc());
3,978✔
98
        Array::set(ndx, 0);
3,978✔
99
        return;
3,978✔
100
    }
3,978✔
101
    REALM_ASSERT(false);
2,147,483,647✔
102
}
2,147,483,647✔
103

104

105
void ArrayBigBlobs::insert(size_t ndx, BinaryData value, bool add_zero_term)
106
{
1,225,146✔
107
    REALM_ASSERT_3(ndx, <=, size());
1,225,146✔
108
    REALM_ASSERT_7(value.size(), ==, 0, ||, value.data(), !=, 0);
1,225,146✔
109

110
    if (value.is_null()) {
1,225,146✔
111
        Array::insert(ndx, 0); // Throws
717,090✔
112
    }
717,090✔
113
    else {
508,056✔
114
        ArrayBlob new_blob(m_alloc);
508,056✔
115
        new_blob.create();                                                      // Throws
508,056✔
116
        ref_type ref = new_blob.add(value.data(), value.size(), add_zero_term); // Throws
508,056✔
117

118
        Array::insert(ndx, int64_t(ref)); // Throws
508,056✔
119
    }
508,056✔
120
}
1,225,146✔
121

122

123
size_t ArrayBigBlobs::count(BinaryData value, bool is_string, size_t begin, size_t end) const noexcept
124
{
6✔
125
    size_t num_matches = 0;
6✔
126

127
    size_t begin_2 = begin;
6✔
128
    for (;;) {
24✔
129
        size_t ndx = find_first(value, is_string, begin_2, end);
24✔
130
        if (ndx == not_found)
24✔
131
            break;
6✔
132
        ++num_matches;
18✔
133
        begin_2 = ndx + 1;
18✔
134
    }
18✔
135

136
    return num_matches;
6✔
137
}
6✔
138

139

140
size_t ArrayBigBlobs::find_first(BinaryData value, bool is_string, size_t begin, size_t end) const noexcept
141
{
128,895✔
142
    if (end == npos)
128,895✔
143
        end = m_size;
54✔
144
    REALM_ASSERT_11(begin, <=, m_size, &&, end, <=, m_size, &&, begin, <=, end);
128,895✔
145

146
    // When strings are stored as blobs, they are always zero-terminated
147
    // but the value we get as input might not be.
148
    size_t value_size = value.size();
128,895✔
149
    size_t full_size = is_string ? value_size + 1 : value_size;
128,895✔
150

151
    if (value.is_null()) {
128,895✔
152
        for (size_t i = begin; i != end; ++i) {
33,777✔
153
            ref_type ref = get_as_ref(i);
33,774✔
154
            if (ref == 0)
33,774✔
155
                return i;
33,750✔
156
        }
33,774✔
157
    }
33,753✔
158
    else {
95,142✔
159
        for (size_t i = begin; i != end; ++i) {
1,265,244✔
160
            ref_type ref = get_as_ref(i);
1,258,032✔
161
            if (ref) {
1,258,032✔
162
                const char* blob_header = get_alloc().translate(ref);
1,225,941✔
163
                size_t sz = get_size_from_header(blob_header);
1,225,941✔
164
                if (sz == full_size) {
1,225,941✔
165
                    const char* blob_value = ArrayBlob::get(blob_header, 0);
486,999✔
166
                    if (std::equal(blob_value, blob_value + value_size, value.data()))
486,999✔
167
                        return i;
87,930✔
168
                }
486,999✔
169
            }
1,225,941✔
170
        }
1,258,032✔
171
    }
95,142✔
172

173
    return not_found;
7,215✔
174
}
128,895✔
175

176

177
void ArrayBigBlobs::find_all(IntegerColumn& result, BinaryData value, bool is_string, size_t add_offset, size_t begin,
178
                             size_t end)
179
{
6✔
180
    size_t begin_2 = begin;
6✔
181
    for (;;) {
24✔
182
        size_t ndx = find_first(value, is_string, begin_2, end);
24✔
183
        if (ndx == not_found)
24✔
184
            break;
6✔
185
        result.add(add_offset + ndx); // Throws
18✔
186
        begin_2 = ndx + 1;
18✔
187
    }
18✔
188
}
6✔
189

190

191
void ArrayBigBlobs::verify() const
192
{
33,315✔
193
#ifdef REALM_DEBUG
33,315✔
194
    REALM_ASSERT(has_refs());
33,315✔
195
    for (size_t i = 0; i < size(); ++i) {
5,685,933✔
196
        ref_type blob_ref = Array::get_as_ref(i);
5,652,618✔
197
        // 0 is used to indicate realm::null()
198
        if (blob_ref != 0) {
5,652,618✔
199
            ArrayBlob blob(m_alloc);
5,652,567✔
200
            blob.init_from_ref(blob_ref);
5,652,567✔
201
            blob.verify();
5,652,567✔
202
        }
5,652,567✔
203
    }
5,652,618✔
204
#endif
33,315✔
205
}
33,315✔
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