mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 01:42:17 +00:00
LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder and decoder to serialize JS values. It also used a u32 buffer under the hood, which made using its structures a bit awkward. We had previously worked around its data structures in transferable streams, which nested transfers of MessagePort instances. We basically had to add hooks into the MessagePort to route to the correct transfer receiving steps, and we could not invoke the correct AOs directly as the spec dictates. We now use IPC mechanics to encode and decode data. This works because, although we are encoding JS values, we are only ultimately encoding primitive and basic AK types. The resulting data structures actually enforce that we implement transferable streams exactly as the spec is worded (I had planned to do that in a separate commit, but the fallout of this patch actually required that change).
This commit is contained in:
parent
7fad8c333d
commit
64abc6101d
Notes:
github-actions[bot]
2025-07-18 14:10:44 +00:00
Author: https://github.com/trflynn89
Commit: 64abc6101d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5492
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/shannonbooth
44 changed files with 765 additions and 970 deletions
|
@ -180,22 +180,22 @@ const JS::Uint8ClampedArray* ImageData::data() const
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#pixel-manipulation:serialization-steps
|
||||
WebIDL::ExceptionOr<void> ImageData::serialization_steps(SerializationRecord& serialized, bool for_storage, SerializationMemory& memory)
|
||||
WebIDL::ExceptionOr<void> ImageData::serialization_steps(HTML::TransferDataEncoder& serialized, bool for_storage, HTML::SerializationMemory& memory)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Set serialized.[[Data]] to the sub-serialization of the value of value's data attribute.
|
||||
auto serialized_data = TRY(structured_serialize_internal(vm, m_data, for_storage, memory));
|
||||
serialized.extend(move(serialized_data));
|
||||
serialized.append(move(serialized_data));
|
||||
|
||||
// 2. Set serialized.[[Width]] to the value of value's width attribute.
|
||||
serialize_primitive_type(serialized, m_bitmap->width());
|
||||
serialized.encode(m_bitmap->width());
|
||||
|
||||
// 3. Set serialized.[[Height]] to the value of value's height attribute.
|
||||
serialize_primitive_type(serialized, m_bitmap->height());
|
||||
serialized.encode(m_bitmap->height());
|
||||
|
||||
// 4. Set serialized.[[ColorSpace]] to the value of value's colorSpace attribute.
|
||||
serialize_enum(serialized, m_color_space);
|
||||
serialized.encode(m_color_space);
|
||||
|
||||
// FIXME:: 5. Set serialized.[[PixelFormat]] to the value of value's pixelFormat attribute.
|
||||
|
||||
|
@ -203,26 +203,25 @@ WebIDL::ExceptionOr<void> ImageData::serialization_steps(SerializationRecord& se
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#pixel-manipulation:deserialization-steps
|
||||
WebIDL::ExceptionOr<void> ImageData::deserialization_steps(ReadonlySpan<u32> const& serialized, size_t& position, DeserializationMemory& memory)
|
||||
WebIDL::ExceptionOr<void> ImageData::deserialization_steps(HTML::TransferDataDecoder& serialized, HTML::DeserializationMemory& memory)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Initialize value's data attribute to the sub-deserialization of serialized.[[Data]].
|
||||
auto [value, position_after_deserialization] = TRY(structured_deserialize_internal(vm, serialized, realm, memory, position));
|
||||
if (value.has_value() && value.value().is_object() && is<JS::Uint8ClampedArray>(value.value().as_object())) {
|
||||
m_data = as<JS::Uint8ClampedArray>(value.release_value().as_object());
|
||||
}
|
||||
position = position_after_deserialization;
|
||||
auto deserialized = TRY(structured_deserialize_internal(vm, serialized, realm, memory));
|
||||
|
||||
if (auto* data = as_if<JS::Uint8ClampedArray>(deserialized.as_object()))
|
||||
m_data = *data;
|
||||
|
||||
// 2. Initialize value's width attribute to serialized.[[Width]].
|
||||
auto const width = deserialize_primitive_type<int>(serialized, position);
|
||||
auto width = serialized.decode<int>();
|
||||
|
||||
// 3. Initialize value's height attribute to serialized.[[Height]].
|
||||
auto const height = deserialize_primitive_type<int>(serialized, position);
|
||||
auto height = serialized.decode<int>();
|
||||
|
||||
// 4. Initialize value's colorSpace attribute to serialized.[[ColorSpace]].
|
||||
m_color_space = deserialize_primitive_type<Bindings::PredefinedColorSpace>(serialized, position);
|
||||
m_color_space = serialized.decode<Bindings::PredefinedColorSpace>();
|
||||
|
||||
// FIXME: 5. Initialize value's pixelFormat attribute to serialized.[[PixelFormat]].
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue