StructuredSerialize.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2022, Daniel Ehrenberg <dan@littledan.dev>
  3. * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Result.h>
  9. #include <AK/Types.h>
  10. #include <AK/Vector.h>
  11. #include <LibJS/Forward.h>
  12. #include <LibWeb/WebIDL/ExceptionOr.h>
  13. // Structured serialize is an entirely different format from IPC because:
  14. // - It contains representation of type information
  15. // - It may contain circularities
  16. // - It is restricted to JS values
  17. namespace Web::HTML {
  18. using SerializationRecord = Vector<u32>;
  19. struct SerializationRange {
  20. u64 start = 0;
  21. u64 end = 0;
  22. };
  23. using SerializationMemory = HashMap<JS::Handle<JS::Value>, SerializationRange>;
  24. WebIDL::ExceptionOr<SerializationRecord> structured_serialize(JS::VM& vm, JS::Value);
  25. WebIDL::ExceptionOr<SerializationRecord> structured_serialize_for_storage(JS::VM& vm, JS::Value);
  26. WebIDL::ExceptionOr<SerializationRecord> structured_serialize_internal(JS::VM& vm, JS::Value, bool for_storage, SerializationMemory&);
  27. WebIDL::ExceptionOr<JS::Value> structured_deserialize(JS::VM& vm, SerializationRecord const& serialized, JS::Realm& target_realm, Optional<SerializationMemory>);
  28. // TODO: structured_[de]serialize_with_transfer
  29. }