V8: include/v8-persistent-handle.h Source File (original) (raw)
1
2
3
4
5#ifndef INCLUDE_V8_PERSISTENT_HANDLE_H_
6#define INCLUDE_V8_PERSISTENT_HANDLE_H_
7
8#include "v8-internal.h"
11#include "v8config.h"
12
13namespace v8 {
14
15class Isolate;
16template <class K, class V, class T>
17class PersistentValueMapBase;
18template
19class Global;
20template
21class PersistentBase;
22template <class K, class V, class T>
23class PersistentValueMap;
24class Value;
25
26namespace api_internal {
33 const char* label);
38}
39
44template
46 public:
48
52 template
53 requires(std::is_base_of_v<T, S>)
55 Set(isolate, handle);
56 }
57
58
60
61
63 }
64
65 template
66 requires(std::is_base_of_v<T, S>)
70 }
71};
72
73namespace api_internal {
77}
78
92template
94 public:
100
105 template
107
112 template
114
117 }
118
119 template
122 }
123
124 template
127 }
128
129 template
132 }
133
134 template
137 }
138
151 template
155
162
163 template
165
166
168
176
179
184
190
193
194 private:
197 template
199 template <class F1, class F2>
201 template
203 template
205 template
207 template <class F1, class F2, class F3>
211
213
216
218};
219
226template
228 public:
231 template <class S, class M>
234 static_assert(sizeof(S) < 0,
235 "NonCopyablePersistentTraits::Copy is not instantiable");
236 }
237};
238
249template <class T, class M>
251 public:
256
262 template
263 requires(std::is_base_of_v<T, S>)
267
273 template <class S, class M2>
274 requires(std::is_base_of_v<T, S>)
278
286 Copy(that);
287 }
288 template <class S, class M2>
290 Copy(that);
291 }
293 Copy(that);
294 return *this;
295 }
296 template <class S, class M2>
298 Copy(that);
299 return *this;
300 }
301
308 if (M::kResetInDestructor) this->Reset();
309 }
310
311
312 template <class S, class M2>
314#ifdef V8_ENABLE_CHECKS
315
316
317 if (!that.IsEmpty()) T::Cast(that.template value());
318#endif
321 }
322
323
324 template <class S, class M2>
327 }
328
329 private:
332 template
334 template <class F1, class F2>
336 template
338
339 template <class S, class M2>
341};
342
348template
350 public:
355
361 template
362 requires(std::is_base_of_v<T, S>)
366
372 template
373 requires(std::is_base_of_v<T, S>)
377
382
384
388 template
390
395
396
397
398
400
403
404 private:
405 template
407};
408
409
410template
412
417 public:
420 uint16_t class_id) {}
421};
422
423template
424internal::Address* PersistentBase::New(Isolate* isolate, T* that) {
427 reinterpret_castinternal::Isolate\*\(isolate),
429}
430
431template <class T, class M>
432template <class S, class M2>
433void 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;
438 M::Copy(that, this);
439}
440
441template
444 if (this->IsEmpty()) return false;
445 return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
446}
447
448template
450 if (this->IsEmpty()) return;
452 this->Clear();
453}
454
459template
460template
462 static_assert(std::is_base_of_v<T, S>, "type check");
463 Reset();
464 if (other.IsEmpty()) return;
465 this->slot() = New(isolate, *other);
466}
467
472template
473template
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());
480}
481
482template
483template
488#if (__GNUC__ >= 8) || defined(__clang__)
489#pragma GCC diagnostic push
490#pragma GCC diagnostic ignored "-Wcast-function-type"
491#endif
493 reinterpret_cast<Callback>(callback), type);
494#if (__GNUC__ >= 8) || defined(__clang__)
495#pragma GCC diagnostic pop
496#endif
497}
498
499template
502}
503
504template
505template
508}
509
510template
513}
514
515template
518 if (this->IsEmpty()) return;
519 uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
520 *reinterpret_cast<uint16_t*>(addr) = class_id;
521}
522
523template
526 if (this->IsEmpty()) return 0;
527 uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
528 return *reinterpret_cast<uint16_t*>(addr);
529}
530
531template
533 if (!other.IsEmpty()) {
535 other.Clear();
536 }
537}
538
539template
540template
542 static_assert(std::is_base_of_v<T, S>, "type check");
543 if (this != &rhs) {
544 this->Reset();
545 if (!rhs.IsEmpty()) {
546 this->slot() = rhs.slot();
548 rhs.Clear();
549 }
550 }
551 return *this;
552}
553
554}
555
556#endif
Definition: v8-persistent-handle.h:45
Local< T > Get(Isolate *isolate) const
Definition: v8-persistent-handle.h:59
Eternal(Isolate *isolate, Local< S > handle)
Definition: v8-persistent-handle.h:54
void Set(Isolate *isolate, Local< S > handle)
Definition: v8-persistent-handle.h:67
Definition: v8-persistent-handle.h:349
void MoveOnlyTypeForCPP03
Definition: v8-persistent-handle.h:399
Global & operator=(Global< S > &&rhs)
void operator=(const Global &)=delete
~Global()
Definition: v8-persistent-handle.h:383
Global(Isolate *isolate, Local< S > that)
Definition: v8-persistent-handle.h:363
Global Pass()
Definition: v8-persistent-handle.h:394
Global(Global &&other)
Definition: v8-persistent-handle.h:532
Global(Isolate *isolate, const PersistentBase< S > &that)
Definition: v8-persistent-handle.h:374
Global(const Global &)=delete
Definition: v8-isolate.h:291
Definition: v8-local-handle.h:366
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:448
Definition: v8-persistent-handle.h:227
static const bool kResetInDestructor
Definition: v8-persistent-handle.h:230
static void Copy(const Persistent< S, M > &source, NonCopyablePersistent *dest)
Definition: v8-persistent-handle.h:232
Definition: v8-object.h:262
Definition: v8-persistent-handle.h:93
void SetWeak(P *parameter, typename WeakCallbackInfo< P >::Callback callback, WeakCallbackType type)
Definition: v8-persistent-handle.h:484
void SetWeak()
Definition: v8-persistent-handle.h:500
void Reset()
Definition: v8-persistent-handle.h:449
void AnnotateStrongRetainer(const char *label)
Definition: v8-persistent-handle.h:511
void ClearWeak()
Definition: v8-persistent-handle.h:167
Local< T > Get(Isolate *isolate) const
Definition: v8-persistent-handle.h:115
bool IsWeak() const
Definition: v8-persistent-handle.h:442
void Reset(Isolate *isolate, const PersistentBase< S > &other)
Definition: v8-persistent-handle.h:474
bool operator==(const Local< S > &that) const
Definition: v8-persistent-handle.h:125
P * ClearWeak()
Definition: v8-persistent-handle.h:506
PersistentBase(const PersistentBase &other)=delete
bool operator!=(const PersistentBase< S > &that) const
Definition: v8-persistent-handle.h:130
void Reset(Isolate *isolate, const Local< S > &other)
Definition: v8-persistent-handle.h:461
bool operator==(const PersistentBase< S > &that) const
Definition: v8-persistent-handle.h:120
friend class PersistentBase
Definition: v8-persistent-handle.h:204
friend class Utils
Definition: v8-persistent-handle.h:196
void SetWrapperClassId(uint16_t class_id)
Definition: v8-persistent-handle.h:516
uint16_t WrapperClassId() const
Definition: v8-persistent-handle.h:524
bool operator!=(const Local< S > &that) const
Definition: v8-persistent-handle.h:135
void operator=(const PersistentBase &)=delete
Definition: v8-persistent-handle.h:416
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
Definition: v8-persistent-handle.h:419
virtual ~PersistentHandleVisitor()=default
Definition: v8-util.h:166
Definition: v8-persistent-handle.h:250
~Persistent()
Definition: v8-persistent-handle.h:307
Persistent(const Persistent< S, M2 > &that)
Definition: v8-persistent-handle.h:289
Persistent< S, M2 > & As() const
Definition: v8-persistent-handle.h:325
Persistent & operator=(const Persistent< S, M2 > &that)
Definition: v8-persistent-handle.h:297
Persistent & operator=(const Persistent &that)
Definition: v8-persistent-handle.h:292
friend class Utils
Definition: v8-persistent-handle.h:331
Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
Definition: v8-persistent-handle.h:275
static Persistent< T, M > & Cast(const Persistent< S, M2 > &that)
Definition: v8-persistent-handle.h:313
Persistent(Isolate *isolate, Local< S > that)
Definition: v8-persistent-handle.h:264
Persistent(const Persistent &that)
Definition: v8-persistent-handle.h:285
Definition: v8-function-callback.h:41
Definition: v8-container.h:148
Definition: v8-value.h:32
void(*)(const WeakCallbackInfo< T > &data) Callback
Definition: v8-weak-callback-info.h:28
Definition: v8-handle-base.h:57
IndirectHandleBase()=default
internal::Address *const & slot() const
Definition: v8-handle-base.h:83
bool IsEmpty() const
Definition: v8-handle-base.h:60
static bool EqualHandles(const T1 &lhs, const T2 &rhs)
Definition: v8-internal.h:1776
Definition: v8-internal.h:885
Definition: v8-internal.h:1677
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1737
static bool IsEmpty(T *value)
Definition: v8-internal.h:1696
void DisposeGlobal(internal::Address *global_handle)
void AnnotateStrongRetainer(internal::Address *location, const char *label)
void MoveGlobalReference(internal::Address **from, internal::Address **to)
internal::Address * GlobalizeReference(internal::Isolate *isolate, internal::Address value)
void * ClearWeak(internal::Address *location)
internal::Address * Eternalize(v8::Isolate *isolate, Value *handle)
void MakeWeak(internal::Address **location_addr)
internal::Address * CopyGlobalReference(internal::Address *from)
uintptr_t Address
Definition: v8-internal.h:38
Definition: libplatform.h:15
WeakCallbackType
Definition: v8-weak-callback-info.h:65
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508