Coverage Report

Created: 2025-09-05 06:52

/src/serenity/AK/NeverDestroyed.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Noncopyable.h>
10
#include <AK/Types.h>
11
12
namespace AK {
13
14
template<typename T>
15
class NeverDestroyed {
16
    AK_MAKE_NONCOPYABLE(NeverDestroyed);
17
    AK_MAKE_NONMOVABLE(NeverDestroyed);
18
19
public:
20
    template<typename... Args>
21
    NeverDestroyed(Args&&... args)
22
1.13k
    {
23
1.13k
        new (storage) T(forward<Args>(args)...);
24
1.13k
    }
AK::NeverDestroyed<JS::CellAllocator>::NeverDestroyed<unsigned long, char const*&>(unsigned long&&, char const*&)
Line
Count
Source
22
1.13k
    {
23
1.13k
        new (storage) T(forward<Args>(args)...);
24
1.13k
    }
AK::NeverDestroyed<JS::ExecutionContextAllocator>::NeverDestroyed<>()
Line
Count
Source
22
4
    {
23
4
        new (storage) T(forward<Args>(args)...);
24
4
    }
25
26
    ~NeverDestroyed() = default;
27
28
170
    T* operator->() { return &get(); }
29
    T const* operator->() const { return &get(); }
30
31
    T& operator*() { return get(); }
32
    T const& operator*() const { return get(); }
33
34
66.5k
    T& get() { return reinterpret_cast<T&>(storage); }
AK::NeverDestroyed<JS::CellAllocator>::get()
Line
Count
Source
34
66.4k
    T& get() { return reinterpret_cast<T&>(storage); }
AK::NeverDestroyed<JS::ExecutionContextAllocator>::get()
Line
Count
Source
34
170
    T& get() { return reinterpret_cast<T&>(storage); }
35
    T const& get() const { return reinterpret_cast<T&>(storage); }
36
37
private:
38
    alignas(T) u8 storage[sizeof(T)];
39
};
40
41
}
42
43
#if USING_AK_GLOBALLY
44
using AK::NeverDestroyed;
45
#endif