24
24
#include " env-inl.h"
25
25
#include " memory_tracker-inl.h"
26
26
#include " node.h"
27
+ #include " node_external_reference.h"
27
28
#include " util-inl.h"
28
29
#include " v8.h"
29
30
@@ -32,6 +33,7 @@ namespace v8_utils {
32
33
using v8::Array;
33
34
using v8::Context;
34
35
using v8::FunctionCallbackInfo;
36
+ using v8::HandleScope;
35
37
using v8::HeapCodeStatistics;
36
38
using v8::HeapSpaceStatistics;
37
39
using v8::HeapStatistics;
@@ -45,6 +47,7 @@ using v8::Uint32;
45
47
using v8::V8;
46
48
using v8::Value;
47
49
50
+
48
51
#define HEAP_STATISTICS_PROPERTIES (V ) \
49
52
V (0 , total_heap_size, kTotalHeapSizeIndex ) \
50
53
V (1 , total_heap_size_executable, kTotalHeapSizeExecutableIndex ) \
@@ -85,7 +88,7 @@ static const size_t kHeapCodeStatisticsPropertiesCount =
85
88
#undef V
86
89
87
90
BindingData::BindingData (Environment* env, Local<Object> obj)
88
- : BaseObject (env, obj),
91
+ : SnapshotableObject (env, obj, type_int ),
89
92
heap_statistics_buffer (env->isolate (), kHeapStatisticsPropertiesCount),
90
93
heap_space_statistics_buffer(env->isolate (),
91
94
kHeapSpaceStatisticsPropertiesCount),
@@ -105,6 +108,32 @@ BindingData::BindingData(Environment* env, Local<Object> obj)
105
108
.Check ();
106
109
}
107
110
111
+ void BindingData::PrepareForSerialization (Local<Context> context,
112
+ v8::SnapshotCreator* creator) {
113
+ // We'll just re-initialize the buffers in the constructor since their
114
+ // contents can be thrown away once consumed in the previous call.
115
+ heap_statistics_buffer.Release ();
116
+ heap_space_statistics_buffer.Release ();
117
+ heap_code_statistics_buffer.Release ();
118
+ }
119
+
120
+ void BindingData::Deserialize (Local<Context> context,
121
+ Local<Object> holder,
122
+ int index,
123
+ InternalFieldInfo* info) {
124
+ DCHECK_EQ (index , BaseObject::kSlot );
125
+ HandleScope scope (context->GetIsolate ());
126
+ Environment* env = Environment::GetCurrent (context);
127
+ BindingData* binding = env->AddBindingData <BindingData>(context, holder);
128
+ CHECK_NOT_NULL (binding);
129
+ }
130
+
131
+ InternalFieldInfo* BindingData::Serialize (int index) {
132
+ DCHECK_EQ (index , BaseObject::kSlot );
133
+ InternalFieldInfo* info = InternalFieldInfo::New (type ());
134
+ return info;
135
+ }
136
+
108
137
void BindingData::MemoryInfo (MemoryTracker* tracker) const {
109
138
tracker->TrackField (" heap_statistics_buffer" , heap_statistics_buffer);
110
139
tracker->TrackField (" heap_space_statistics_buffer" ,
@@ -168,7 +197,6 @@ void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
168
197
V8::SetFlagsFromString (*flags, static_cast <size_t >(flags.length ()));
169
198
}
170
199
171
-
172
200
void Initialize (Local<Object> target,
173
201
Local<Value> unused,
174
202
Local<Context> context,
@@ -223,7 +251,16 @@ void Initialize(Local<Object> target,
223
251
env->SetMethod (target, " setFlagsFromString" , SetFlagsFromString);
224
252
}
225
253
254
+ void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
255
+ registry->Register (CachedDataVersionTag);
256
+ registry->Register (UpdateHeapStatisticsBuffer);
257
+ registry->Register (UpdateHeapCodeStatisticsBuffer);
258
+ registry->Register (UpdateHeapSpaceStatisticsBuffer);
259
+ registry->Register (SetFlagsFromString);
260
+ }
261
+
226
262
} // namespace v8_utils
227
263
} // namespace node
228
264
229
265
NODE_MODULE_CONTEXT_AWARE_INTERNAL (v8, node::v8_utils::Initialize)
266
+ NODE_MODULE_EXTERNAL_REFERENCE(v8, node::v8_utils::RegisterExternalReferences)
0 commit comments