1 2 #ifndef SRC_NODE_UTIL_H_ 3 #define SRC_NODE_UTIL_H_ 4 5 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 6 #include "base_object.h" 7 #include "node_snapshotable.h" 8 #include "v8.h" 9 10 namespace node { 11 namespace util { 12 13 class WeakReference : public SnapshotableObject { 14 public: SERIALIZABLE_OBJECT_METHODS()15 SERIALIZABLE_OBJECT_METHODS() 16 17 static constexpr FastStringKey type_name{"node::util::WeakReference"}; 18 static constexpr EmbedderObjectType type_int = 19 EmbedderObjectType::k_util_weak_reference; 20 21 WeakReference(Realm* realm, 22 v8::Local<v8::Object> object, 23 v8::Local<v8::Object> target); 24 static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 25 static void Get(const v8::FunctionCallbackInfo<v8::Value>& args); 26 static void GetRef(const v8::FunctionCallbackInfo<v8::Value>& args); 27 static void IncRef(const v8::FunctionCallbackInfo<v8::Value>& args); 28 static void DecRef(const v8::FunctionCallbackInfo<v8::Value>& args); 29 30 SET_MEMORY_INFO_NAME(WeakReference) 31 SET_SELF_SIZE(WeakReference) 32 SET_NO_MEMORY_INFO() 33 34 struct InternalFieldInfo : public node::InternalFieldInfoBase { 35 SnapshotIndex target; 36 uint64_t reference_count; 37 }; 38 39 private: 40 WeakReference(Realm* realm, 41 v8::Local<v8::Object> object, 42 v8::Local<v8::Object> target, 43 uint64_t reference_count); 44 v8::Global<v8::Object> target_; 45 uint64_t reference_count_ = 0; 46 47 SnapshotIndex target_index_ = 0; // 0 means target_ is not snapshotted 48 }; 49 50 } // namespace util 51 } // namespace node 52 53 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 54 55 #endif // SRC_NODE_UTIL_H_ 56