• 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

28.57
/src/realm/util/backtrace.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2018 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/util/backtrace.hpp>
20
#include <realm/util/features.h>
21

22
#include <sstream>
23
#include <cstdlib>
24
#include <cstring>
25

26
#if !defined(REALM_HAVE_BACKTRACE) && (REALM_PLATFORM_APPLE || (defined(__linux__) && defined(__GNUC__)))
27
// we detect the backtrace facility in CMake, but if building outside it we assume
28
// it's available on Apple or Linux/glibc
29
#define REALM_HAVE_BACKTRACE 1
30
#endif
31

32
#if REALM_HAVE_BACKTRACE
33
#if defined(REALM_BACKTRACE_HEADER)
34
#include REALM_BACKTRACE_HEADER
35
#else
36
#include <execinfo.h>
37
#endif
38
#endif
39

40
using namespace realm::util;
41

42
#if REALM_HAVE_BACKTRACE
43
static const size_t g_backtrace_depth = 128;
44
#endif
45
static const char* g_backtrace_error = "<error calculating backtrace>";
46
static const char* g_backtrace_alloc_error = "<error allocating backtrace>";
47
static const char* g_backtrace_symbolicate_error = "<error symbolicating backtrace>";
48
static const char* g_backtrace_unsupported_error = "<backtrace not supported on this platform>";
49

50
Backtrace::~Backtrace()
51
{
303✔
52
    // std::free(nullptr) is guaranteed to silently do nothing.
53
    std::free(m_memory);
303✔
54
}
303✔
55

56
Backtrace::Backtrace(Backtrace&& other) noexcept
57
    : Backtrace()
×
58
{
×
59
    *this = std::move(other);
×
60
}
×
61

62
Backtrace::Backtrace(const Backtrace& other) noexcept
63
    : Backtrace()
×
64
{
×
65
    *this = other;
×
66
}
×
67

68
Backtrace& Backtrace::operator=(Backtrace&& other) noexcept
69
{
×
70
    std::swap(m_memory, other.m_memory);
×
71
    std::swap(m_strs, other.m_strs);
×
72
    std::swap(m_len, other.m_len);
×
73
    return *this;
×
74
}
×
75

76
Backtrace& Backtrace::operator=(const Backtrace& other) noexcept
77
{
×
78
    // For this class to work as a member of an exception, it has to define a
79
    // copy-constructor, because std::current_exception() may copy the exception
80
    // object.
81

82
    m_len = other.m_len;
×
83
    size_t required_memory = sizeof(char*) * m_len;
×
84
    for (size_t i = 0; i < m_len; ++i) {
×
85
        required_memory += std::strlen(other.m_strs[i]) + 1;
×
86
    }
×
87

88
    void* new_memory = std::malloc(required_memory);
×
89
    if (new_memory == nullptr) {
×
90
        std::free(m_memory);
×
91
        m_memory = nullptr;
×
92
        m_strs = &g_backtrace_alloc_error;
×
93
        m_len = 1;
×
94
        return *this;
×
95
    }
×
96

97
    char** new_strs = static_cast<char**>(new_memory);
×
98
    char* p = static_cast<char*>(new_memory) + sizeof(char*) * m_len;
×
99
    for (size_t i = 0; i < m_len; ++i) {
×
100
        *(new_strs++) = p;
×
101
        // FIXME: stpcpy() is not supported on Android, so we gotta manually
102
        // calculate the end of the destination here.
103
        size_t len = std::strlen(other.m_strs[i]);
×
104
        std::memcpy(p, other.m_strs[i], len);
×
105
        p[len] = '\0';
×
106
        p += len + 1;
×
107
    }
×
108
    std::free(m_memory);
×
109
    m_memory = new_memory;
×
110
    m_strs = static_cast<char* const*>(m_memory);
×
111
    m_len = other.m_len;
×
112
    return *this;
×
113
}
×
114

115

116
Backtrace Backtrace::capture() noexcept
117
{
303✔
118
#if REALM_HAVE_BACKTRACE
303✔
119
    static_cast<void>(g_backtrace_unsupported_error);
303✔
120
    void* callstack[g_backtrace_depth];
303✔
121
    int frames = ::backtrace(callstack, g_backtrace_depth);
303✔
122
    if (REALM_UNLIKELY(frames <= 1)) {
303✔
123
        return Backtrace(nullptr, &g_backtrace_error, 1);
×
124
    }
×
125
    else {
303✔
126
        // Translate the backtrace to symbols (and exclude the call to the
127
        // capture() function from the trace).
128
        --frames;
303✔
129
        void* memory = ::backtrace_symbols(callstack + 1, frames);
303✔
130
        if (REALM_UNLIKELY(memory == nullptr)) {
303✔
131
            return Backtrace(nullptr, &g_backtrace_symbolicate_error, 1);
×
132
        }
×
133
        else {
303✔
134
            return Backtrace{memory, size_t(frames)};
303✔
135
        }
303✔
136
    }
303✔
137
#else
138
    static_cast<void>(g_backtrace_error);
139
    static_cast<void>(g_backtrace_symbolicate_error);
140
    return Backtrace(nullptr, &g_backtrace_unsupported_error, 1);
141
#endif
142
}
303✔
143

144

145
void Backtrace::print(std::ostream& os) const
146
{
231✔
147
    for (size_t i = 0; i < m_len; ++i) {
5,292✔
148
        os << m_strs[i];
5,061✔
149
        if (i + 1 != m_len) {
5,061✔
150
            os << "\n";
4,830✔
151
        }
4,830✔
152
    }
5,061✔
153
}
231✔
154

155
const char* detail::ExceptionWithBacktraceBase::materialize_message() const noexcept
156
{
×
157
    if (m_has_materialized_message) {
×
158
        return m_materialized_message.c_str();
×
159
    }
×
160

161
    const char* msg = message();
×
162

163
    try {
×
164
        std::stringstream ss;
×
165
        ss << msg << "\n";
×
166
        ss << "Exception backtrace:\n";
×
167
        m_backtrace.print(ss);
×
168
        m_materialized_message = ss.str();
×
169
        m_has_materialized_message = true;
×
170
        return m_materialized_message.c_str();
×
171
    }
×
172
    catch (...) {
×
173
        return msg;
×
174
    }
×
175
}
×
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