• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
15   SERIALIZABLE_OBJECT_METHODS()
16 
17   SET_OBJECT_ID(util_weak_reference)
18 
19   WeakReference(Realm* realm,
20                 v8::Local<v8::Object> object,
21                 v8::Local<v8::Object> target);
22   static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
23   static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
24   static void IncRef(const v8::FunctionCallbackInfo<v8::Value>& args);
25   static void DecRef(const v8::FunctionCallbackInfo<v8::Value>& args);
26 
27   SET_MEMORY_INFO_NAME(WeakReference)
28   SET_SELF_SIZE(WeakReference)
29   SET_NO_MEMORY_INFO()
30 
31   struct InternalFieldInfo : public node::InternalFieldInfoBase {
32     SnapshotIndex target;
33     uint64_t reference_count;
34   };
35 
36  private:
37   WeakReference(Realm* realm,
38                 v8::Local<v8::Object> object,
39                 v8::Local<v8::Object> target,
40                 uint64_t reference_count);
41   v8::Global<v8::Object> target_;
42   uint64_t reference_count_ = 0;
43 
44   SnapshotIndex target_index_ = 0;  // 0 means target_ is not snapshotted
45 };
46 
47 }  // namespace util
48 }  // namespace node
49 
50 #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
51 
52 #endif  // SRC_NODE_UTIL_H_
53