1 #ifndef SRC_BASE_OBJECT_TYPES_H_ 2 #define SRC_BASE_OBJECT_TYPES_H_ 3 4 #include <cinttypes> 5 6 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 7 8 namespace node { 9 // List of internalBinding() data wrappers. The first argument should match 10 // what the class passes to SET_BINDING_ID(), the second argument should match 11 // the C++ class name. 12 #define SERIALIZABLE_BINDING_TYPES(V) \ 13 V(encoding_binding_data, encoding_binding::BindingData) \ 14 V(fs_binding_data, fs::BindingData) \ 15 V(v8_binding_data, v8_utils::BindingData) \ 16 V(blob_binding_data, BlobBindingData) \ 17 V(process_binding_data, process::BindingData) \ 18 V(timers_binding_data, timers::BindingData) \ 19 V(url_binding_data, url::BindingData) 20 21 #define UNSERIALIZABLE_BINDING_TYPES(V) \ 22 V(http2_binding_data, http2::BindingData) \ 23 V(http_parser_binding_data, http_parser::BindingData) \ 24 V(quic_binding_data, quic::BindingData) 25 26 // List of (non-binding) BaseObjects that are serializable in the snapshot. 27 // The first argument should match what the type passes to 28 // SET_OBJECT_ID(), the second argument should match the C++ class 29 // name. 30 #define SERIALIZABLE_NON_BINDING_TYPES(V) \ 31 V(util_weak_reference, util::WeakReference) 32 33 // Helper list of all binding data wrapper types. 34 #define BINDING_TYPES(V) \ 35 SERIALIZABLE_BINDING_TYPES(V) \ 36 UNSERIALIZABLE_BINDING_TYPES(V) 37 38 // Helper list of all BaseObjects that implement snapshot support. 39 #define SERIALIZABLE_OBJECT_TYPES(V) \ 40 SERIALIZABLE_BINDING_TYPES(V) \ 41 SERIALIZABLE_NON_BINDING_TYPES(V) 42 43 #define V(TypeId, NativeType) k_##TypeId, 44 enum class BindingDataType : uint8_t { BINDING_TYPES(V) kBindingDataTypeCount }; 45 // Make sure that we put the bindings first so that we can also use the enums 46 // for the bindings as index to the binding data store. 47 enum class EmbedderObjectType : uint8_t { 48 BINDING_TYPES(V) SERIALIZABLE_NON_BINDING_TYPES(V) 49 // We do not need to know about all the unserializable non-binding types for 50 // now so we do not list them. 51 kEmbedderObjectTypeCount 52 }; 53 #undef V 54 55 // For now, BaseObjects only need to call this when they implement snapshot 56 // support. 57 #define SET_OBJECT_ID(TypeId) \ 58 static constexpr EmbedderObjectType type_int = EmbedderObjectType::k_##TypeId; 59 60 // Binding data should call this so that they can be looked up from the binding 61 // data store. 62 #define SET_BINDING_ID(TypeId) \ 63 static constexpr BindingDataType binding_type_int = \ 64 BindingDataType::k_##TypeId; \ 65 SET_OBJECT_ID(TypeId) \ 66 static_assert(static_cast<uint8_t>(type_int) == \ 67 static_cast<uint8_t>(binding_type_int)); 68 69 } // namespace node 70 71 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 72 73 #endif // SRC_BASE_OBJECT_TYPES_H_ 74