Loading...
Searching...
No Matches
v8-snapshot.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_SNAPSHOT_H_
6#define INCLUDE_V8_SNAPSHOT_H_
7
8#include "v8-internal.h" // NOLINT(build/include_directory)
9#include "v8-isolate.h" // NOLINT(build/include_directory)
10#include "v8-local-handle.h" // NOLINT(build/include_directory)
11#include "v8config.h" // NOLINT(build/include_directory)
12
13namespace v8 {
14
15class Object;
16
17namespace internal {
18class SnapshotCreatorImpl;
19} // namespace internal
20
22 public:
28 bool CanBeRehashed() const;
33 bool IsValid() const;
34
35 const char* data;
37};
38
48 using CallbackFunction = StartupData (*)(Local<Object> holder, int index,
49 void* data);
51 void* data_arg = nullptr)
52 : callback(function), data(data_arg) {}
54 void* data;
55};
56
62 using CallbackFunction = StartupData (*)(Local<Context> holder, int index,
63 void* data);
65 void* data_arg = nullptr)
66 : callback(function), data(data_arg) {}
68 void* data;
69};
70
78 void* cpp_heap_pointer, void* data);
79 explicit SerializeAPIWrapperCallback(CallbackFunction function = nullptr,
80 void* data = nullptr)
81 : callback(function), data(data) {}
82
84 void* data;
85};
86
92 using CallbackFunction = void (*)(Local<Object> holder, int index,
93 StartupData payload, void* data);
95 void* data_arg = nullptr)
96 : callback(function), data(data_arg) {}
97
99 void* data;
100};
101
107 using CallbackFunction = void (*)(Local<Context> holder, int index,
108 StartupData payload, void* data);
110 void* data_arg = nullptr)
111 : callback(function), data(data_arg) {}
113 void* data;
114};
115
117 using CallbackFunction = void (*)(Local<Object> holder, StartupData payload,
118 void* data);
120 void* data = nullptr)
121 : callback(function), data(data) {}
122
124 void* data;
125};
126
136 public:
137 enum class FunctionCodeHandling { kClear, kKeep };
138
149 V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.")
150 explicit SnapshotCreator(Isolate* isolate,
151 const intptr_t* external_references = nullptr,
152 const StartupData* existing_blob = nullptr,
153 bool owns_isolate = true);
154
163 V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.")
164 explicit SnapshotCreator(const intptr_t* external_references = nullptr,
165 const StartupData* existing_blob = nullptr);
166
177 explicit SnapshotCreator(const v8::Isolate::CreateParams& params);
178
191 const v8::Isolate::CreateParams& params);
192
198
202 Isolate* GetIsolate();
203
220 void SetDefaultContext(
221 Local<Context> context,
222 SerializeInternalFieldsCallback internal_fields_serializer =
224 SerializeContextDataCallback context_data_serializer =
226 SerializeAPIWrapperCallback api_wrapper_serializer =
228
242 size_t AddContext(Local<Context> context,
243 SerializeInternalFieldsCallback internal_fields_serializer =
245 SerializeContextDataCallback context_data_serializer =
247 SerializeAPIWrapperCallback api_wrapper_serializer =
249
256 template <class T>
257 V8_INLINE size_t AddData(Local<Context> context, Local<T> object);
258
265 template <class T>
266 V8_INLINE size_t AddData(Local<T> object);
267
276 StartupData CreateBlob(FunctionCodeHandling function_code_handling);
277
278 // Disallow copying and assigning.
280 void operator=(const SnapshotCreator&) = delete;
281
282 private:
283 size_t AddData(Local<Context> context, internal::Address object);
284 size_t AddData(internal::Address object);
285
286 internal::SnapshotCreatorImpl* impl_;
287 friend class internal::SnapshotCreatorImpl;
288};
289
290template <class T>
291size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) {
292 return AddData(context, internal::ValueHelper::ValueAsAddress(*object));
293}
294
295template <class T>
296size_t SnapshotCreator::AddData(Local<T> object) {
297 return AddData(internal::ValueHelper::ValueAsAddress(*object));
298}
299
300} // namespace v8
301
302#endif // INCLUDE_V8_SNAPSHOT_H_
Definition: v8-context.h:48
Definition: v8-isolate.h:261
Definition: v8-local-handle.h:266
Definition: v8-snapshot.h:135
FunctionCodeHandling
Definition: v8-snapshot.h:137
Definition: v8-snapshot.h:21
bool CanBeRehashed() const
int raw_size
Definition: v8-snapshot.h:36
const char * data
Definition: v8-snapshot.h:35
bool IsValid() const
Definition: libplatform.h:15
Definition: v8-snapshot.h:116
CallbackFunction callback
Definition: v8-snapshot.h:123
void * data
Definition: v8-snapshot.h:124
void(*)(Local< Object > holder, StartupData payload, void *data) CallbackFunction
Definition: v8-snapshot.h:118
DeserializeAPIWrapperCallback(CallbackFunction function=nullptr, void *data=nullptr)
Definition: v8-snapshot.h:119
Definition: v8-snapshot.h:106
void(*)(Local< Context > holder, int index, StartupData payload, void *data) CallbackFunction
Definition: v8-snapshot.h:108
void * data
Definition: v8-snapshot.h:113
DeserializeContextDataCallback(CallbackFunction function=nullptr, void *data_arg=nullptr)
Definition: v8-snapshot.h:109
CallbackFunction callback
Definition: v8-snapshot.h:112
Definition: v8-snapshot.h:91
CallbackFunction callback
Definition: v8-snapshot.h:98
void * data
Definition: v8-snapshot.h:99
DeserializeInternalFieldsCallback(CallbackFunction function=nullptr, void *data_arg=nullptr)
Definition: v8-snapshot.h:94
void(*)(Local< Object > holder, int index, StartupData payload, void *data) CallbackFunction
Definition: v8-snapshot.h:93
Definition: v8-snapshot.h:76
SerializeAPIWrapperCallback(CallbackFunction function=nullptr, void *data=nullptr)
Definition: v8-snapshot.h:79
void * data
Definition: v8-snapshot.h:84
CallbackFunction callback
Definition: v8-snapshot.h:83
StartupData(*)(Local< Object > holder, void *cpp_heap_pointer, void *data) CallbackFunction
Definition: v8-snapshot.h:78
Definition: v8-snapshot.h:61
void * data
Definition: v8-snapshot.h:68
CallbackFunction callback
Definition: v8-snapshot.h:67
StartupData(*)(Local< Context > holder, int index, void *data) CallbackFunction
Definition: v8-snapshot.h:63
SerializeContextDataCallback(CallbackFunction function=nullptr, void *data_arg=nullptr)
Definition: v8-snapshot.h:64
Definition: v8-snapshot.h:47
void * data
Definition: v8-snapshot.h:54
SerializeInternalFieldsCallback(CallbackFunction function=nullptr, void *data_arg=nullptr)
Definition: v8-snapshot.h:50
CallbackFunction callback
Definition: v8-snapshot.h:53
StartupData(*)(Local< Object > holder, int index, void *data) CallbackFunction
Definition: v8-snapshot.h:49
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:603