|
4 | 4 |
|
5 | 5 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
6 | 6 |
|
7 |
| -#include <cassert> // For static_assert |
8 |
| -#include <cstddef> // For offsetof |
9 | 7 | #include "aliased_buffer.h"
|
10 | 8 | #include "base_object.h"
|
11 | 9 | #include "util.h"
|
@@ -35,13 +33,13 @@ bool WithoutCodeCache(const SnapshotConfig& config);
|
35 | 33 | // and pass it into the V8 callback as the payload of StartupData.
|
36 | 34 | // The memory chunk looks like this:
|
37 | 35 | //
|
38 |
| -// [ type ] - EmbedderObjectType (a uint64_t) |
39 |
| -// [ length ] - a uint64_t |
| 36 | +// [ type ] - EmbedderObjectType (a uint8_t) |
| 37 | +// [ length ] - a size_t |
40 | 38 | // [ ... ] - custom bytes of size |length - header size|
|
41 | 39 | struct InternalFieldInfoBase {
|
42 | 40 | public:
|
43 | 41 | EmbedderObjectType type;
|
44 |
| - uint64_t length; |
| 42 | + size_t length; |
45 | 43 |
|
46 | 44 | template <typename T>
|
47 | 45 | static T* New(EmbedderObjectType type) {
|
@@ -73,35 +71,14 @@ struct InternalFieldInfoBase {
|
73 | 71 | InternalFieldInfoBase() = default;
|
74 | 72 | };
|
75 | 73 |
|
76 |
| -// Make sure that there's no padding in the struct since we will memcpy |
77 |
| -// them into the snapshot blob and they need to be reproducible. |
78 |
| -static_assert(offsetof(InternalFieldInfoBase, type) == 0, |
79 |
| - "InternalFieldInfoBase::type should start from offset 0"); |
80 |
| -static_assert(offsetof(InternalFieldInfoBase, length) == |
81 |
| - sizeof(EmbedderObjectType), |
82 |
| - "InternalFieldInfoBase::type should have no padding"); |
83 |
| - |
84 | 74 | struct EmbedderTypeInfo {
|
85 |
| - // To avoid padding, the enum is uint64_t. |
86 |
| - enum class MemoryMode : uint64_t { kBaseObject = 0, kCppGC }; |
| 75 | + enum class MemoryMode : uint8_t { kBaseObject, kCppGC }; |
87 | 76 | EmbedderTypeInfo(EmbedderObjectType t, MemoryMode m) : type(t), mode(m) {}
|
88 | 77 | EmbedderTypeInfo() = default;
|
89 |
| - |
90 | 78 | EmbedderObjectType type;
|
91 | 79 | MemoryMode mode;
|
92 | 80 | };
|
93 | 81 |
|
94 |
| -// Make sure that there's no padding in the struct since we will memcpy |
95 |
| -// them into the snapshot blob and they need to be reproducible. |
96 |
| -static_assert(offsetof(EmbedderTypeInfo, type) == 0, |
97 |
| - "EmbedderTypeInfo::type should start from offset 0"); |
98 |
| -static_assert(offsetof(EmbedderTypeInfo, mode) == sizeof(EmbedderObjectType), |
99 |
| - "EmbedderTypeInfo::type should have no padding"); |
100 |
| -static_assert(sizeof(EmbedderTypeInfo) == |
101 |
| - sizeof(EmbedderObjectType) + |
102 |
| - sizeof(EmbedderTypeInfo::MemoryMode), |
103 |
| - "EmbedderTypeInfo::mode should have no padding"); |
104 |
| - |
105 | 82 | // An interface for snapshotable native objects to inherit from.
|
106 | 83 | // Use the SERIALIZABLE_OBJECT_METHODS() macro in the class to define
|
107 | 84 | // the following methods to implement:
|
@@ -173,12 +150,6 @@ class BindingData : public SnapshotableObject {
|
173 | 150 | AliasedBufferIndex is_building_snapshot_buffer;
|
174 | 151 | };
|
175 | 152 |
|
176 |
| - // Make sure that there's no padding in the struct since we will memcpy |
177 |
| - // them into the snapshot blob and they need to be reproducible. |
178 |
| - static_assert(sizeof(InternalFieldInfo) == |
179 |
| - sizeof(InternalFieldInfoBase) + sizeof(AliasedBufferIndex), |
180 |
| - "InternalFieldInfo should have no padding"); |
181 |
| - |
182 | 153 | BindingData(Realm* realm,
|
183 | 154 | v8::Local<v8::Object> obj,
|
184 | 155 | InternalFieldInfo* info = nullptr);
|
|
0 commit comments