11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_VALUE_SERIALIZER_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_VALUE_SERIALIZER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <cstdint>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "include/v8-value-serializer.h"
111cb0ef41Sopenharmony_ci#include "src/base/compiler-specific.h"
121cb0ef41Sopenharmony_ci#include "src/base/macros.h"
131cb0ef41Sopenharmony_ci#include "src/base/strings.h"
141cb0ef41Sopenharmony_ci#include "src/base/vector.h"
151cb0ef41Sopenharmony_ci#include "src/common/message-template.h"
161cb0ef41Sopenharmony_ci#include "src/handles/maybe-handles.h"
171cb0ef41Sopenharmony_ci#include "src/utils/identity-map.h"
181cb0ef41Sopenharmony_ci#include "src/zone/zone.h"
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cinamespace v8 {
211cb0ef41Sopenharmony_cinamespace internal {
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciclass BigInt;
241cb0ef41Sopenharmony_ciclass HeapNumber;
251cb0ef41Sopenharmony_ciclass Isolate;
261cb0ef41Sopenharmony_ciclass JSArrayBuffer;
271cb0ef41Sopenharmony_ciclass JSArrayBufferView;
281cb0ef41Sopenharmony_ciclass JSDate;
291cb0ef41Sopenharmony_ciclass JSMap;
301cb0ef41Sopenharmony_ciclass JSPrimitiveWrapper;
311cb0ef41Sopenharmony_ciclass JSRegExp;
321cb0ef41Sopenharmony_ciclass JSSet;
331cb0ef41Sopenharmony_ciclass JSSharedStruct;
341cb0ef41Sopenharmony_ciclass Object;
351cb0ef41Sopenharmony_ciclass Oddball;
361cb0ef41Sopenharmony_ciclass Smi;
371cb0ef41Sopenharmony_ciclass WasmMemoryObject;
381cb0ef41Sopenharmony_ciclass WasmModuleObject;
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cienum class SerializationTag : uint8_t;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci/**
431cb0ef41Sopenharmony_ci * Writes V8 objects in a binary format that allows the objects to be cloned
441cb0ef41Sopenharmony_ci * according to the HTML structured clone algorithm.
451cb0ef41Sopenharmony_ci *
461cb0ef41Sopenharmony_ci * Format is based on Blink's previous serialization logic.
471cb0ef41Sopenharmony_ci */
481cb0ef41Sopenharmony_ciclass ValueSerializer {
491cb0ef41Sopenharmony_ci public:
501cb0ef41Sopenharmony_ci  ValueSerializer(Isolate* isolate, v8::ValueSerializer::Delegate* delegate);
511cb0ef41Sopenharmony_ci  ~ValueSerializer();
521cb0ef41Sopenharmony_ci  ValueSerializer(const ValueSerializer&) = delete;
531cb0ef41Sopenharmony_ci  ValueSerializer& operator=(const ValueSerializer&) = delete;
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  /*
561cb0ef41Sopenharmony_ci   * Writes out a header, which includes the format version.
571cb0ef41Sopenharmony_ci   */
581cb0ef41Sopenharmony_ci  void WriteHeader();
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci  /*
611cb0ef41Sopenharmony_ci   * Serializes a V8 object into the buffer.
621cb0ef41Sopenharmony_ci   */
631cb0ef41Sopenharmony_ci  Maybe<bool> WriteObject(Handle<Object> object) V8_WARN_UNUSED_RESULT;
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  /*
661cb0ef41Sopenharmony_ci   * Returns the buffer, allocated via the delegate, and its size.
671cb0ef41Sopenharmony_ci   * Caller assumes ownership of the buffer.
681cb0ef41Sopenharmony_ci   */
691cb0ef41Sopenharmony_ci  std::pair<uint8_t*, size_t> Release();
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  /*
721cb0ef41Sopenharmony_ci   * Marks an ArrayBuffer as havings its contents transferred out of band.
731cb0ef41Sopenharmony_ci   * Pass the corresponding JSArrayBuffer in the deserializing context to
741cb0ef41Sopenharmony_ci   * ValueDeserializer::TransferArrayBuffer.
751cb0ef41Sopenharmony_ci   */
761cb0ef41Sopenharmony_ci  void TransferArrayBuffer(uint32_t transfer_id,
771cb0ef41Sopenharmony_ci                           Handle<JSArrayBuffer> array_buffer);
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  /*
801cb0ef41Sopenharmony_ci   * Publicly exposed wire format writing methods.
811cb0ef41Sopenharmony_ci   * These are intended for use within the delegate's WriteHostObject method.
821cb0ef41Sopenharmony_ci   */
831cb0ef41Sopenharmony_ci  void WriteUint32(uint32_t value);
841cb0ef41Sopenharmony_ci  void WriteUint64(uint64_t value);
851cb0ef41Sopenharmony_ci  void WriteRawBytes(const void* source, size_t length);
861cb0ef41Sopenharmony_ci  void WriteDouble(double value);
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci  /*
891cb0ef41Sopenharmony_ci   * Indicate whether to treat ArrayBufferView objects as host objects,
901cb0ef41Sopenharmony_ci   * i.e. pass them to Delegate::WriteHostObject. This should not be
911cb0ef41Sopenharmony_ci   * called when no Delegate was passed.
921cb0ef41Sopenharmony_ci   *
931cb0ef41Sopenharmony_ci   * The default is not to treat ArrayBufferViews as host objects.
941cb0ef41Sopenharmony_ci   */
951cb0ef41Sopenharmony_ci  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci private:
981cb0ef41Sopenharmony_ci  friend class WebSnapshotSerializer;
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  // Managing allocations of the internal buffer.
1011cb0ef41Sopenharmony_ci  Maybe<bool> ExpandBuffer(size_t required_capacity);
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci  // Writing the wire format.
1041cb0ef41Sopenharmony_ci  void WriteTag(SerializationTag tag);
1051cb0ef41Sopenharmony_ci  template <typename T>
1061cb0ef41Sopenharmony_ci  void WriteVarint(T value);
1071cb0ef41Sopenharmony_ci  template <typename T>
1081cb0ef41Sopenharmony_ci  void WriteZigZag(T value);
1091cb0ef41Sopenharmony_ci  void WriteOneByteString(base::Vector<const uint8_t> chars);
1101cb0ef41Sopenharmony_ci  void WriteTwoByteString(base::Vector<const base::uc16> chars);
1111cb0ef41Sopenharmony_ci  void WriteBigIntContents(BigInt bigint);
1121cb0ef41Sopenharmony_ci  Maybe<uint8_t*> ReserveRawBytes(size_t bytes);
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ci  // Writing V8 objects of various kinds.
1151cb0ef41Sopenharmony_ci  void WriteOddball(Oddball oddball);
1161cb0ef41Sopenharmony_ci  void WriteSmi(Smi smi);
1171cb0ef41Sopenharmony_ci  void WriteHeapNumber(HeapNumber number);
1181cb0ef41Sopenharmony_ci  void WriteBigInt(BigInt bigint);
1191cb0ef41Sopenharmony_ci  void WriteString(Handle<String> string);
1201cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSReceiver(Handle<JSReceiver> receiver)
1211cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1221cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSObject(Handle<JSObject> object) V8_WARN_UNUSED_RESULT;
1231cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSObjectSlow(Handle<JSObject> object) V8_WARN_UNUSED_RESULT;
1241cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSArray(Handle<JSArray> array) V8_WARN_UNUSED_RESULT;
1251cb0ef41Sopenharmony_ci  void WriteJSDate(JSDate date);
1261cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSPrimitiveWrapper(Handle<JSPrimitiveWrapper> value)
1271cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1281cb0ef41Sopenharmony_ci  void WriteJSRegExp(Handle<JSRegExp> regexp);
1291cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSMap(Handle<JSMap> map) V8_WARN_UNUSED_RESULT;
1301cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSSet(Handle<JSSet> map) V8_WARN_UNUSED_RESULT;
1311cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSArrayBuffer(Handle<JSArrayBuffer> array_buffer)
1321cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1331cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSArrayBufferView(JSArrayBufferView array_buffer);
1341cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSError(Handle<JSObject> error) V8_WARN_UNUSED_RESULT;
1351cb0ef41Sopenharmony_ci  Maybe<bool> WriteJSSharedStruct(Handle<JSSharedStruct> shared_struct)
1361cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1371cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
1381cb0ef41Sopenharmony_ci  Maybe<bool> WriteWasmModule(Handle<WasmModuleObject> object)
1391cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1401cb0ef41Sopenharmony_ci  Maybe<bool> WriteWasmMemory(Handle<WasmMemoryObject> object)
1411cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1421cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
1431cb0ef41Sopenharmony_ci  Maybe<bool> WriteSharedObject(Handle<HeapObject> object)
1441cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1451cb0ef41Sopenharmony_ci  Maybe<bool> WriteHostObject(Handle<JSObject> object) V8_WARN_UNUSED_RESULT;
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci  /*
1481cb0ef41Sopenharmony_ci   * Reads the specified keys from the object and writes key-value pairs to the
1491cb0ef41Sopenharmony_ci   * buffer. Returns the number of keys actually written, which may be smaller
1501cb0ef41Sopenharmony_ci   * if some keys are not own properties when accessed.
1511cb0ef41Sopenharmony_ci   */
1521cb0ef41Sopenharmony_ci  Maybe<uint32_t> WriteJSObjectPropertiesSlow(
1531cb0ef41Sopenharmony_ci      Handle<JSObject> object, Handle<FixedArray> keys) V8_WARN_UNUSED_RESULT;
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  /*
1561cb0ef41Sopenharmony_ci   * Asks the delegate to handle an error that occurred during data cloning, by
1571cb0ef41Sopenharmony_ci   * throwing an exception appropriate for the host.
1581cb0ef41Sopenharmony_ci   */
1591cb0ef41Sopenharmony_ci  V8_NOINLINE Maybe<bool> ThrowDataCloneError(MessageTemplate template_index)
1601cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1611cb0ef41Sopenharmony_ci  V8_NOINLINE Maybe<bool> ThrowDataCloneError(MessageTemplate template_index,
1621cb0ef41Sopenharmony_ci                                              Handle<Object> arg0)
1631cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  Maybe<bool> ThrowIfOutOfMemory();
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  Isolate* const isolate_;
1681cb0ef41Sopenharmony_ci  v8::ValueSerializer::Delegate* const delegate_;
1691cb0ef41Sopenharmony_ci  uint8_t* buffer_ = nullptr;
1701cb0ef41Sopenharmony_ci  size_t buffer_size_ = 0;
1711cb0ef41Sopenharmony_ci  size_t buffer_capacity_ = 0;
1721cb0ef41Sopenharmony_ci  const bool supports_shared_values_;
1731cb0ef41Sopenharmony_ci  bool treat_array_buffer_views_as_host_objects_ = false;
1741cb0ef41Sopenharmony_ci  bool out_of_memory_ = false;
1751cb0ef41Sopenharmony_ci  Zone zone_;
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci  // To avoid extra lookups in the identity map, ID+1 is actually stored in the
1781cb0ef41Sopenharmony_ci  // map (checking if the used identity is zero is the fast way of checking if
1791cb0ef41Sopenharmony_ci  // the entry is new).
1801cb0ef41Sopenharmony_ci  IdentityMap<uint32_t, ZoneAllocationPolicy> id_map_;
1811cb0ef41Sopenharmony_ci  uint32_t next_id_ = 0;
1821cb0ef41Sopenharmony_ci
1831cb0ef41Sopenharmony_ci  // A similar map, for transferred array buffers.
1841cb0ef41Sopenharmony_ci  IdentityMap<uint32_t, ZoneAllocationPolicy> array_buffer_transfer_map_;
1851cb0ef41Sopenharmony_ci};
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci/*
1881cb0ef41Sopenharmony_ci * Deserializes values from data written with ValueSerializer, or a compatible
1891cb0ef41Sopenharmony_ci * implementation.
1901cb0ef41Sopenharmony_ci */
1911cb0ef41Sopenharmony_ciclass ValueDeserializer {
1921cb0ef41Sopenharmony_ci public:
1931cb0ef41Sopenharmony_ci  ValueDeserializer(Isolate* isolate, base::Vector<const uint8_t> data,
1941cb0ef41Sopenharmony_ci                    v8::ValueDeserializer::Delegate* delegate);
1951cb0ef41Sopenharmony_ci  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
1961cb0ef41Sopenharmony_ci  ~ValueDeserializer();
1971cb0ef41Sopenharmony_ci  ValueDeserializer(const ValueDeserializer&) = delete;
1981cb0ef41Sopenharmony_ci  ValueDeserializer& operator=(const ValueDeserializer&) = delete;
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_ci  /*
2011cb0ef41Sopenharmony_ci   * Runs version detection logic, which may fail if the format is invalid.
2021cb0ef41Sopenharmony_ci   */
2031cb0ef41Sopenharmony_ci  Maybe<bool> ReadHeader() V8_WARN_UNUSED_RESULT;
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci  /*
2061cb0ef41Sopenharmony_ci   * Reads the underlying wire format version. Likely mostly to be useful to
2071cb0ef41Sopenharmony_ci   * legacy code reading old wire format versions. Must be called after
2081cb0ef41Sopenharmony_ci   * ReadHeader.
2091cb0ef41Sopenharmony_ci   */
2101cb0ef41Sopenharmony_ci  uint32_t GetWireFormatVersion() const { return version_; }
2111cb0ef41Sopenharmony_ci
2121cb0ef41Sopenharmony_ci  /*
2131cb0ef41Sopenharmony_ci   * Deserializes a V8 object from the buffer.
2141cb0ef41Sopenharmony_ci   */
2151cb0ef41Sopenharmony_ci  MaybeHandle<Object> ReadObjectWrapper() V8_WARN_UNUSED_RESULT;
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci  /*
2181cb0ef41Sopenharmony_ci   * Reads an object, consuming the entire buffer.
2191cb0ef41Sopenharmony_ci   *
2201cb0ef41Sopenharmony_ci   * This is required for the legacy "version 0" format, which did not allow
2211cb0ef41Sopenharmony_ci   * reference deduplication, and instead relied on a "stack" model for
2221cb0ef41Sopenharmony_ci   * deserializing, with the contents of objects and arrays provided first.
2231cb0ef41Sopenharmony_ci   */
2241cb0ef41Sopenharmony_ci  MaybeHandle<Object> ReadObjectUsingEntireBufferForLegacyFormat()
2251cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
2261cb0ef41Sopenharmony_ci
2271cb0ef41Sopenharmony_ci  /*
2281cb0ef41Sopenharmony_ci   * Accepts the array buffer corresponding to the one passed previously to
2291cb0ef41Sopenharmony_ci   * ValueSerializer::TransferArrayBuffer.
2301cb0ef41Sopenharmony_ci   */
2311cb0ef41Sopenharmony_ci  void TransferArrayBuffer(uint32_t transfer_id,
2321cb0ef41Sopenharmony_ci                           Handle<JSArrayBuffer> array_buffer);
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  /*
2351cb0ef41Sopenharmony_ci   * Publicly exposed wire format writing methods.
2361cb0ef41Sopenharmony_ci   * These are intended for use within the delegate's WriteHostObject method.
2371cb0ef41Sopenharmony_ci   */
2381cb0ef41Sopenharmony_ci  bool ReadUint32(uint32_t* value) V8_WARN_UNUSED_RESULT;
2391cb0ef41Sopenharmony_ci  bool ReadUint64(uint64_t* value) V8_WARN_UNUSED_RESULT;
2401cb0ef41Sopenharmony_ci  bool ReadDouble(double* value) V8_WARN_UNUSED_RESULT;
2411cb0ef41Sopenharmony_ci  bool ReadRawBytes(size_t length, const void** data) V8_WARN_UNUSED_RESULT;
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci private:
2441cb0ef41Sopenharmony_ci  friend class WebSnapshotDeserializer;
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci  // Reading the wire format.
2471cb0ef41Sopenharmony_ci  Maybe<SerializationTag> PeekTag() const V8_WARN_UNUSED_RESULT;
2481cb0ef41Sopenharmony_ci  void ConsumeTag(SerializationTag peeked_tag);
2491cb0ef41Sopenharmony_ci  Maybe<SerializationTag> ReadTag() V8_WARN_UNUSED_RESULT;
2501cb0ef41Sopenharmony_ci  template <typename T>
2511cb0ef41Sopenharmony_ci  V8_INLINE Maybe<T> ReadVarint() V8_WARN_UNUSED_RESULT;
2521cb0ef41Sopenharmony_ci  template <typename T>
2531cb0ef41Sopenharmony_ci  V8_NOINLINE Maybe<T> ReadVarintLoop() V8_WARN_UNUSED_RESULT;
2541cb0ef41Sopenharmony_ci  template <typename T>
2551cb0ef41Sopenharmony_ci  Maybe<T> ReadZigZag() V8_WARN_UNUSED_RESULT;
2561cb0ef41Sopenharmony_ci  Maybe<double> ReadDouble() V8_WARN_UNUSED_RESULT;
2571cb0ef41Sopenharmony_ci  Maybe<base::Vector<const uint8_t>> ReadRawBytes(size_t size)
2581cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
2591cb0ef41Sopenharmony_ci  MaybeHandle<Object> ReadObject() V8_WARN_UNUSED_RESULT;
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci  // Reads a string if it matches the one provided.
2621cb0ef41Sopenharmony_ci  // Returns true if this was the case. Otherwise, nothing is consumed.
2631cb0ef41Sopenharmony_ci  bool ReadExpectedString(Handle<String> expected) V8_WARN_UNUSED_RESULT;
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ci  // Like ReadObject, but skips logic for special cases in simulating the
2661cb0ef41Sopenharmony_ci  // "stack machine".
2671cb0ef41Sopenharmony_ci  MaybeHandle<Object> ReadObjectInternal() V8_WARN_UNUSED_RESULT;
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci  // Reads a string intended to be part of a more complicated object.
2701cb0ef41Sopenharmony_ci  // Before v12, these are UTF-8 strings. After, they can be any encoding
2711cb0ef41Sopenharmony_ci  // permissible for a string (with the relevant tag).
2721cb0ef41Sopenharmony_ci  MaybeHandle<String> ReadString() V8_WARN_UNUSED_RESULT;
2731cb0ef41Sopenharmony_ci
2741cb0ef41Sopenharmony_ci  // Reading V8 objects of specific kinds.
2751cb0ef41Sopenharmony_ci  // The tag is assumed to have already been read.
2761cb0ef41Sopenharmony_ci  MaybeHandle<BigInt> ReadBigInt() V8_WARN_UNUSED_RESULT;
2771cb0ef41Sopenharmony_ci  MaybeHandle<String> ReadUtf8String(
2781cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
2791cb0ef41Sopenharmony_ci  MaybeHandle<String> ReadOneByteString(
2801cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
2811cb0ef41Sopenharmony_ci  MaybeHandle<String> ReadTwoByteString(
2821cb0ef41Sopenharmony_ci      AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
2831cb0ef41Sopenharmony_ci  MaybeHandle<JSObject> ReadJSObject() V8_WARN_UNUSED_RESULT;
2841cb0ef41Sopenharmony_ci  MaybeHandle<JSArray> ReadSparseJSArray() V8_WARN_UNUSED_RESULT;
2851cb0ef41Sopenharmony_ci  MaybeHandle<JSArray> ReadDenseJSArray() V8_WARN_UNUSED_RESULT;
2861cb0ef41Sopenharmony_ci  MaybeHandle<JSDate> ReadJSDate() V8_WARN_UNUSED_RESULT;
2871cb0ef41Sopenharmony_ci  MaybeHandle<JSPrimitiveWrapper> ReadJSPrimitiveWrapper(SerializationTag tag)
2881cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
2891cb0ef41Sopenharmony_ci  MaybeHandle<JSRegExp> ReadJSRegExp() V8_WARN_UNUSED_RESULT;
2901cb0ef41Sopenharmony_ci  MaybeHandle<JSMap> ReadJSMap() V8_WARN_UNUSED_RESULT;
2911cb0ef41Sopenharmony_ci  MaybeHandle<JSSet> ReadJSSet() V8_WARN_UNUSED_RESULT;
2921cb0ef41Sopenharmony_ci  MaybeHandle<JSArrayBuffer> ReadJSArrayBuffer(bool is_shared)
2931cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
2941cb0ef41Sopenharmony_ci  MaybeHandle<JSArrayBuffer> ReadTransferredJSArrayBuffer()
2951cb0ef41Sopenharmony_ci      V8_WARN_UNUSED_RESULT;
2961cb0ef41Sopenharmony_ci  MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView(
2971cb0ef41Sopenharmony_ci      Handle<JSArrayBuffer> buffer) V8_WARN_UNUSED_RESULT;
2981cb0ef41Sopenharmony_ci  bool ValidateAndSetJSArrayBufferViewFlags(
2991cb0ef41Sopenharmony_ci      JSArrayBufferView view, JSArrayBuffer buffer,
3001cb0ef41Sopenharmony_ci      uint32_t serialized_flags) V8_WARN_UNUSED_RESULT;
3011cb0ef41Sopenharmony_ci  MaybeHandle<Object> ReadJSError() V8_WARN_UNUSED_RESULT;
3021cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY
3031cb0ef41Sopenharmony_ci  MaybeHandle<JSObject> ReadWasmModuleTransfer() V8_WARN_UNUSED_RESULT;
3041cb0ef41Sopenharmony_ci  MaybeHandle<WasmMemoryObject> ReadWasmMemory() V8_WARN_UNUSED_RESULT;
3051cb0ef41Sopenharmony_ci#endif  // V8_ENABLE_WEBASSEMBLY
3061cb0ef41Sopenharmony_ci  MaybeHandle<HeapObject> ReadSharedObject() V8_WARN_UNUSED_RESULT;
3071cb0ef41Sopenharmony_ci  MaybeHandle<JSObject> ReadHostObject() V8_WARN_UNUSED_RESULT;
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_ci  /*
3101cb0ef41Sopenharmony_ci   * Reads key-value pairs into the object until the specified end tag is
3111cb0ef41Sopenharmony_ci   * encountered. If successful, returns the number of properties read.
3121cb0ef41Sopenharmony_ci   */
3131cb0ef41Sopenharmony_ci  Maybe<uint32_t> ReadJSObjectProperties(Handle<JSObject> object,
3141cb0ef41Sopenharmony_ci                                         SerializationTag end_tag,
3151cb0ef41Sopenharmony_ci                                         bool can_use_transitions);
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci  // Manipulating the map from IDs to reified objects.
3181cb0ef41Sopenharmony_ci  bool HasObjectWithID(uint32_t id);
3191cb0ef41Sopenharmony_ci  MaybeHandle<JSReceiver> GetObjectWithID(uint32_t id);
3201cb0ef41Sopenharmony_ci  void AddObjectWithID(uint32_t id, Handle<JSReceiver> object);
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci  Isolate* const isolate_;
3231cb0ef41Sopenharmony_ci  v8::ValueDeserializer::Delegate* const delegate_;
3241cb0ef41Sopenharmony_ci  const uint8_t* position_;
3251cb0ef41Sopenharmony_ci  const uint8_t* const end_;
3261cb0ef41Sopenharmony_ci  const bool supports_shared_values_;
3271cb0ef41Sopenharmony_ci  uint32_t version_ = 0;
3281cb0ef41Sopenharmony_ci  uint32_t next_id_ = 0;
3291cb0ef41Sopenharmony_ci  bool version_13_broken_data_mode_ = false;
3301cb0ef41Sopenharmony_ci  bool suppress_deserialization_errors_ = false;
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci  // Always global handles.
3331cb0ef41Sopenharmony_ci  Handle<FixedArray> id_map_;
3341cb0ef41Sopenharmony_ci  MaybeHandle<SimpleNumberDictionary> array_buffer_transfer_map_;
3351cb0ef41Sopenharmony_ci};
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ci}  // namespace internal
3381cb0ef41Sopenharmony_ci}  // namespace v8
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_VALUE_SERIALIZER_H_
341