ladybird/Libraries/LibWeb/Geometry/DOMQuad.h
Timothy Flynn 64abc6101d 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).
2025-07-18 10:09:02 -04:00

64 lines
2.1 KiB
C++

/*
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Geometry/DOMPoint.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Geometry/DOMRectReadOnly.h>
namespace Web::Geometry {
// https://drafts.fxtf.org/geometry/#dictdef-domquadinit
struct DOMQuadInit {
DOMPointInit p1;
DOMPointInit p2;
DOMPointInit p3;
DOMPointInit p4;
};
// https://drafts.fxtf.org/geometry/#domquad
class DOMQuad
: public Bindings::PlatformObject
, public Bindings::Serializable {
WEB_PLATFORM_OBJECT(DOMQuad, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(DOMQuad);
public:
static GC::Ref<DOMQuad> construct_impl(JS::Realm&, DOMPointInit const& p1, DOMPointInit const& p2, DOMPointInit const& p3, DOMPointInit const& p4);
static GC::Ref<DOMQuad> create(JS::Realm& realm);
virtual ~DOMQuad() override;
static GC::Ref<DOMQuad> from_rect(JS::VM&, DOMRectInit const&);
static GC::Ref<DOMQuad> from_quad(JS::VM&, DOMQuadInit const&);
GC::Ref<DOMPoint> p1() const { return m_p1; }
GC::Ref<DOMPoint> p2() const { return m_p2; }
GC::Ref<DOMPoint> p3() const { return m_p3; }
GC::Ref<DOMPoint> p4() const { return m_p4; }
GC::Ref<DOMRect> get_bounds() const;
virtual HTML::SerializeType serialize_type() const override { return HTML::SerializeType::DOMQuad; }
virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override;
virtual WebIDL::ExceptionOr<void> deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override;
private:
DOMQuad(JS::Realm&, DOMPointInit const& p1, DOMPointInit const& p2, DOMPointInit const& p3, DOMPointInit const& p4);
explicit DOMQuad(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
GC::Ref<DOMPoint> m_p1;
GC::Ref<DOMPoint> m_p2;
GC::Ref<DOMPoint> m_p3;
GC::Ref<DOMPoint> m_p4;
};
}