File indexing completed on 2025-04-02 08:54:43
0001
0002
0003
0004
0005 #ifndef INCLUDE_CPPGC_PREFINALIZER_H_
0006 #define INCLUDE_CPPGC_PREFINALIZER_H_
0007
0008 #include "cppgc/internal/compiler-specific.h"
0009 #include "cppgc/liveness-broker.h"
0010
0011 namespace cppgc {
0012
0013 namespace internal {
0014
0015 class V8_EXPORT PrefinalizerRegistration final {
0016 public:
0017 using Callback = bool (*)(const cppgc::LivenessBroker&, void*);
0018
0019 PrefinalizerRegistration(void*, Callback);
0020
0021 void* operator new(size_t, void* location) = delete;
0022 void* operator new(size_t) = delete;
0023 };
0024
0025 }
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 #define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer) \
0057 public: \
0058 static bool InvokePreFinalizer(const cppgc::LivenessBroker& liveness_broker, \
0059 void* object) { \
0060 static_assert(cppgc::IsGarbageCollectedOrMixinTypeV<Class>, \
0061 "Only garbage collected objects can have prefinalizers"); \
0062 Class* self = static_cast<Class*>(object); \
0063 if (liveness_broker.IsHeapObjectAlive(self)) return false; \
0064 self->PreFinalizer(); \
0065 return true; \
0066 } \
0067 \
0068 private: \
0069 CPPGC_NO_UNIQUE_ADDRESS cppgc::internal::PrefinalizerRegistration \
0070 prefinalizer_dummy_{this, Class::InvokePreFinalizer}; \
0071 static_assert(true, "Force semicolon.")
0072
0073 }
0074
0075 #endif