diff --git a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt index 3c5d824eacf..45ee28cd2d2 100644 --- a/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt +++ b/Tests/LibWeb/Text/expected/HTML/StructuredClone-serializable-objects.txt @@ -18,3 +18,5 @@ instanceOf DOMPoint: true DOMPoint: {"x":10,"y":20,"z":30,"w":40} instanceOf DOMRectReadOnly: true DOMRectReadOnly: {"x":10,"y":20,"width":30,"height":40,"top":20,"right":40,"bottom":60,"left":10} +instanceOf DOMRect: true +DOMRect: {"x":10,"y":20,"width":30,"height":40,"top":20,"right":40,"bottom":60,"left":10} diff --git a/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html index 07dc0625acf..f748cf773e3 100644 --- a/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html +++ b/Tests/LibWeb/Text/input/HTML/StructuredClone-serializable-objects.html @@ -39,6 +39,10 @@ println(`instanceOf DOMRectReadOnly: ${domRectReadOnly instanceof DOMRectReadOnly}`); println(`DOMRectReadOnly: ${JSON.stringify(domRectReadOnly)}`); + let domRect = structuredClone(new DOMRect(10, 20, 30, 40)); + println(`instanceOf DOMRect: ${domRect instanceof DOMRect}`); + println(`DOMRect: ${JSON.stringify(domRect)}`); + done(); }); diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp index 53be04b73c2..bc3c7394051 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp @@ -22,6 +22,11 @@ JS::NonnullGCPtr DOMRect::create(JS::Realm& realm, Gfx::FloatRect const return realm.heap().allocate(realm, realm, rect.x(), rect.y(), rect.width(), rect.height()); } +JS::NonnullGCPtr DOMRect::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + // https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary JS::NonnullGCPtr DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other) { @@ -34,6 +39,11 @@ DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double heig { } +DOMRect::DOMRect(JS::Realm& realm) + : DOMRectReadOnly(realm) +{ +} + DOMRect::~DOMRect() = default; void DOMRect::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.h b/Userland/Libraries/LibWeb/Geometry/DOMRect.h index f76e3876f1b..67fb6b65325 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRect.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.h @@ -18,6 +18,7 @@ class DOMRect final : public DOMRectReadOnly { public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0); [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Gfx::FloatRect const&); + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&); [[nodiscard]] static JS::NonnullGCPtr from_rect(JS::VM&, DOMRectInit const&); virtual ~DOMRect() override; @@ -32,8 +33,11 @@ public: void set_width(double width) { m_rect.set_width(width); } void set_height(double height) { m_rect.set_height(height); } + virtual StringView interface_name() const override { return "DOMRect"sv; } + private: DOMRect(JS::Realm&, double x, double y, double width, double height); + explicit DOMRect(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 4e70133ce72..c9f24225467 100644 --- a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp +++ b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -978,6 +979,8 @@ private: return Geometry::DOMPoint::create(realm); if (interface_name == "DOMRectReadOnly"sv) return Geometry::DOMRectReadOnly::create(realm); + if (interface_name == "DOMRect"sv) + return Geometry::DOMRect::create(realm); VERIFY_NOT_REACHED(); }