GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_realm-inl.h Lines: 27 27 100.0 %
Date: 2022-12-07 04:23:16 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
16135442
inline Environment* Realm::env() const {
34
16135442
  return env_;
35
}
36
37
2129361
inline v8::Isolate* Realm::isolate() const {
38
2129361
  return isolate_;
39
}
40
41
1648778
inline bool Realm::has_run_bootstrapping_code() const {
42
1648778
  return has_run_bootstrapping_code_;
43
}
44
45
template <typename T>
46
81
void Realm::ForEachBaseObject(T&& iterator) const {
47
81
  cleanup_queue_.ForEachBaseObject(std::forward<T>(iterator));
48
81
}
49
50
2916328
void Realm::modify_base_object_count(int64_t delta) {
51
2916328
  base_object_count_ += delta;
52
2916328
}
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
10120335
PER_REALM_STRONG_PERSISTENT_VALUES(V)
70
#undef V
71
72
9614053
v8::Local<v8::Context> Realm::context() const {
73
9614053
  return PersistentToLocal::Strong(context_);
74
}
75
76
1466227
void Realm::AddCleanupHook(CleanupQueue::Callback fn, void* arg) {
77
1466227
  cleanup_queue_.Add(fn, arg);
78
1466227
}
79
80
1450101
void Realm::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) {
81
1450101
  cleanup_queue_.Remove(fn, arg);
82
1450101
}
83
84
6459
bool Realm::HasCleanupHooks() const {
85
6459
  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_