v8 11.3.244 (node 20.3.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-value-serializer.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_VALUE_SERIALIZER_H_
6#define INCLUDE_V8_VALUE_SERIALIZER_H_
7
8#include <stddef.h>
9#include <stdint.h>
10
11#include <memory>
12#include <utility>
13
14#include "v8-local-handle.h" // NOLINT(build/include_directory)
15#include "v8-maybe.h" // NOLINT(build/include_directory)
16#include "v8config.h" // NOLINT(build/include_directory)
17
18namespace v8 {
19
20class ArrayBuffer;
21class Isolate;
22class Object;
23class SharedArrayBuffer;
24class String;
25class WasmModuleObject;
26class Value;
27
28namespace internal {
29struct ScriptStreamingData;
30class SharedObjectConveyorHandles;
31class ValueDeserializer;
32class ValueSerializer;
33} // namespace internal
34
46 public:
49
51
52 private:
53 friend class internal::ValueSerializer;
54 friend class internal::ValueDeserializer;
55
56 explicit SharedValueConveyor(Isolate* isolate);
57
58 std::unique_ptr<internal::SharedObjectConveyorHandles> private_;
59};
60
66 public:
68 public:
69 virtual ~Delegate() = default;
70
76 virtual void ThrowDataCloneError(Local<String> message) = 0;
77
84
96 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
97
99 Isolate* isolate, Local<WasmModuleObject> module);
100
114 virtual bool AdoptSharedValueConveyor(Isolate* isolate,
115 SharedValueConveyor&& conveyor);
116
128 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
129 size_t* actual_size);
130
136 virtual void FreeBufferMemory(void* buffer);
137 };
138
139 explicit ValueSerializer(Isolate* isolate);
140 ValueSerializer(Isolate* isolate, Delegate* delegate);
142
147
152 Local<Value> value);
153
160 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
161
167 void TransferArrayBuffer(uint32_t transfer_id,
168 Local<ArrayBuffer> array_buffer);
169
178
184 void WriteUint32(uint32_t value);
185 void WriteUint64(uint64_t value);
186 void WriteDouble(double value);
187 void WriteRawBytes(const void* source, size_t length);
188
190 void operator=(const ValueSerializer&) = delete;
191
192 private:
193 struct PrivateData;
194 PrivateData* private_;
195};
196
202 public:
204 public:
205 virtual ~Delegate() = default;
206
213
219 Isolate* isolate, uint32_t transfer_id);
220
226 Isolate* isolate, uint32_t clone_id);
227
233 };
234
235 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
236 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
237 Delegate* delegate);
239
245
250
255 void TransferArrayBuffer(uint32_t transfer_id,
256 Local<ArrayBuffer> array_buffer);
257
264 Local<SharedArrayBuffer> shared_array_buffer);
265
273 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
274
280 uint32_t GetWireFormatVersion() const;
281
287 V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
288 V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
290 V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
291
293 void operator=(const ValueDeserializer&) = delete;
294
295 private:
296 struct PrivateData;
297 PrivateData* private_;
298};
299
300} // namespace v8
301
302#endif // INCLUDE_V8_VALUE_SERIALIZER_H_
SharedValueConveyor(SharedValueConveyor &&) noexcept
virtual const SharedValueConveyor * GetSharedValueConveyor(Isolate *isolate)
virtual MaybeLocal< Object > ReadHostObject(Isolate *isolate)
virtual MaybeLocal< WasmModuleObject > GetWasmModuleFromId(Isolate *isolate, uint32_t transfer_id)
virtual MaybeLocal< SharedArrayBuffer > GetSharedArrayBufferFromId(Isolate *isolate, uint32_t clone_id)
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t *value)
void TransferSharedArrayBuffer(uint32_t id, Local< SharedArrayBuffer > shared_array_buffer)
ValueDeserializer(const ValueDeserializer &)=delete
V8_WARN_UNUSED_RESULT Maybe< bool > ReadHeader(Local< Context > context)
V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void **data)
ValueDeserializer(Isolate *isolate, const uint8_t *data, size_t size, Delegate *delegate)
uint32_t GetWireFormatVersion() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > ReadValue(Local< Context > context)
V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t *value)
void operator=(const ValueDeserializer &)=delete
ValueDeserializer(Isolate *isolate, const uint8_t *data, size_t size)
V8_WARN_UNUSED_RESULT bool ReadDouble(double *value)
void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format)
virtual void ThrowDataCloneError(Local< String > message)=0
virtual Maybe< bool > WriteHostObject(Isolate *isolate, Local< Object > object)
virtual bool AdoptSharedValueConveyor(Isolate *isolate, SharedValueConveyor &&conveyor)
virtual Maybe< uint32_t > GetWasmModuleTransferId(Isolate *isolate, Local< WasmModuleObject > module)
virtual Maybe< uint32_t > GetSharedArrayBufferId(Isolate *isolate, Local< SharedArrayBuffer > shared_array_buffer)
virtual void FreeBufferMemory(void *buffer)
virtual ~Delegate()=default
virtual void * ReallocateBufferMemory(void *old_buffer, size_t size, size_t *actual_size)
ValueSerializer(Isolate *isolate)
V8_WARN_UNUSED_RESULT std::pair< uint8_t *, size_t > Release()
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
void SetTreatArrayBufferViewsAsHostObjects(bool mode)
V8_WARN_UNUSED_RESULT Maybe< bool > WriteValue(Local< Context > context, Local< Value > value)
ValueSerializer(const ValueSerializer &)=delete
ValueSerializer(Isolate *isolate, Delegate *delegate)
void WriteDouble(double value)
void WriteUint32(uint32_t value)
void operator=(const ValueSerializer &)=delete
void WriteUint64(uint64_t value)
void WriteRawBytes(const void *source, size_t length)
#define V8_EXPORT
Definition v8config.h:719
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:609