diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp index 621f4980d3..056cddd3a6 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023, Kenneth Myhra + * Copyright (c) 2022-2024, Kenneth Myhra * Copyright (c) 2023, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +149,40 @@ void Blob::initialize(JS::Realm& realm) set_prototype(&Bindings::ensure_web_prototype(realm, "Blob"_fly_string)); } +WebIDL::ExceptionOr Blob::serialization_steps(HTML::SerializationRecord& record, bool) +{ + auto& vm = this->vm(); + + TRY(HTML::serialize_string(vm, record, interface_name())); + + // FIXME: 1. Set serialized.[[SnapshotState]] to value’s snapshot state. + + // NON-STANDARD: FileAPI spec doesn't specify that type should be serialized, although + // to be conformant with other browsers this needs to be serialized. + TRY(HTML::serialize_string(vm, record, m_type)); + + // 2. Set serialized.[[ByteSequence]] to value’s underlying byte sequence. + TRY(HTML::serialize_bytes(vm, record, m_byte_buffer.bytes())); + + return {}; +} + +WebIDL::ExceptionOr Blob::deserialization_steps(ReadonlySpan const& record, size_t& position) +{ + auto& vm = this->vm(); + + // FIXME: 1. Set value’s snapshot state to serialized.[[SnapshotState]]. + + // NON-STANDARD: FileAPI spec doesn't specify that type should be deserialized, although + // to be conformant with other browsers this needs to be deserialized. + m_type = TRY(HTML::deserialize_string(vm, record, position)); + + // 2. Set value’s underlying byte sequence to serialized.[[ByteSequence]]. + m_byte_buffer = TRY(HTML::deserialize_bytes(vm, record, position)); + + return {}; +} + // https://w3c.github.io/FileAPI/#ref-for-dom-blob-blob JS::NonnullGCPtr Blob::create(JS::Realm& realm, Optional> const& blob_parts, Optional const& options) { diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.h b/Userland/Libraries/LibWeb/FileAPI/Blob.h index ad9566cab8..42984e7676 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.h +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023, Kenneth Myhra + * Copyright (c) 2022-2024, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,9 @@ struct BlobPropertyBag { [[nodiscard]] ErrorOr process_blob_parts(Vector const& blob_parts, Optional const& options = {}); [[nodiscard]] bool is_basic_latin(StringView view); -class Blob : public Bindings::PlatformObject { +class Blob + : public Bindings::PlatformObject + , public Bindings::Serializable { WEB_PLATFORM_OBJECT(Blob, Bindings::PlatformObject); JS_DECLARE_ALLOCATOR(Blob); @@ -52,6 +55,11 @@ public: WebIDL::ExceptionOr> get_stream(); + virtual StringView interface_name() const override { return "Blob"sv; } + + virtual WebIDL::ExceptionOr serialization_steps(HTML::SerializationRecord& record, bool for_storage) override; + virtual WebIDL::ExceptionOr deserialization_steps(ReadonlySpan const& record, size_t& position) override; + protected: Blob(JS::Realm&, ByteBuffer, String type); Blob(JS::Realm&, ByteBuffer);