Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-snapshot.h
$ cat -n /usr/include/node/v8-snapshot.h 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 13 namespace v8 { 14 15 class Object; 16 17 namespace internal { 18 class SnapshotCreatorImpl; 19 } // namespace internal 20 21 class V8_EXPORT StartupData { 22 public: 23 /** 24 * Whether the data created can be rehashed and and the hash seed can be 25 * recomputed when deserialized. 26 * Only valid for StartupData returned by SnapshotCreator::CreateBlob(). 27 */ 28 bool CanBeRehashed() const; 29 /** 30 * Allows embedders to verify whether the data is valid for the current 31 * V8 instance. 32 */ 33 bool IsValid() const; 34 35 const char* data; 36 int raw_size; 37 }; 38 39 /** 40 * Callback and supporting data used in SnapshotCreator to implement embedder 41 * logic to serialize internal fields of v8::Objects. 42 * Internal fields that directly reference V8 objects are serialized without 43 * calling this callback. Internal fields that contain aligned pointers are 44 * serialized by this callback if it returns non-zero result. Otherwise it is 45 * serialized verbatim. 46 */ 47 struct SerializeInternalFieldsCallback { 48 using CallbackFunction = StartupData (*)(Local
holder, int index, 49 void* data); 50 SerializeInternalFieldsCallback(CallbackFunction function = nullptr, 51 void* data_arg = nullptr) 52 : callback(function), data(data_arg) {} 53 CallbackFunction callback; 54 void* data; 55 }; 56 57 /** 58 * Similar to SerializeInternalFieldsCallback, but works with the embedder data 59 * in a v8::Context. 60 */ 61 struct SerializeContextDataCallback { 62 using CallbackFunction = StartupData (*)(Local
holder, int index, 63 void* data); 64 SerializeContextDataCallback(CallbackFunction function = nullptr, 65 void* data_arg = nullptr) 66 : callback(function), data(data_arg) {} 67 CallbackFunction callback; 68 void* data; 69 }; 70 71 /** 72 * Callback and supporting data used to implement embedder logic to deserialize 73 * internal fields of v8::Objects. 74 */ 75 struct DeserializeInternalFieldsCallback { 76 using CallbackFunction = void (*)(Local
holder, int index, 77 StartupData payload, void* data); 78 DeserializeInternalFieldsCallback(CallbackFunction function = nullptr, 79 void* data_arg = nullptr) 80 : callback(function), data(data_arg) {} 81 82 CallbackFunction callback; 83 void* data; 84 }; 85 86 /** 87 * Similar to DeserializeInternalFieldsCallback, but works with the embedder 88 * data in a v8::Context. 89 */ 90 struct DeserializeContextDataCallback { 91 using CallbackFunction = void (*)(Local
holder, int index, 92 StartupData payload, void* data); 93 DeserializeContextDataCallback(CallbackFunction function = nullptr, 94 void* data_arg = nullptr) 95 : callback(function), data(data_arg) {} 96 CallbackFunction callback; 97 void* data; 98 }; 99 100 /** 101 * Helper class to create a snapshot data blob. 102 * 103 * The Isolate used by a SnapshotCreator is owned by it, and will be entered 104 * and exited by the constructor and destructor, respectively; The destructor 105 * will also destroy the Isolate. Experimental language features, including 106 * those available by default, are not available while creating a snapshot. 107 */ 108 class V8_EXPORT SnapshotCreator { 109 public: 110 enum class FunctionCodeHandling { kClear, kKeep }; 111 112 /** 113 * Initialize and enter an isolate, and set it up for serialization. 114 * The isolate is either created from scratch or from an existing snapshot. 115 * The caller keeps ownership of the argument snapshot. 116 * \param existing_blob existing snapshot from which to create this one. 117 * \param external_references a null-terminated array of external references 118 * that must be equivalent to CreateParams::external_references. 119 * \param owns_isolate whether this SnapshotCreator should call 120 * v8::Isolate::Dispose() during its destructor. 121 */ 122 V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.") 123 explicit SnapshotCreator(Isolate* isolate, 124 const intptr_t* external_references = nullptr, 125 const StartupData* existing_blob = nullptr, 126 bool owns_isolate = true); 127 128 /** 129 * Create and enter an isolate, and set it up for serialization. 130 * The isolate is either created from scratch or from an existing snapshot. 131 * The caller keeps ownership of the argument snapshot. 132 * \param existing_blob existing snapshot from which to create this one. 133 * \param external_references a null-terminated array of external references 134 * that must be equivalent to CreateParams::external_references. 135 */ 136 V8_DEPRECATE_SOON("Use the version that passes CreateParams instead.") 137 explicit SnapshotCreator(const intptr_t* external_references = nullptr, 138 const StartupData* existing_blob = nullptr); 139 140 /** 141 * Creates an Isolate for serialization and enters it. The creator fully owns 142 * the Isolate and will invoke `v8::Isolate::Dispose()` during destruction. 143 * 144 * \param params The parameters to initialize the Isolate for. Details: 145 * - `params.external_references` are expected to be a 146 * null-terminated array of external references. 147 * - `params.existing_blob` is an optional snapshot blob from 148 * which can be used to initialize the new blob. 149 */ 150 explicit SnapshotCreator(const v8::Isolate::CreateParams& params); 151 152 /** 153 * Initializes an Isolate for serialization and enters it. The creator does 154 * not own the Isolate but merely initialize it properly. 155 * 156 * \param isolate The isolate that was allocated by `Isolate::Allocate()~. 157 * \param params The parameters to initialize the Isolate for. Details: 158 * - `params.external_references` are expected to be a 159 * null-terminated array of external references. 160 * - `params.existing_blob` is an optional snapshot blob from 161 * which can be used to initialize the new blob. 162 */ 163 SnapshotCreator(v8::Isolate* isolate, 164 const v8::Isolate::CreateParams& params); 165 166 /** 167 * Destroy the snapshot creator, and exit and dispose of the Isolate 168 * associated with it. 169 */ 170 ~SnapshotCreator(); 171 172 /** 173 * \returns the isolate prepared by the snapshot creator. 174 */ 175 Isolate* GetIsolate(); 176 177 /** 178 * Set the default context to be included in the snapshot blob. 179 * The snapshot will not contain the global proxy, and we expect one or a 180 * global object template to create one, to be provided upon deserialization. 181 * 182 * \param internal_fields_serializer An optional callback used to serialize 183 * internal pointer fields set by 184 * v8::Object::SetAlignedPointerInInternalField(). 185 * 186 * \param context_data_serializer An optional callback used to serialize 187 * context embedder data set by 188 * v8::Context::SetAlignedPointerInEmbedderData(). 189 * 190 */ 191 void SetDefaultContext( 192 Local
context, 193 SerializeInternalFieldsCallback internal_fields_serializer = 194 SerializeInternalFieldsCallback(), 195 SerializeContextDataCallback context_data_serializer = 196 SerializeContextDataCallback()); 197 198 /** 199 * Add additional context to be included in the snapshot blob. 200 * The snapshot will include the global proxy. 201 * 202 * \param internal_fields_serializer Similar to internal_fields_serializer 203 * in SetDefaultContext() but only applies to the context being added. 204 * 205 * \param context_data_serializer Similar to context_data_serializer 206 * in SetDefaultContext() but only applies to the context being added. 207 */ 208 size_t AddContext(Local
context, 209 SerializeInternalFieldsCallback internal_fields_serializer = 210 SerializeInternalFieldsCallback(), 211 SerializeContextDataCallback context_data_serializer = 212 SerializeContextDataCallback()); 213 214 /** 215 * Attach arbitrary V8::Data to the context snapshot, which can be retrieved 216 * via Context::GetDataFromSnapshotOnce after deserialization. This data does 217 * not survive when a new snapshot is created from an existing snapshot. 218 * \returns the index for retrieval. 219 */ 220 template
221 V8_INLINE size_t AddData(Local
context, Local
object); 222 223 /** 224 * Attach arbitrary V8::Data to the isolate snapshot, which can be retrieved 225 * via Isolate::GetDataFromSnapshotOnce after deserialization. This data does 226 * not survive when a new snapshot is created from an existing snapshot. 227 * \returns the index for retrieval. 228 */ 229 template
230 V8_INLINE size_t AddData(Local
object); 231 232 /** 233 * Created a snapshot data blob. 234 * This must not be called from within a handle scope. 235 * \param function_code_handling whether to include compiled function code 236 * in the snapshot. 237 * \returns { nullptr, 0 } on failure, and a startup snapshot on success. The 238 * caller acquires ownership of the data array in the return value. 239 */ 240 StartupData CreateBlob(FunctionCodeHandling function_code_handling); 241 242 // Disallow copying and assigning. 243 SnapshotCreator(const SnapshotCreator&) = delete; 244 void operator=(const SnapshotCreator&) = delete; 245 246 private: 247 size_t AddData(Local
context, internal::Address object); 248 size_t AddData(internal::Address object); 249 250 internal::SnapshotCreatorImpl* impl_; 251 friend class internal::SnapshotCreatorImpl; 252 }; 253 254 template
255 size_t SnapshotCreator::AddData(Local
context, Local
object) { 256 return AddData(context, internal::ValueHelper::ValueAsAddress(*object)); 257 } 258 259 template
260 size_t SnapshotCreator::AddData(Local
object) { 261 return AddData(internal::ValueHelper::ValueAsAddress(*object)); 262 } 263 264 } // namespace v8 265 266 #endif // INCLUDE_V8_SNAPSHOT_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™