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