diff --git a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt
index 34b534dfce..00c29cc79e 100644
--- a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt
+++ b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt
@@ -12,3 +12,5 @@ DOMMatrixReadOnly: {"a":10,"b":20,"c":50,"d":60,"e":130,"f":140,"m11":10,"m12":2
instanceOf DOMMatrix: true
DOMMatrix: {"a":10,"b":20,"c":30,"d":40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
DOMMatrix: {"a":10,"b":20,"c":50,"d":60,"e":130,"f":140,"m11":10,"m12":20,"m13":30,"m14":40,"m21":50,"m22":60,"m23":70,"m24":80,"m31":90,"m32":100,"m33":110,"m34":120,"m41":130,"m42":140,"m43":150,"m44":160,"is2D":false,"isIdentity":false}
+instanceOf DOMPointReadOnly: true
+DOMPointReadOnly: {"x":10,"y":20,"z":30,"w":40}
diff --git a/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html
index 87002d560b..1e626668a2 100644
--- a/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html
+++ b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html
@@ -27,6 +27,10 @@
domMatrix = structuredClone(new DOMMatrix([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]));
println(`DOMMatrix: ${JSON.stringify(domMatrix)}`);
+ let domPointReadOnly = structuredClone(new DOMPointReadOnly(10, 20, 30, 40));
+ println(`instanceOf DOMPointReadOnly: ${domPointReadOnly instanceof DOMPointReadOnly}`);
+ println(`DOMPointReadOnly: ${JSON.stringify(domPointReadOnly)}`);
+
done();
});
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
index 035b4ef283..6c719ae301 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Andreas Kling
* Copyright (c) 2022, Sam Atkins
+ * Copyright (c) 2024, Kenneth Myhra
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -8,6 +9,7 @@
#include
#include
#include
+#include
#include
namespace Web::Geometry {
@@ -19,6 +21,11 @@ JS::NonnullGCPtr DOMPointReadOnly::construct_impl(JS::Realm& r
return realm.heap().allocate(realm, realm, x, y, z, w);
}
+JS::NonnullGCPtr DOMPointReadOnly::create(JS::Realm& realm)
+{
+ return realm.heap().allocate(realm, realm);
+}
+
DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
: PlatformObject(realm)
, m_x(x)
@@ -28,6 +35,11 @@ DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double
{
}
+DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm)
+ : PlatformObject(realm)
+{
+}
+
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
JS::NonnullGCPtr DOMPointReadOnly::from_point(JS::VM& vm, DOMPointInit const& other)
{
@@ -53,4 +65,31 @@ void DOMPointReadOnly::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMPointReadOnly);
}
+WebIDL::ExceptionOr DOMPointReadOnly::serialization_steps(HTML::SerializationRecord& serialized, bool)
+{
+ // 1. Set serialized.[[X]] to value’s x coordinate.
+ HTML::serialize_primitive_type(serialized, m_x);
+ // 2. Set serialized.[[Y]] to value’s y coordinate.
+ HTML::serialize_primitive_type(serialized, m_y);
+ // 3. Set serialized.[[Z]] to value’s z coordinate.
+ HTML::serialize_primitive_type(serialized, m_z);
+ // 4. Set serialized.[[W]] to value’s w coordinate.
+ HTML::serialize_primitive_type(serialized, m_w);
+
+ return {};
+}
+
+WebIDL::ExceptionOr DOMPointReadOnly::deserialization_steps(ReadonlySpan const& serialized, size_t& position)
+{
+ // 1. Set value’s x coordinate to serialized.[[X]].
+ m_x = HTML::deserialize_primitive_type(serialized, position);
+ // 2. Set value’s y coordinate to serialized.[[Y]].
+ m_y = HTML::deserialize_primitive_type(serialized, position);
+ // 3. Set value’s z coordinate to serialized.[[Z]].
+ m_z = HTML::deserialize_primitive_type(serialized, position);
+ // 4. Set value’s w coordinate to serialized.[[W]].
+ m_w = HTML::deserialize_primitive_type(serialized, position);
+ return {};
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
index 1630af8cfd..ff3a9e4dc5 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Andreas Kling
* Copyright (c) 2022, Sam Atkins
+ * Copyright (c) 2024, Kenneth Myhra
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -9,6 +10,7 @@
#include
#include
+#include
#include
namespace Web::Geometry {
@@ -21,12 +23,15 @@ struct DOMPointInit {
};
// https://drafts.fxtf.org/geometry/#dompointreadonly
-class DOMPointReadOnly : public Bindings::PlatformObject {
+class DOMPointReadOnly
+ : public Bindings::PlatformObject
+ , public Bindings::Serializable {
WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(DOMPointReadOnly);
public:
static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
+ static JS::NonnullGCPtr create(JS::Realm&);
static JS::NonnullGCPtr from_point(JS::VM&, DOMPointInit const&);
@@ -39,8 +44,13 @@ public:
WebIDL::ExceptionOr> matrix_transform(DOMMatrixInit&) const;
+ virtual StringView interface_name() const override { return "DOMPointReadOnly"sv; }
+ virtual WebIDL::ExceptionOr serialization_steps(HTML::SerializationRecord&, bool for_storage) override;
+ virtual WebIDL::ExceptionOr deserialization_steps(ReadonlySpan const&, size_t& position) override;
+
protected:
DOMPointReadOnly(JS::Realm&, double x, double y, double z, double w);
+ explicit DOMPointReadOnly(JS::Realm&);
virtual void initialize(JS::Realm&) override;
diff --git a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
index cabd81c39d..523bb58101 100644
--- a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
+++ b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp
@@ -37,6 +37,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -969,6 +970,8 @@ private:
return Geometry::DOMMatrixReadOnly::create(realm);
if (interface_name == "DOMMatrix"sv)
return Geometry::DOMMatrix::create(realm);
+ if (interface_name == "DOMPointReadOnly"sv)
+ return Geometry::DOMPointReadOnly::create(realm);
VERIFY_NOT_REACHED();
}