GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_realm-inl.h Lines: 27 27 100.0 %
Date: 2022-10-02 04:22:39 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_REALM_INL_H_
2
#define SRC_NODE_REALM_INL_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "cleanup_queue-inl.h"
7
#include "node_realm.h"
8
9
namespace node {
10
11
inline Realm* Realm::GetCurrent(v8::Isolate* isolate) {
12
  if (UNLIKELY(!isolate->InContext())) return nullptr;
13
  v8::HandleScope handle_scope(isolate);
14
  return GetCurrent(isolate->GetCurrentContext());
15
}
16
17
inline Realm* Realm::GetCurrent(v8::Local<v8::Context> context) {
18
  if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) return nullptr;
19
  return static_cast<Realm*>(
20
      context->GetAlignedPointerFromEmbedderData(ContextEmbedderIndex::kRealm));
21
}
22
23
inline Realm* Realm::GetCurrent(
24
    const v8::FunctionCallbackInfo<v8::Value>& info) {
25
  return GetCurrent(info.GetIsolate()->GetCurrentContext());
26
}
27
28
template <typename T>
29
inline Realm* Realm::GetCurrent(const v8::PropertyCallbackInfo<T>& info) {
30
  return GetCurrent(info.GetIsolate()->GetCurrentContext());
31
}
32
33
13858428
inline Environment* Realm::env() const {
34
13858428
  return env_;
35
}
36
37
2117513
inline v8::Isolate* Realm::isolate() const {
38
2117513
  return isolate_;
39
}
40
41
1581105
inline bool Realm::has_run_bootstrapping_code() const {
42
1581105
  return has_run_bootstrapping_code_;
43
}
44
45
template <typename T>
46
56
void Realm::ForEachBaseObject(T&& iterator) const {
47
56
  cleanup_queue_.ForEachBaseObject(std::forward<T>(iterator));
48
56
}
49
50
2908339
void Realm::modify_base_object_count(int64_t delta) {
51
2908339
  base_object_count_ += delta;
52
2908339
}
53
54
14
int64_t Realm::base_object_created_after_bootstrap() const {
55
14
  return base_object_count_ - base_object_created_by_bootstrap_;
56
}
57
58
2
int64_t Realm::base_object_count() const {
59
2
  return base_object_count_;
60
}
61
62
#define V(PropertyName, TypeName)                                              \
63
  inline v8::Local<TypeName> Realm::PropertyName() const {                     \
64
    return PersistentToLocal::Strong(PropertyName##_);                         \
65
  }                                                                            \
66
  inline void Realm::set_##PropertyName(v8::Local<TypeName> value) {           \
67
    PropertyName##_.Reset(isolate(), value);                                   \
68
  }
69
10023223
PER_REALM_STRONG_PERSISTENT_VALUES(V)
70
#undef V
71
72
9322110
v8::Local<v8::Context> Realm::context() const {
73
9322110
  return PersistentToLocal::Strong(context_);
74
}
75
76
1460796
void Realm::AddCleanupHook(CleanupQueue::Callback fn, void* arg) {
77
1460796
  cleanup_queue_.Add(fn, arg);
78
1460796
}
79
80
1447543
void Realm::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) {
81
1447543
  cleanup_queue_.Remove(fn, arg);
82
1447543
}
83
84
6420
bool Realm::HasCleanupHooks() const {
85
6420
  return !cleanup_queue_.empty();
86
}
87
88
}  // namespace node
89
90
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
91
92
#endif  // SRC_NODE_REALM_INL_H_