v8 10.2.154 (node 18.16.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 <utility>
12
13#include "v8-local-handle.h" // NOLINT(build/include_directory)
14#include "v8-maybe.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17namespace v8 {
18
19class ArrayBuffer;
20class Isolate;
21class Object;
22class SharedArrayBuffer;
23class String;
24class WasmModuleObject;
25class Value;
26
27namespace internal {
28struct ScriptStreamingData;
29} // namespace internal
30
36 public:
38 public:
39 virtual ~Delegate() = default;
40
46 virtual void ThrowDataCloneError(Local<String> message) = 0;
47
54
66 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
67
69 Isolate* isolate, Local<WasmModuleObject> module);
70
75 virtual bool SupportsSharedValues() const;
76
85 Local<Value> shared_value);
86
98 virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
99 size_t* actual_size);
100
106 virtual void FreeBufferMemory(void* buffer);
107 };
108
109 explicit ValueSerializer(Isolate* isolate);
110 ValueSerializer(Isolate* isolate, Delegate* delegate);
112
117
122 Local<Value> value);
123
130 V8_WARN_UNUSED_RESULT std::pair<uint8_t*, size_t> Release();
131
137 void TransferArrayBuffer(uint32_t transfer_id,
138 Local<ArrayBuffer> array_buffer);
139
148
154 void WriteUint32(uint32_t value);
155 void WriteUint64(uint64_t value);
156 void WriteDouble(double value);
157 void WriteRawBytes(const void* source, size_t length);
158
160 void operator=(const ValueSerializer&) = delete;
161
162 private:
163 struct PrivateData;
164 PrivateData* private_;
165};
166
172 public:
174 public:
175 virtual ~Delegate() = default;
176
183
189 Isolate* isolate, uint32_t transfer_id);
190
196 Isolate* isolate, uint32_t clone_id);
197
202 virtual bool SupportsSharedValues() const;
203
209 uint32_t shared_value_id);
210 };
211
212 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
213 ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
214 Delegate* delegate);
216
222
227
232 void TransferArrayBuffer(uint32_t transfer_id,
233 Local<ArrayBuffer> array_buffer);
234
241 Local<SharedArrayBuffer> shared_array_buffer);
242
250 void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
251
257 uint32_t GetWireFormatVersion() const;
258
264 V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
265 V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
267 V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
268
270 void operator=(const ValueDeserializer&) = delete;
271
272 private:
273 struct PrivateData;
274 PrivateData* private_;
275};
276
277} // namespace v8
278
279#endif // INCLUDE_V8_VALUE_SERIALIZER_H_
virtual MaybeLocal< Value > GetSharedValueFromId(Isolate *isolate, uint32_t shared_value_id)
virtual bool SupportsSharedValues() const
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 bool SupportsSharedValues() const
virtual void ThrowDataCloneError(Local< String > message)=0
virtual Maybe< bool > WriteHostObject(Isolate *isolate, Local< Object > object)
virtual Maybe< uint32_t > GetWasmModuleTransferId(Isolate *isolate, Local< WasmModuleObject > module)
virtual Maybe< uint32_t > GetSharedValueId(Isolate *isolate, Local< Value > shared_value)
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:578
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:499