|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright (c) 2022-2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
|
|
+ * Copyright (c) 2022-2024, Kenneth Myhra <kennethmyhra@serenityos.org>
|
|
|
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
|
|
|
*
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
@@ -15,6 +15,7 @@
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
#include <LibWeb/FileAPI/Blob.h>
|
|
|
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
|
|
+#include <LibWeb/HTML/StructuredSerialize.h>
|
|
|
#include <LibWeb/Infra/Strings.h>
|
|
|
#include <LibWeb/Streams/AbstractOperations.h>
|
|
|
#include <LibWeb/Streams/ReadableStreamDefaultReader.h>
|
|
@@ -148,6 +149,40 @@ void Blob::initialize(JS::Realm& realm)
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::BlobPrototype>(realm, "Blob"_fly_string));
|
|
|
}
|
|
|
|
|
|
+WebIDL::ExceptionOr<void> 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<void> Blob::deserialization_steps(ReadonlySpan<u32> 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> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
|
|
{
|