GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_realm-inl.h Lines: 34 34 100.0 %
Date: 2022-12-31 04:22:30 Branches: 1 2 50.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
730036
inline Realm* Realm::GetCurrent(v8::Local<v8::Context> context) {
18
730036
  if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) return nullptr;
19
  return static_cast<Realm*>(
20
1460072
      context->GetAlignedPointerFromEmbedderData(ContextEmbedderIndex::kRealm));
21
}
22
23
730036
inline Realm* Realm::GetCurrent(
24
    const v8::FunctionCallbackInfo<v8::Value>& info) {
25
730036
  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
96308
inline IsolateData* Realm::isolate_data() const {
34
96308
  return env_->isolate_data();
35
}
36
37
16164467
inline Environment* Realm::env() const {
38
16164467
  return env_;
39
}
40
41
2973388
inline v8::Isolate* Realm::isolate() const {
42
2973388
  return isolate_;
43
}
44
45
1668523
inline bool Realm::has_run_bootstrapping_code() const {
46
1668523
  return has_run_bootstrapping_code_;
47
}
48
49
template <typename T>
50
81
void Realm::ForEachBaseObject(T&& iterator) const {
51
81
  cleanup_queue_.ForEachBaseObject(std::forward<T>(iterator));
52
81
}
53
54
2807692
void Realm::modify_base_object_count(int64_t delta) {
55
2807692
  base_object_count_ += delta;
56
2807692
}
57
58
14
int64_t Realm::base_object_created_after_bootstrap() const {
59
14
  return base_object_count_ - base_object_created_by_bootstrap_;
60
}
61
62
2
int64_t Realm::base_object_count() const {
63
2
  return base_object_count_;
64
}
65
66
#define V(PropertyName, TypeName)                                              \
67
  inline v8::Local<TypeName> Realm::PropertyName() const {                     \
68
    return PersistentToLocal::Strong(PropertyName##_);                         \
69
  }                                                                            \
70
  inline void Realm::set_##PropertyName(v8::Local<TypeName> value) {           \
71
    PropertyName##_.Reset(isolate(), value);                                   \
72
  }
73
10111388
PER_REALM_STRONG_PERSISTENT_VALUES(V)
74
#undef V
75
76
9776983
v8::Local<v8::Context> Realm::context() const {
77
9776983
  return PersistentToLocal::Strong(context_);
78
}
79
80
1409602
void Realm::AddCleanupHook(CleanupQueue::Callback fn, void* arg) {
81
1409602
  cleanup_queue_.Add(fn, arg);
82
1409602
}
83
84
1398090
void Realm::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) {
85
1398090
  cleanup_queue_.Remove(fn, arg);
86
1398090
}
87
88
6666
bool Realm::HasCleanupHooks() const {
89
6666
  return !cleanup_queue_.empty();
90
}
91
92
}  // namespace node
93
94
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
95
96
#endif  // SRC_NODE_REALM_INL_H_