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 virtual bool HasCustomHostObject(Isolate* isolate);
85
90 virtual Maybe<bool> IsHostObject(Isolate* isolate, Local<Object> object);
91
98
110 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
111
113 Isolate* isolate, Local<WasmModuleObject> module);
114
128 virtual bool AdoptSharedValueConveyor(Isolate* isolate,
129 SharedValueConveyor&& conveyor);
130
142 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
143 size_t* actual_size);
144
150 virtual void FreeBufferMemory(void* buffer);
151 };
152
153 explicit ValueSerializer(Isolate* isolate);
154 ValueSerializer(Isolate* isolate, Delegate* delegate);
156
161
166 Local<Value> value);
167
174 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
175
181 void TransferArrayBuffer(uint32_t transfer_id,
182 Local<ArrayBuffer> array_buffer);
183
192
198 void WriteUint32(uint32_t value);
199 void WriteUint64(uint64_t value);
200 void WriteDouble(double value);
201 void WriteRawBytes(const void* source, size_t length);
202
204 void operator=(const ValueSerializer&) = delete;
205
206 private:
207 struct PrivateData;
208 PrivateData* private_;
209};
210
216 public:
218 public:
219 virtual ~Delegate() = default;
220
227
233 Isolate* isolate, uint32_t transfer_id);
234
240 Isolate* isolate, uint32_t clone_id);
241
247 };
248
249 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
250 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
251 Delegate* delegate);
253
259
264
269 void TransferArrayBuffer(uint32_t transfer_id,
270 Local<ArrayBuffer> array_buffer);
271
278 Local<SharedArrayBuffer> shared_array_buffer);
279
287 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
288
294 uint32_t GetWireFormatVersion() const;
295
301 V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
302 V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
304 V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
305
307 void operator=(const ValueDeserializer&) = delete;
308
309 private:
310 struct PrivateData;
311 PrivateData* private_;
312};
313
314} // namespace v8
315
316#endif // INCLUDE_V8_VALUE_SERIALIZER_H_
Definition: v8-isolate.h:261
Definition: v8-local-handle.h:266
Definition: v8-local-handle.h:632
Definition: v8-maybe.h:32
Definition: v8-value-serializer.h:45
SharedValueConveyor(SharedValueConveyor &&) noexcept
Definition: v8-value-serializer.h:217
virtual const SharedValueConveyor * GetSharedValueConveyor(Isolate *isolate)
virtual MaybeLocal< Object > ReadHostObject(Isolate *isolate)
virtual MaybeLocal< SharedArrayBuffer > GetSharedArrayBufferFromId(Isolate *isolate, uint32_t clone_id)
virtual MaybeLocal< WasmModuleObject > GetWasmModuleFromId(Isolate *isolate, uint32_t transfer_id)
Definition: v8-value-serializer.h:215
bool ReadUint64(uint64_t *value)
void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format)
ValueDeserializer(Isolate *isolate, const uint8_t *data, size_t size, Delegate *delegate)
void TransferSharedArrayBuffer(uint32_t id, Local< SharedArrayBuffer > shared_array_buffer)
bool ReadDouble(double *value)
ValueDeserializer(const ValueDeserializer &)=delete
bool ReadUint32(uint32_t *value)
void operator=(const ValueDeserializer &)=delete
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
ValueDeserializer(Isolate *isolate, const uint8_t *data, size_t size)
Maybe< bool > ReadHeader(Local< Context > context)
MaybeLocal< Value > ReadValue(Local< Context > context)
uint32_t GetWireFormatVersion() const
bool ReadRawBytes(size_t length, const void **data)
Definition: v8-value-serializer.h:67
virtual void * ReallocateBufferMemory(void *old_buffer, size_t size, size_t *actual_size)
virtual Maybe< uint32_t > GetSharedArrayBufferId(Isolate *isolate, Local< SharedArrayBuffer > shared_array_buffer)
virtual Maybe< uint32_t > GetWasmModuleTransferId(Isolate *isolate, Local< WasmModuleObject > module)
virtual void ThrowDataCloneError(Local< String > message)=0
virtual ~Delegate()=default
virtual bool HasCustomHostObject(Isolate *isolate)
virtual void FreeBufferMemory(void *buffer)
virtual Maybe< bool > IsHostObject(Isolate *isolate, Local< Object > object)
virtual bool AdoptSharedValueConveyor(Isolate *isolate, SharedValueConveyor &&conveyor)
virtual Maybe< bool > WriteHostObject(Isolate *isolate, Local< Object > object)
Definition: v8-value-serializer.h:65
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
void WriteUint64(uint64_t value)
void WriteDouble(double value)
ValueSerializer(Isolate *isolate)
std::pair< uint8_t *, size_t > Release()
ValueSerializer(Isolate *isolate, Delegate *delegate)
ValueSerializer(const ValueSerializer &)=delete
void operator=(const ValueSerializer &)=delete
void WriteUint32(uint32_t value)
Maybe< bool > WriteValue(Local< Context > context, Local< Value > value)
void WriteRawBytes(const void *source, size_t length)
void SetTreatArrayBufferViewsAsHostObjects(bool mode)
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:793
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:660