Coverage Report

Created: 2025-10-31 09:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/deps/v8/include/v8-persistent-handle.h
Line
Count
Source
1
// Copyright 2021 the V8 project authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef INCLUDE_V8_PERSISTENT_HANDLE_H_
6
#define INCLUDE_V8_PERSISTENT_HANDLE_H_
7
8
#include "v8-internal.h"            // NOLINT(build/include_directory)
9
#include "v8-local-handle.h"        // NOLINT(build/include_directory)
10
#include "v8-weak-callback-info.h"  // NOLINT(build/include_directory)
11
#include "v8config.h"               // NOLINT(build/include_directory)
12
13
namespace v8 {
14
15
class Isolate;
16
template <class K, class V, class T>
17
class PersistentValueMapBase;
18
template <class T>
19
class Global;
20
template <class T>
21
class PersistentBase;
22
template <class K, class V, class T>
23
class PersistentValueMap;
24
class Value;
25
26
namespace api_internal {
27
V8_EXPORT internal::Address* Eternalize(v8::Isolate* isolate, Value* handle);
28
V8_EXPORT internal::Address* CopyGlobalReference(internal::Address* from);
29
V8_EXPORT void DisposeGlobal(internal::Address* global_handle);
30
V8_EXPORT void MakeWeak(internal::Address** location_addr);
31
V8_EXPORT void* ClearWeak(internal::Address* location);
32
V8_EXPORT void AnnotateStrongRetainer(internal::Address* location,
33
                                      const char* label);
34
V8_EXPORT internal::Address* GlobalizeReference(internal::Isolate* isolate,
35
                                                internal::Address value);
36
V8_EXPORT void MoveGlobalReference(internal::Address** from,
37
                                   internal::Address** to);
38
}  // namespace api_internal
39
40
/**
41
 * Eternal handles are set-once handles that live for the lifetime of the
42
 * isolate.
43
 */
44
template <class T>
45
class Eternal : public api_internal::IndirectHandleBase {
46
 public:
47
19.8k
  V8_INLINE Eternal() = default;
v8::Eternal<v8::Private>::Eternal()
Line
Count
Source
47
2.76k
  V8_INLINE Eternal() = default;
v8::Eternal<v8::Symbol>::Eternal()
Line
Count
Source
47
735
  V8_INLINE Eternal() = default;
v8::Eternal<v8::String>::Eternal()
Line
Count
Source
47
12.9k
  V8_INLINE Eternal() = default;
v8::Eternal<v8::DictionaryTemplate>::Eternal()
Line
Count
Source
47
1.12k
  V8_INLINE Eternal() = default;
v8::Eternal<v8::FunctionTemplate>::Eternal()
Line
Count
Source
47
840
  V8_INLINE Eternal() = default;
v8::Eternal<v8::ObjectTemplate>::Eternal()
Line
Count
Source
47
1.43k
  V8_INLINE Eternal() = default;
48
49
  /**
50
   * Constructor for handling automatic up casting.
51
   */
52
  template <class S>
53
    requires(std::is_base_of_v<T, S>)
54
  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) {
55
    Set(isolate, handle);
56
  }
57
58
  // Can only be safely called if already set.
59
20.3k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
20.3k
    return Local<T>::FromSlot(slot());
63
20.3k
  }
v8::Eternal<v8::String>::Get(v8::Isolate*) const
Line
Count
Source
59
14.6k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
14.6k
    return Local<T>::FromSlot(slot());
63
14.6k
  }
v8::Eternal<v8::Private>::Get(v8::Isolate*) const
Line
Count
Source
59
1.47k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
1.47k
    return Local<T>::FromSlot(slot());
63
1.47k
  }
v8::Eternal<v8::Symbol>::Get(v8::Isolate*) const
Line
Count
Source
59
2.27k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
2.27k
    return Local<T>::FromSlot(slot());
63
2.27k
  }
v8::Eternal<v8::DictionaryTemplate>::Get(v8::Isolate*) const
Line
Count
Source
59
35
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
35
    return Local<T>::FromSlot(slot());
63
35
  }
v8::Eternal<v8::FunctionTemplate>::Get(v8::Isolate*) const
Line
Count
Source
59
700
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
700
    return Local<T>::FromSlot(slot());
63
700
  }
v8::Eternal<v8::ObjectTemplate>::Get(v8::Isolate*) const
Line
Count
Source
59
1.26k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
60
    // The eternal handle will never go away, so as with the roots, we don't
61
    // even need to open a handle.
62
1.26k
    return Local<T>::FromSlot(slot());
63
1.26k
  }
64
65
  template <class S>
66
    requires(std::is_base_of_v<T, S>)
67
17.9k
  void Set(Isolate* isolate, Local<S> handle) {
68
17.9k
    slot() =
69
17.9k
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
17.9k
  }
_ZN2v87EternalINS_18DictionaryTemplateEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
35
  void Set(Isolate* isolate, Local<S> handle) {
68
35
    slot() =
69
35
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
35
  }
_ZN2v87EternalINS_16FunctionTemplateEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
280
  void Set(Isolate* isolate, Local<S> handle) {
68
280
    slot() =
69
280
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
280
  }
_ZN2v87EternalINS_14ObjectTemplateEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
1.22k
  void Set(Isolate* isolate, Local<S> handle) {
68
1.22k
    slot() =
69
1.22k
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
1.22k
  }
_ZN2v87EternalINS_7PrivateEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
2.76k
  void Set(Isolate* isolate, Local<S> handle) {
68
2.76k
    slot() =
69
2.76k
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
2.76k
  }
_ZN2v87EternalINS_6SymbolEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
735
  void Set(Isolate* isolate, Local<S> handle) {
68
735
    slot() =
69
735
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
735
  }
_ZN2v87EternalINS_6StringEE3SetIS1_Qsr3stdE12is_base_of_vIT_TL0__EEEvPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
67
12.9k
  void Set(Isolate* isolate, Local<S> handle) {
68
12.9k
    slot() =
69
12.9k
        api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
12.9k
  }
71
};
72
73
namespace api_internal {
74
V8_EXPORT void MakeWeak(internal::Address* location, void* data,
75
                        WeakCallbackInfo<void>::Callback weak_callback,
76
                        WeakCallbackType type);
77
}  // namespace api_internal
78
79
/**
80
 * An object reference that is independent of any handle scope.  Where
81
 * a Local handle only lives as long as the HandleScope in which it was
82
 * allocated, a PersistentBase handle remains valid until it is explicitly
83
 * disposed using Reset().
84
 *
85
 * A persistent handle contains a reference to a storage cell within
86
 * the V8 engine which holds an object value and which is updated by
87
 * the garbage collector whenever the object is moved.  A new storage
88
 * cell can be created using the constructor or PersistentBase::Reset and
89
 * existing handles can be disposed using PersistentBase::Reset.
90
 *
91
 */
92
template <class T>
93
class PersistentBase : public api_internal::IndirectHandleBase {
94
 public:
95
  /**
96
   * If non-empty, destroy the underlying storage cell
97
   * IsEmpty() will return true after this call.
98
   */
99
  V8_INLINE void Reset();
100
101
  /**
102
   * If non-empty, destroy the underlying storage cell
103
   * and create a new one with the contents of other if other is non empty
104
   */
105
  template <class S>
106
  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
107
108
  /**
109
   * If non-empty, destroy the underlying storage cell
110
   * and create a new one with the contents of other if other is non empty
111
   */
112
  template <class S>
113
  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
114
115
760k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
760k
    return Local<T>::New(isolate, *this);
117
760k
  }
v8::PersistentBase<v8::Context>::Get(v8::Isolate*) const
Line
Count
Source
115
22.1k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
22.1k
    return Local<T>::New(isolate, *this);
117
22.1k
  }
Unexecuted instantiation: v8::PersistentBase<v8::Int8Array>::Get(v8::Isolate*) const
v8::PersistentBase<v8::Uint8Array>::Get(v8::Isolate*) const
Line
Count
Source
115
140
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
140
    return Local<T>::New(isolate, *this);
117
140
  }
Unexecuted instantiation: v8::PersistentBase<v8::Int16Array>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Uint16Array>::Get(v8::Isolate*) const
v8::PersistentBase<v8::Int32Array>::Get(v8::Isolate*) const
Line
Count
Source
115
70
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
70
    return Local<T>::New(isolate, *this);
117
70
  }
v8::PersistentBase<v8::Uint32Array>::Get(v8::Isolate*) const
Line
Count
Source
115
245
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
245
    return Local<T>::New(isolate, *this);
117
245
  }
Unexecuted instantiation: v8::PersistentBase<v8::Float32Array>::Get(v8::Isolate*) const
v8::PersistentBase<v8::Float64Array>::Get(v8::Isolate*) const
Line
Count
Source
115
175
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
175
    return Local<T>::New(isolate, *this);
117
175
  }
v8::PersistentBase<v8::BigInt64Array>::Get(v8::Isolate*) const
Line
Count
Source
115
70
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
70
    return Local<T>::New(isolate, *this);
117
70
  }
Unexecuted instantiation: v8::PersistentBase<v8::Object>::Get(v8::Isolate*) const
v8::PersistentBase<v8::Value>::Get(v8::Isolate*) const
Line
Count
Source
115
737k
  V8_INLINE Local<T> Get(Isolate* isolate) const {
116
737k
    return Local<T>::New(isolate, *this);
117
737k
  }
Unexecuted instantiation: v8::PersistentBase<v8::Function>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Array>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Module>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Promise>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Promise::Resolver>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::RegExp>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::WasmMemoryObject>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::Map>::Get(v8::Isolate*) const
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBufferView>::Get(v8::Isolate*) const
118
119
  template <class S>
120
  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
121
    return internal::HandleHelper::EqualHandles(*this, that);
122
  }
123
124
  template <class S>
125
0
  V8_INLINE bool operator==(const Local<S>& that) const {
126
0
    return internal::HandleHelper::EqualHandles(*this, that);
127
0
  }
Unexecuted instantiation: bool v8::PersistentBase<v8::Context>::operator==<v8::Context>(v8::Local<v8::Context> const&) const
Unexecuted instantiation: bool v8::PersistentBase<v8::Module>::operator==<v8::Module>(v8::Local<v8::Module> const&) const
128
129
  template <class S>
130
  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
131
    return !operator==(that);
132
  }
133
134
  template <class S>
135
  V8_INLINE bool operator!=(const Local<S>& that) const {
136
    return !operator==(that);
137
  }
138
139
  /**
140
   * Install a finalization callback on this object.
141
   * NOTE: There is no guarantee as to *when* or even *if* the callback is
142
   * invoked. The invocation is performed solely on a best effort basis.
143
   * As always, GC-based finalization should *not* be relied upon for any
144
   * critical form of resource management!
145
   *
146
   * The callback is supposed to reset the handle. No further V8 API may be
147
   * called in this callback. In case additional work involving V8 needs to be
148
   * done, a second callback can be scheduled using
149
   * WeakCallbackInfo<void>::SetSecondPassCallback.
150
   */
151
  template <typename P>
152
  V8_INLINE void SetWeak(P* parameter,
153
                         typename WeakCallbackInfo<P>::Callback callback,
154
                         WeakCallbackType type);
155
156
  /**
157
   * Turns this handle into a weak phantom handle without finalization callback.
158
   * The handle will be reset automatically when the garbage collector detects
159
   * that the object is no longer reachable.
160
   */
161
  V8_INLINE void SetWeak();
162
163
  template <typename P>
164
  V8_INLINE P* ClearWeak();
165
166
  // TODO(dcarney): remove this.
167
0
  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
Unexecuted instantiation: v8::PersistentBase<v8::Object>::ClearWeak()
Unexecuted instantiation: v8::PersistentBase<v8::Value>::ClearWeak()
168
169
  /**
170
   * Annotates the strong handle with the given label, which is then used by the
171
   * heap snapshot generator as a name of the edge from the root to the handle.
172
   * The function does not take ownership of the label and assumes that the
173
   * label is valid as long as the handle is valid.
174
   */
175
  V8_INLINE void AnnotateStrongRetainer(const char* label);
176
177
  /** Returns true if the handle's reference is weak.  */
178
  V8_INLINE bool IsWeak() const;
179
180
  /**
181
   * Assigns a wrapper class ID to the handle.
182
   */
183
  V8_INLINE void SetWrapperClassId(uint16_t class_id);
184
185
  /**
186
   * Returns the class ID previously assigned to this handle or 0 if no class ID
187
   * was previously assigned.
188
   */
189
  V8_INLINE uint16_t WrapperClassId() const;
190
191
  PersistentBase(const PersistentBase& other) = delete;
192
  void operator=(const PersistentBase&) = delete;
193
194
 private:
195
  friend class Isolate;
196
  friend class Utils;
197
  template <class F>
198
  friend class Local;
199
  template <class F1, class F2>
200
  friend class Persistent;
201
  template <class F>
202
  friend class Global;
203
  template <class F>
204
  friend class PersistentBase;
205
  template <class F>
206
  friend class ReturnValue;
207
  template <class F1, class F2, class F3>
208
  friend class PersistentValueMapBase;
209
  friend class Object;
210
  friend class internal::ValueHelper;
211
212
754k
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Object>::PersistentBase()
Line
Count
Source
212
315
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Context>::PersistentBase()
Line
Count
Source
212
70
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Module>::PersistentBase()
Line
Count
Source
212
35
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Array>::PersistentBase()
Line
Count
Source
212
35
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Function>::PersistentBase()
Line
Count
Source
212
1.89k
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Int32Array>::PersistentBase()
Line
Count
Source
212
105
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Uint32Array>::PersistentBase()
Line
Count
Source
212
245
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Uint8Array>::PersistentBase()
Line
Count
Source
212
105
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Float64Array>::PersistentBase()
Line
Count
Source
212
175
  V8_INLINE PersistentBase() = default;
v8::PersistentBase<v8::Value>::PersistentBase()
Line
Count
Source
212
751k
  V8_INLINE PersistentBase() = default;
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::PersistentBase()
v8::PersistentBase<v8::BigInt64Array>::PersistentBase()
Line
Count
Source
212
70
  V8_INLINE PersistentBase() = default;
Unexecuted instantiation: v8::PersistentBase<v8::Promise>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::Promise::Resolver>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::RegExp>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::WasmMemoryObject>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::Map>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBufferView>::PersistentBase()
Unexecuted instantiation: v8::PersistentBase<v8::FunctionTemplate>::PersistentBase()
213
214
  V8_INLINE explicit PersistentBase(internal::Address* location)
215
14.4k
      : IndirectHandleBase(location) {}
Unexecuted instantiation: v8::PersistentBase<v8::Value>::PersistentBase(unsigned long*)
v8::PersistentBase<v8::Object>::PersistentBase(unsigned long*)
Line
Count
Source
215
280
      : IndirectHandleBase(location) {}
v8::PersistentBase<v8::Context>::PersistentBase(unsigned long*)
Line
Count
Source
215
13.4k
      : IndirectHandleBase(location) {}
v8::PersistentBase<v8::Int32Array>::PersistentBase(unsigned long*)
Line
Count
Source
215
105
      : IndirectHandleBase(location) {}
v8::PersistentBase<v8::Uint32Array>::PersistentBase(unsigned long*)
Line
Count
Source
215
245
      : IndirectHandleBase(location) {}
v8::PersistentBase<v8::Uint8Array>::PersistentBase(unsigned long*)
Line
Count
Source
215
105
      : IndirectHandleBase(location) {}
v8::PersistentBase<v8::Float64Array>::PersistentBase(unsigned long*)
Line
Count
Source
215
175
      : IndirectHandleBase(location) {}
Unexecuted instantiation: v8::PersistentBase<v8::Data>::PersistentBase(unsigned long*)
Unexecuted instantiation: v8::PersistentBase<v8::Module>::PersistentBase(unsigned long*)
v8::PersistentBase<v8::BigInt64Array>::PersistentBase(unsigned long*)
Line
Count
Source
215
70
      : IndirectHandleBase(location) {}
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::PersistentBase(unsigned long*)
Unexecuted instantiation: v8::PersistentBase<v8::SharedArrayBuffer>::PersistentBase(unsigned long*)
Unexecuted instantiation: v8::PersistentBase<v8::RegExp>::PersistentBase(unsigned long*)
Unexecuted instantiation: v8::PersistentBase<v8::Function>::PersistentBase(unsigned long*)
Unexecuted instantiation: v8::PersistentBase<v8::Array>::PersistentBase(unsigned long*)
216
217
  V8_INLINE static internal::Address* New(Isolate* isolate, T* that);
218
};
219
220
/**
221
 * Default traits for Persistent. This class does not allow
222
 * use of the copy constructor or assignment operator.
223
 * At present kResetInDestructor is not set, but that will change in a future
224
 * version.
225
 */
226
template <class T>
227
class NonCopyablePersistentTraits {
228
 public:
229
  using NonCopyablePersistent = Persistent<T, NonCopyablePersistentTraits<T>>;
230
  static const bool kResetInDestructor = false;
231
  template <class S, class M>
232
  V8_INLINE static void Copy(const Persistent<S, M>& source,
233
                             NonCopyablePersistent* dest) {
234
    static_assert(sizeof(S) < 0,
235
                  "NonCopyablePersistentTraits::Copy is not instantiable");
236
  }
237
};
238
239
/**
240
 * A PersistentBase which allows copy and assignment.
241
 *
242
 * Copy, assignment and destructor behavior is controlled by the traits
243
 * class M.
244
 *
245
 * CAVEAT: Persistent objects do not have proper destruction behavior by default
246
 * and as such will leak the object without explicit clear. Consider using
247
 * `v8::Global` instead which has proper destruction and move semantics.
248
 */
249
template <class T, class M>
250
class Persistent : public PersistentBase<T> {
251
 public:
252
  /**
253
   * A Persistent with no storage cell.
254
   */
255
  V8_INLINE Persistent() = default;
256
257
  /**
258
   * Construct a Persistent from a Local with automatic up casting.
259
   * When the Local is non-empty, a new storage cell is created
260
   * pointing to the same object, and no flags are set.
261
   */
262
  template <class S>
263
    requires(std::is_base_of_v<T, S>)
264
  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
265
      : PersistentBase<T>(
266
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
267
268
  /**
269
   * Construct a Persistent from a Persistent with automatic up casting.
270
   * When the Persistent is non-empty, a new storage cell is created
271
   * pointing to the same object, and no flags are set.
272
   */
273
  template <class S, class M2>
274
    requires(std::is_base_of_v<T, S>)
275
  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
276
      : PersistentBase<T>(
277
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
278
279
  /**
280
   * The copy constructors and assignment operator create a Persistent
281
   * exactly as the Persistent constructor, but the Copy function from the
282
   * traits class is called, allowing the setting of flags based on the
283
   * copied Persistent.
284
   */
285
  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>() {
286
    Copy(that);
287
  }
288
  template <class S, class M2>
289
  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>() {
290
    Copy(that);
291
  }
292
  V8_INLINE Persistent& operator=(const Persistent& that) {
293
    Copy(that);
294
    return *this;
295
  }
296
  template <class S, class M2>
297
  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) {
298
    Copy(that);
299
    return *this;
300
  }
301
302
  /**
303
   * The destructor will dispose the Persistent based on the
304
   * kResetInDestructor flags in the traits class.  Since not calling dispose
305
   * can result in a memory leak, it is recommended to always set this flag.
306
   */
307
  V8_INLINE ~Persistent() {
308
    if (M::kResetInDestructor) this->Reset();
309
  }
310
311
  // TODO(dcarney): this is pretty useless, fix or remove
312
  template <class S, class M2>
313
  V8_INLINE static Persistent<T, M>& Cast(const Persistent<S, M2>& that) {
314
#ifdef V8_ENABLE_CHECKS
315
    // If we're going to perform the type check then we have to check
316
    // that the handle isn't empty before doing the checked cast.
317
    if (!that.IsEmpty()) T::Cast(that.template value<S>());
318
#endif
319
    return reinterpret_cast<Persistent<T, M>&>(
320
        const_cast<Persistent<S, M2>&>(that));
321
  }
322
323
  // TODO(dcarney): this is pretty useless, fix or remove
324
  template <class S, class M2>
325
  V8_INLINE Persistent<S, M2>& As() const {
326
    return Persistent<S, M2>::Cast(*this);
327
  }
328
329
 private:
330
  friend class Isolate;
331
  friend class Utils;
332
  template <class F>
333
  friend class Local;
334
  template <class F1, class F2>
335
  friend class Persistent;
336
  template <class F>
337
  friend class ReturnValue;
338
339
  template <class S, class M2>
340
  V8_INLINE void Copy(const Persistent<S, M2>& that);
341
};
342
343
/**
344
 * A PersistentBase which has move semantics.
345
 *
346
 * Note: Persistent class hierarchy is subject to future changes.
347
 */
348
template <class T>
349
class Global : public PersistentBase<T> {
350
 public:
351
  /**
352
   * A Global with no storage cell.
353
   */
354
754k
  V8_INLINE Global() = default;
v8::Global<v8::Object>::Global()
Line
Count
Source
354
315
  V8_INLINE Global() = default;
v8::Global<v8::Context>::Global()
Line
Count
Source
354
70
  V8_INLINE Global() = default;
v8::Global<v8::Module>::Global()
Line
Count
Source
354
35
  V8_INLINE Global() = default;
v8::Global<v8::Array>::Global()
Line
Count
Source
354
35
  V8_INLINE Global() = default;
v8::Global<v8::Function>::Global()
Line
Count
Source
354
1.89k
  V8_INLINE Global() = default;
v8::Global<v8::Int32Array>::Global()
Line
Count
Source
354
105
  V8_INLINE Global() = default;
v8::Global<v8::Uint32Array>::Global()
Line
Count
Source
354
245
  V8_INLINE Global() = default;
v8::Global<v8::Uint8Array>::Global()
Line
Count
Source
354
105
  V8_INLINE Global() = default;
v8::Global<v8::Float64Array>::Global()
Line
Count
Source
354
175
  V8_INLINE Global() = default;
v8::Global<v8::Value>::Global()
Line
Count
Source
354
751k
  V8_INLINE Global() = default;
Unexecuted instantiation: v8::Global<v8::ArrayBuffer>::Global()
v8::Global<v8::BigInt64Array>::Global()
Line
Count
Source
354
70
  V8_INLINE Global() = default;
Unexecuted instantiation: v8::Global<v8::Promise>::Global()
Unexecuted instantiation: v8::Global<v8::Promise::Resolver>::Global()
Unexecuted instantiation: v8::Global<v8::RegExp>::Global()
Unexecuted instantiation: v8::Global<v8::WasmMemoryObject>::Global()
Unexecuted instantiation: v8::Global<v8::Map>::Global()
Unexecuted instantiation: v8::Global<v8::ArrayBufferView>::Global()
Unexecuted instantiation: v8::Global<v8::FunctionTemplate>::Global()
355
356
  /**
357
   * Construct a Global from a Local with automatic up casting.
358
   * When the Local is non-empty, a new storage cell is created
359
   * pointing to the same object, and no flags are set.
360
   */
361
  template <class S>
362
    requires(std::is_base_of_v<T, S>)
363
  V8_INLINE Global(Isolate* isolate, Local<S> that)
364
14.4k
      : PersistentBase<T>(
365
14.4k
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
Unexecuted instantiation: _ZN2v86GlobalINS_5ValueEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
_ZN2v86GlobalINS_6ObjectEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
280
      : PersistentBase<T>(
365
280
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
_ZN2v86GlobalINS_10Int32ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
105
      : PersistentBase<T>(
365
105
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
_ZN2v86GlobalINS_11Uint32ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
245
      : PersistentBase<T>(
365
245
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
_ZN2v86GlobalINS_10Uint8ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
105
      : PersistentBase<T>(
365
105
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
_ZN2v86GlobalINS_12Float64ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
175
      : PersistentBase<T>(
365
175
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
Unexecuted instantiation: _ZN2v86GlobalINS_4DataEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Unexecuted instantiation: _ZN2v86GlobalINS_6ModuleEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
_ZN2v86GlobalINS_7ContextEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
13.4k
      : PersistentBase<T>(
365
13.4k
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
_ZN2v86GlobalINS_13BigInt64ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Line
Count
Source
364
70
      : PersistentBase<T>(
365
70
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
Unexecuted instantiation: _ZN2v86GlobalINS_11ArrayBufferEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Unexecuted instantiation: _ZN2v86GlobalINS_17SharedArrayBufferEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Unexecuted instantiation: _ZN2v86GlobalINS_6RegExpEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Unexecuted instantiation: _ZN2v86GlobalINS_8FunctionEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
Unexecuted instantiation: _ZN2v86GlobalINS_5ArrayEEC2IS1_Qsr3stdE12is_base_of_vIT_TL0__EEEPNS_7IsolateENS_5LocalIS4_EE
366
367
  /**
368
   * Construct a Global from a PersistentBase with automatic up casting.
369
   * When the Persistent is non-empty, a new storage cell is created
370
   * pointing to the same object, and no flags are set.
371
   */
372
  template <class S>
373
    requires(std::is_base_of_v<T, S>)
374
  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
375
      : PersistentBase<T>(
376
            PersistentBase<T>::New(isolate, that.template value<S>())) {}
377
378
  /**
379
   * Move constructor.
380
   */
381
  V8_INLINE Global(Global&& other);
382
383
768k
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Context>::~Global()
Line
Count
Source
383
13.5k
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Function>::~Global()
Line
Count
Source
383
1.89k
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Object>::~Global()
Line
Count
Source
383
595
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Value>::~Global()
Line
Count
Source
383
751k
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Int32Array>::~Global()
Line
Count
Source
383
210
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Uint32Array>::~Global()
Line
Count
Source
383
490
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Uint8Array>::~Global()
Line
Count
Source
383
210
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Array>::~Global()
Line
Count
Source
383
35
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Float64Array>::~Global()
Line
Count
Source
383
350
  V8_INLINE ~Global() { this->Reset(); }
v8::Global<v8::Module>::~Global()
Line
Count
Source
383
35
  V8_INLINE ~Global() { this->Reset(); }
Unexecuted instantiation: v8::Global<v8::Data>::~Global()
Unexecuted instantiation: v8::Global<v8::ArrayBuffer>::~Global()
v8::Global<v8::BigInt64Array>::~Global()
Line
Count
Source
383
140
  V8_INLINE ~Global() { this->Reset(); }
Unexecuted instantiation: v8::Global<v8::Promise>::~Global()
Unexecuted instantiation: v8::Global<v8::Promise::Resolver>::~Global()
Unexecuted instantiation: v8::Global<v8::SharedArrayBuffer>::~Global()
Unexecuted instantiation: v8::Global<v8::RegExp>::~Global()
Unexecuted instantiation: v8::Global<v8::WasmMemoryObject>::~Global()
Unexecuted instantiation: v8::Global<v8::Map>::~Global()
Unexecuted instantiation: v8::Global<v8::ArrayBufferView>::~Global()
Unexecuted instantiation: v8::Global<v8::FunctionTemplate>::~Global()
384
385
  /**
386
   * Move via assignment.
387
   */
388
  template <class S>
389
  V8_INLINE Global& operator=(Global<S>&& rhs);
390
391
  /**
392
   * Pass allows returning uniques from functions, etc.
393
   */
394
  Global Pass() { return static_cast<Global&&>(*this); }
395
396
  /*
397
   * For compatibility with Chromium's base::Bind (base::Passed).
398
   */
399
  using MoveOnlyTypeForCPP03 = void;
400
401
  Global(const Global&) = delete;
402
  void operator=(const Global&) = delete;
403
404
 private:
405
  template <class F>
406
  friend class ReturnValue;
407
};
408
409
// UniquePersistent is an alias for Global for historical reason.
410
template <class T>
411
using UniquePersistent = Global<T>;
412
413
/**
414
 * Interface for iterating through all the persistent handles in the heap.
415
 */
416
class V8_EXPORT PersistentHandleVisitor {
417
 public:
418
  virtual ~PersistentHandleVisitor() = default;
419
  virtual void VisitPersistentHandle(Persistent<Value>* value,
420
0
                                     uint16_t class_id) {}
421
};
422
423
template <class T>
424
774k
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
774k
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
774k
  return api_internal::GlobalizeReference(
427
774k
      reinterpret_cast<internal::Isolate*>(isolate),
428
774k
      internal::ValueHelper::ValueAsAddress(that));
429
774k
}
v8::PersistentBase<v8::Context>::New(v8::Isolate*, v8::Context*)
Line
Count
Source
424
13.5k
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
13.5k
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
13.5k
  return api_internal::GlobalizeReference(
427
13.5k
      reinterpret_cast<internal::Isolate*>(isolate),
428
13.5k
      internal::ValueHelper::ValueAsAddress(that));
429
13.5k
}
v8::PersistentBase<v8::Function>::New(v8::Isolate*, v8::Function*)
Line
Count
Source
424
875
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
875
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
875
  return api_internal::GlobalizeReference(
427
875
      reinterpret_cast<internal::Isolate*>(isolate),
428
875
      internal::ValueHelper::ValueAsAddress(that));
429
875
}
v8::PersistentBase<v8::Value>::New(v8::Isolate*, v8::Value*)
Line
Count
Source
424
758k
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
758k
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
758k
  return api_internal::GlobalizeReference(
427
758k
      reinterpret_cast<internal::Isolate*>(isolate),
428
758k
      internal::ValueHelper::ValueAsAddress(that));
429
758k
}
v8::PersistentBase<v8::Array>::New(v8::Isolate*, v8::Array*)
Line
Count
Source
424
35
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
35
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
35
  return api_internal::GlobalizeReference(
427
35
      reinterpret_cast<internal::Isolate*>(isolate),
428
35
      internal::ValueHelper::ValueAsAddress(that));
429
35
}
v8::PersistentBase<v8::Object>::New(v8::Isolate*, v8::Object*)
Line
Count
Source
424
560
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
560
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
560
  return api_internal::GlobalizeReference(
427
560
      reinterpret_cast<internal::Isolate*>(isolate),
428
560
      internal::ValueHelper::ValueAsAddress(that));
429
560
}
v8::PersistentBase<v8::Int32Array>::New(v8::Isolate*, v8::Int32Array*)
Line
Count
Source
424
105
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
105
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
105
  return api_internal::GlobalizeReference(
427
105
      reinterpret_cast<internal::Isolate*>(isolate),
428
105
      internal::ValueHelper::ValueAsAddress(that));
429
105
}
v8::PersistentBase<v8::Uint32Array>::New(v8::Isolate*, v8::Uint32Array*)
Line
Count
Source
424
245
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
245
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
245
  return api_internal::GlobalizeReference(
427
245
      reinterpret_cast<internal::Isolate*>(isolate),
428
245
      internal::ValueHelper::ValueAsAddress(that));
429
245
}
v8::PersistentBase<v8::Uint8Array>::New(v8::Isolate*, v8::Uint8Array*)
Line
Count
Source
424
105
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
105
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
105
  return api_internal::GlobalizeReference(
427
105
      reinterpret_cast<internal::Isolate*>(isolate),
428
105
      internal::ValueHelper::ValueAsAddress(that));
429
105
}
v8::PersistentBase<v8::Float64Array>::New(v8::Isolate*, v8::Float64Array*)
Line
Count
Source
424
175
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
175
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
175
  return api_internal::GlobalizeReference(
427
175
      reinterpret_cast<internal::Isolate*>(isolate),
428
175
      internal::ValueHelper::ValueAsAddress(that));
429
175
}
Unexecuted instantiation: v8::PersistentBase<v8::Data>::New(v8::Isolate*, v8::Data*)
Unexecuted instantiation: v8::PersistentBase<v8::Module>::New(v8::Isolate*, v8::Module*)
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::New(v8::Isolate*, v8::ArrayBuffer*)
v8::PersistentBase<v8::BigInt64Array>::New(v8::Isolate*, v8::BigInt64Array*)
Line
Count
Source
424
70
internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
70
  if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
70
  return api_internal::GlobalizeReference(
427
70
      reinterpret_cast<internal::Isolate*>(isolate),
428
70
      internal::ValueHelper::ValueAsAddress(that));
429
70
}
Unexecuted instantiation: v8::PersistentBase<v8::Promise>::New(v8::Isolate*, v8::Promise*)
Unexecuted instantiation: v8::PersistentBase<v8::Promise::Resolver>::New(v8::Isolate*, v8::Promise::Resolver*)
Unexecuted instantiation: v8::PersistentBase<v8::SharedArrayBuffer>::New(v8::Isolate*, v8::SharedArrayBuffer*)
Unexecuted instantiation: v8::PersistentBase<v8::RegExp>::New(v8::Isolate*, v8::RegExp*)
Unexecuted instantiation: v8::PersistentBase<v8::WasmMemoryObject>::New(v8::Isolate*, v8::WasmMemoryObject*)
Unexecuted instantiation: v8::PersistentBase<v8::Map>::New(v8::Isolate*, v8::Map*)
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBufferView>::New(v8::Isolate*, v8::ArrayBufferView*)
Unexecuted instantiation: v8::PersistentBase<v8::FunctionTemplate>::New(v8::Isolate*, v8::FunctionTemplate*)
430
431
template <class T, class M>
432
template <class S, class M2>
433
void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
434
  static_assert(std::is_base_of_v<T, S>, "type check");
435
  this->Reset();
436
  if (that.IsEmpty()) return;
437
  this->slot() = api_internal::CopyGlobalReference(that.slot());
438
  M::Copy(that, this);
439
}
440
441
template <class T>
442
560
bool PersistentBase<T>::IsWeak() const {
443
560
  using I = internal::Internals;
444
560
  if (this->IsEmpty()) return false;
445
560
  return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
446
560
}
Unexecuted instantiation: v8::PersistentBase<v8::Int8Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Uint8Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Int16Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Uint16Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Int32Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Uint32Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Float32Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Float64Array>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::BigInt64Array>::IsWeak() const
v8::PersistentBase<v8::Object>::IsWeak() const
Line
Count
Source
442
560
bool PersistentBase<T>::IsWeak() const {
443
560
  using I = internal::Internals;
444
560
  if (this->IsEmpty()) return false;
445
560
  return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
446
560
}
Unexecuted instantiation: v8::PersistentBase<v8::Function>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Promise>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Value>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Promise::Resolver>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Context>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::WasmMemoryObject>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::Map>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBufferView>::IsWeak() const
Unexecuted instantiation: v8::PersistentBase<v8::FunctionTemplate>::IsWeak() const
447
448
template <class T>
449
1.55M
void PersistentBase<T>::Reset() {
450
1.55M
  if (this->IsEmpty()) return;
451
774k
  api_internal::DisposeGlobal(this->slot());
452
774k
  this->Clear();
453
774k
}
v8::PersistentBase<v8::Context>::Reset()
Line
Count
Source
449
13.7k
void PersistentBase<T>::Reset() {
450
13.7k
  if (this->IsEmpty()) return;
451
13.5k
  api_internal::DisposeGlobal(this->slot());
452
13.5k
  this->Clear();
453
13.5k
}
v8::PersistentBase<v8::Function>::Reset()
Line
Count
Source
449
3.01k
void PersistentBase<T>::Reset() {
450
3.01k
  if (this->IsEmpty()) return;
451
875
  api_internal::DisposeGlobal(this->slot());
452
875
  this->Clear();
453
875
}
v8::PersistentBase<v8::Value>::Reset()
Line
Count
Source
449
1.53M
void PersistentBase<T>::Reset() {
450
1.53M
  if (this->IsEmpty()) return;
451
758k
  api_internal::DisposeGlobal(this->slot());
452
758k
  this->Clear();
453
758k
}
v8::PersistentBase<v8::Array>::Reset()
Line
Count
Source
449
70
void PersistentBase<T>::Reset() {
450
70
  if (this->IsEmpty()) return;
451
35
  api_internal::DisposeGlobal(this->slot());
452
35
  this->Clear();
453
35
}
v8::PersistentBase<v8::Object>::Reset()
Line
Count
Source
449
875
void PersistentBase<T>::Reset() {
450
875
  if (this->IsEmpty()) return;
451
560
  api_internal::DisposeGlobal(this->slot());
452
560
  this->Clear();
453
560
}
v8::PersistentBase<v8::Int32Array>::Reset()
Line
Count
Source
449
315
void PersistentBase<T>::Reset() {
450
315
  if (this->IsEmpty()) return;
451
105
  api_internal::DisposeGlobal(this->slot());
452
105
  this->Clear();
453
105
}
v8::PersistentBase<v8::Uint32Array>::Reset()
Line
Count
Source
449
735
void PersistentBase<T>::Reset() {
450
735
  if (this->IsEmpty()) return;
451
245
  api_internal::DisposeGlobal(this->slot());
452
245
  this->Clear();
453
245
}
v8::PersistentBase<v8::Uint8Array>::Reset()
Line
Count
Source
449
315
void PersistentBase<T>::Reset() {
450
315
  if (this->IsEmpty()) return;
451
105
  api_internal::DisposeGlobal(this->slot());
452
105
  this->Clear();
453
105
}
v8::PersistentBase<v8::Float64Array>::Reset()
Line
Count
Source
449
525
void PersistentBase<T>::Reset() {
450
525
  if (this->IsEmpty()) return;
451
175
  api_internal::DisposeGlobal(this->slot());
452
175
  this->Clear();
453
175
}
v8::PersistentBase<v8::Module>::Reset()
Line
Count
Source
449
35
void PersistentBase<T>::Reset() {
450
35
  if (this->IsEmpty()) return;
451
0
  api_internal::DisposeGlobal(this->slot());
452
0
  this->Clear();
453
0
}
Unexecuted instantiation: v8::PersistentBase<v8::Data>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::Reset()
v8::PersistentBase<v8::BigInt64Array>::Reset()
Line
Count
Source
449
210
void PersistentBase<T>::Reset() {
450
210
  if (this->IsEmpty()) return;
451
70
  api_internal::DisposeGlobal(this->slot());
452
70
  this->Clear();
453
70
}
Unexecuted instantiation: v8::PersistentBase<v8::Promise>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::Promise::Resolver>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::SharedArrayBuffer>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::RegExp>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::WasmMemoryObject>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::Map>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBufferView>::Reset()
Unexecuted instantiation: v8::PersistentBase<v8::FunctionTemplate>::Reset()
454
455
/**
456
 * If non-empty, destroy the underlying storage cell
457
 * and create a new one with the contents of other if other is non empty
458
 */
459
template <class T>
460
template <class S>
461
760k
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
760k
  static_assert(std::is_base_of_v<T, S>, "type check");
463
760k
  Reset();
464
760k
  if (other.IsEmpty()) return;
465
759k
  this->slot() = New(isolate, *other);
466
759k
}
void v8::PersistentBase<v8::Context>::Reset<v8::Context>(v8::Isolate*, v8::Local<v8::Context> const&)
Line
Count
Source
461
105
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
105
  static_assert(std::is_base_of_v<T, S>, "type check");
463
105
  Reset();
464
105
  if (other.IsEmpty()) return;
465
105
  this->slot() = New(isolate, *other);
466
105
}
void v8::PersistentBase<v8::Function>::Reset<v8::Function>(v8::Isolate*, v8::Local<v8::Function> const&)
Line
Count
Source
461
1.08k
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
1.08k
  static_assert(std::is_base_of_v<T, S>, "type check");
463
1.08k
  Reset();
464
1.08k
  if (other.IsEmpty()) return;
465
875
  this->slot() = New(isolate, *other);
466
875
}
void v8::PersistentBase<v8::Array>::Reset<v8::Array>(v8::Isolate*, v8::Local<v8::Array> const&)
Line
Count
Source
461
35
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
35
  static_assert(std::is_base_of_v<T, S>, "type check");
463
35
  Reset();
464
35
  if (other.IsEmpty()) return;
465
35
  this->slot() = New(isolate, *other);
466
35
}
void v8::PersistentBase<v8::Object>::Reset<v8::Object>(v8::Isolate*, v8::Local<v8::Object> const&)
Line
Count
Source
461
280
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
280
  static_assert(std::is_base_of_v<T, S>, "type check");
463
280
  Reset();
464
280
  if (other.IsEmpty()) return;
465
280
  this->slot() = New(isolate, *other);
466
280
}
void v8::PersistentBase<v8::Value>::Reset<v8::Value>(v8::Isolate*, v8::Local<v8::Value> const&)
Line
Count
Source
461
758k
void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
758k
  static_assert(std::is_base_of_v<T, S>, "type check");
463
758k
  Reset();
464
758k
  if (other.IsEmpty()) return;
465
758k
  this->slot() = New(isolate, *other);
466
758k
}
Unexecuted instantiation: void v8::PersistentBase<v8::Uint32Array>::Reset<v8::Uint32Array>(v8::Isolate*, v8::Local<v8::Uint32Array> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Uint8Array>::Reset<v8::Uint8Array>(v8::Isolate*, v8::Local<v8::Uint8Array> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Float64Array>::Reset<v8::Float64Array>(v8::Isolate*, v8::Local<v8::Float64Array> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Int32Array>::Reset<v8::Int32Array>(v8::Isolate*, v8::Local<v8::Int32Array> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Module>::Reset<v8::Module>(v8::Isolate*, v8::Local<v8::Module> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::ArrayBuffer>::Reset<v8::ArrayBuffer>(v8::Isolate*, v8::Local<v8::ArrayBuffer> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Promise>::Reset<v8::Promise>(v8::Isolate*, v8::Local<v8::Promise> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::BigInt64Array>::Reset<v8::BigInt64Array>(v8::Isolate*, v8::Local<v8::BigInt64Array> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Promise::Resolver>::Reset<v8::Promise::Resolver>(v8::Isolate*, v8::Local<v8::Promise::Resolver> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::WasmMemoryObject>::Reset<v8::WasmMemoryObject>(v8::Isolate*, v8::Local<v8::WasmMemoryObject> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Map>::Reset<v8::Map>(v8::Isolate*, v8::Local<v8::Map> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::ArrayBufferView>::Reset<v8::ArrayBufferView>(v8::Isolate*, v8::Local<v8::ArrayBufferView> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Value>::Reset<v8::External>(v8::Isolate*, v8::Local<v8::External> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::Value>::Reset<v8::Promise::Resolver>(v8::Isolate*, v8::Local<v8::Promise::Resolver> const&)
Unexecuted instantiation: void v8::PersistentBase<v8::FunctionTemplate>::Reset<v8::FunctionTemplate>(v8::Isolate*, v8::Local<v8::FunctionTemplate> const&)
467
468
/**
469
 * If non-empty, destroy the underlying storage cell
470
 * and create a new one with the contents of other if other is non empty
471
 */
472
template <class T>
473
template <class S>
474
void PersistentBase<T>::Reset(Isolate* isolate,
475
                              const PersistentBase<S>& other) {
476
  static_assert(std::is_base_of_v<T, S>, "type check");
477
  Reset();
478
  if (other.IsEmpty()) return;
479
  this->slot() = New(isolate, other.template value<S>());
480
}
481
482
template <class T>
483
template <typename P>
484
V8_INLINE void PersistentBase<T>::SetWeak(
485
    P* parameter, typename WeakCallbackInfo<P>::Callback callback,
486
315
    WeakCallbackType type) {
487
315
  using Callback = WeakCallbackInfo<void>::Callback;
488
#if (__GNUC__ >= 8) && !defined(__clang__)
489
#pragma GCC diagnostic push
490
#pragma GCC diagnostic ignored "-Wcast-function-type"
491
#endif
492
315
#if __clang__
493
315
#pragma clang diagnostic push
494
315
#pragma clang diagnostic ignored "-Wcast-function-type"
495
315
#endif
496
315
  api_internal::MakeWeak(this->slot(), parameter,
497
315
                         reinterpret_cast<Callback>(callback), type);
498
315
#if __clang__
499
315
#pragma clang diagnostic pop
500
315
#endif
501
#if (__GNUC__ >= 8) && !defined(__clang__)
502
#pragma GCC diagnostic pop
503
#endif
504
315
}
Unexecuted instantiation: void v8::PersistentBase<v8::Object>::SetWeak<node::DestroyParam>(node::DestroyParam*, v8::WeakCallbackInfo<node::DestroyParam>::Callback, v8::WeakCallbackType)
void v8::PersistentBase<v8::Object>::SetWeak<node::BaseObject>(node::BaseObject*, v8::WeakCallbackInfo<node::BaseObject>::Callback, v8::WeakCallbackType)
Line
Count
Source
486
315
    WeakCallbackType type) {
487
315
  using Callback = WeakCallbackInfo<void>::Callback;
488
#if (__GNUC__ >= 8) && !defined(__clang__)
489
#pragma GCC diagnostic push
490
#pragma GCC diagnostic ignored "-Wcast-function-type"
491
#endif
492
315
#if __clang__
493
315
#pragma clang diagnostic push
494
315
#pragma clang diagnostic ignored "-Wcast-function-type"
495
315
#endif
496
315
  api_internal::MakeWeak(this->slot(), parameter,
497
315
                         reinterpret_cast<Callback>(callback), type);
498
315
#if __clang__
499
315
#pragma clang diagnostic pop
500
315
#endif
501
#if (__GNUC__ >= 8) && !defined(__clang__)
502
#pragma GCC diagnostic pop
503
#endif
504
315
}
Unexecuted instantiation: void v8::PersistentBase<v8::Context>::SetWeak<node::shadow_realm::ShadowRealm>(node::shadow_realm::ShadowRealm*, v8::WeakCallbackInfo<node::shadow_realm::ShadowRealm>::Callback, v8::WeakCallbackType)
Unexecuted instantiation: void v8::PersistentBase<v8::Value>::SetWeak<v8impl::ExternalWrapper>(v8impl::ExternalWrapper*, v8::WeakCallbackInfo<v8impl::ExternalWrapper>::Callback, v8::WeakCallbackType)
Unexecuted instantiation: void v8::PersistentBase<v8::Value>::SetWeak<v8impl::Reference>(v8impl::Reference*, v8::WeakCallbackInfo<v8impl::Reference>::Callback, v8::WeakCallbackType)
505
506
template <class T>
507
315
void PersistentBase<T>::SetWeak() {
508
315
  api_internal::MakeWeak(&this->slot());
509
315
}
v8::PersistentBase<v8::Context>::SetWeak()
Line
Count
Source
507
35
void PersistentBase<T>::SetWeak() {
508
35
  api_internal::MakeWeak(&this->slot());
509
35
}
Unexecuted instantiation: v8::PersistentBase<v8::Module>::SetWeak()
Unexecuted instantiation: v8::PersistentBase<v8::ArrayBuffer>::SetWeak()
v8::PersistentBase<v8::Float64Array>::SetWeak()
Line
Count
Source
507
70
void PersistentBase<T>::SetWeak() {
508
70
  api_internal::MakeWeak(&this->slot());
509
70
}
v8::PersistentBase<v8::BigInt64Array>::SetWeak()
Line
Count
Source
507
70
void PersistentBase<T>::SetWeak() {
508
70
  api_internal::MakeWeak(&this->slot());
509
70
}
v8::PersistentBase<v8::Uint32Array>::SetWeak()
Line
Count
Source
507
105
void PersistentBase<T>::SetWeak() {
508
105
  api_internal::MakeWeak(&this->slot());
509
105
}
Unexecuted instantiation: v8::PersistentBase<v8::Function>::SetWeak()
Unexecuted instantiation: v8::PersistentBase<v8::Object>::SetWeak()
v8::PersistentBase<v8::Uint8Array>::SetWeak()
Line
Count
Source
507
35
void PersistentBase<T>::SetWeak() {
508
35
  api_internal::MakeWeak(&this->slot());
509
35
}
510
511
template <class T>
512
template <typename P>
513
0
P* PersistentBase<T>::ClearWeak() {
514
0
  return reinterpret_cast<P*>(api_internal::ClearWeak(this->slot()));
515
0
}
Unexecuted instantiation: void* v8::PersistentBase<v8::Object>::ClearWeak<void>()
Unexecuted instantiation: void* v8::PersistentBase<v8::Value>::ClearWeak<void>()
516
517
template <class T>
518
void PersistentBase<T>::AnnotateStrongRetainer(const char* label) {
519
  api_internal::AnnotateStrongRetainer(this->slot(), label);
520
}
521
522
template <class T>
523
void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
524
  using I = internal::Internals;
525
  if (this->IsEmpty()) return;
526
  uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
527
  *reinterpret_cast<uint16_t*>(addr) = class_id;
528
}
529
530
template <class T>
531
uint16_t PersistentBase<T>::WrapperClassId() const {
532
  using I = internal::Internals;
533
  if (this->IsEmpty()) return 0;
534
  uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
535
  return *reinterpret_cast<uint16_t*>(addr);
536
}
537
538
template <class T>
539
0
Global<T>::Global(Global&& other) : PersistentBase<T>(other.slot()) {
540
0
  if (!other.IsEmpty()) {
541
0
    api_internal::MoveGlobalReference(&other.slot(), &this->slot());
542
0
    other.Clear();
543
0
  }
544
0
}
Unexecuted instantiation: v8::Global<v8::Context>::Global(v8::Global<v8::Context>&&)
Unexecuted instantiation: v8::Global<v8::Object>::Global(v8::Global<v8::Object>&&)
Unexecuted instantiation: v8::Global<v8::Value>::Global(v8::Global<v8::Value>&&)
Unexecuted instantiation: v8::Global<v8::SharedArrayBuffer>::Global(v8::Global<v8::SharedArrayBuffer>&&)
Unexecuted instantiation: v8::Global<v8::RegExp>::Global(v8::Global<v8::RegExp>&&)
Unexecuted instantiation: v8::Global<v8::Array>::Global(v8::Global<v8::Array>&&)
545
546
template <class T>
547
template <class S>
548
700
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
700
  static_assert(std::is_base_of_v<T, S>, "type check");
550
700
  if (this != &rhs) {
551
700
    this->Reset();
552
700
    if (!rhs.IsEmpty()) {
553
700
      this->slot() = rhs.slot();
554
700
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
700
      rhs.Clear();
556
700
    }
557
700
  }
558
700
  return *this;
559
700
}
Unexecuted instantiation: v8::Global<v8::Context>& v8::Global<v8::Context>::operator=<v8::Context>(v8::Global<v8::Context>&&)
v8::Global<v8::Int32Array>& v8::Global<v8::Int32Array>::operator=<v8::Int32Array>(v8::Global<v8::Int32Array>&&)
Line
Count
Source
548
105
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
105
  static_assert(std::is_base_of_v<T, S>, "type check");
550
105
  if (this != &rhs) {
551
105
    this->Reset();
552
105
    if (!rhs.IsEmpty()) {
553
105
      this->slot() = rhs.slot();
554
105
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
105
      rhs.Clear();
556
105
    }
557
105
  }
558
105
  return *this;
559
105
}
v8::Global<v8::Uint32Array>& v8::Global<v8::Uint32Array>::operator=<v8::Uint32Array>(v8::Global<v8::Uint32Array>&&)
Line
Count
Source
548
245
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
245
  static_assert(std::is_base_of_v<T, S>, "type check");
550
245
  if (this != &rhs) {
551
245
    this->Reset();
552
245
    if (!rhs.IsEmpty()) {
553
245
      this->slot() = rhs.slot();
554
245
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
245
      rhs.Clear();
556
245
    }
557
245
  }
558
245
  return *this;
559
245
}
v8::Global<v8::Uint8Array>& v8::Global<v8::Uint8Array>::operator=<v8::Uint8Array>(v8::Global<v8::Uint8Array>&&)
Line
Count
Source
548
105
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
105
  static_assert(std::is_base_of_v<T, S>, "type check");
550
105
  if (this != &rhs) {
551
105
    this->Reset();
552
105
    if (!rhs.IsEmpty()) {
553
105
      this->slot() = rhs.slot();
554
105
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
105
      rhs.Clear();
556
105
    }
557
105
  }
558
105
  return *this;
559
105
}
v8::Global<v8::Float64Array>& v8::Global<v8::Float64Array>::operator=<v8::Float64Array>(v8::Global<v8::Float64Array>&&)
Line
Count
Source
548
175
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
175
  static_assert(std::is_base_of_v<T, S>, "type check");
550
175
  if (this != &rhs) {
551
175
    this->Reset();
552
175
    if (!rhs.IsEmpty()) {
553
175
      this->slot() = rhs.slot();
554
175
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
175
      rhs.Clear();
556
175
    }
557
175
  }
558
175
  return *this;
559
175
}
v8::Global<v8::BigInt64Array>& v8::Global<v8::BigInt64Array>::operator=<v8::BigInt64Array>(v8::Global<v8::BigInt64Array>&&)
Line
Count
Source
548
70
Global<T>& Global<T>::operator=(Global<S>&& rhs) {
549
70
  static_assert(std::is_base_of_v<T, S>, "type check");
550
70
  if (this != &rhs) {
551
70
    this->Reset();
552
70
    if (!rhs.IsEmpty()) {
553
70
      this->slot() = rhs.slot();
554
70
      api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
555
70
      rhs.Clear();
556
70
    }
557
70
  }
558
70
  return *this;
559
70
}
Unexecuted instantiation: v8::Global<v8::ArrayBuffer>& v8::Global<v8::ArrayBuffer>::operator=<v8::ArrayBuffer>(v8::Global<v8::ArrayBuffer>&&)
Unexecuted instantiation: v8::Global<v8::RegExp>& v8::Global<v8::RegExp>::operator=<v8::RegExp>(v8::Global<v8::RegExp>&&)
560
561
}  // namespace v8
562
563
#endif  // INCLUDE_V8_PERSISTENT_HANDLE_H_