v8 12.4.254 (node 22.4.1)
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 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_
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 bool HasCustomHostObject(Isolate *isolate)
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 Maybe< bool > IsHostObject(Isolate *isolate, Local< Object > object)
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:753
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:628