diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index df17923d9e..863d33d35d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -587,12 +587,12 @@ JS::NonnullGCPtr Element::get_bounding_client_rect() const // FIXME: Support inline layout nodes as well. auto* paint_box = this->paint_box(); if (!paint_box) - return Geometry::DOMRect::create_with_global_object(window(), 0, 0, 0, 0); + return Geometry::DOMRect::construct_impl(realm(), 0, 0, 0, 0); VERIFY(document().browsing_context()); auto viewport_offset = document().browsing_context()->viewport_scroll_offset(); - return Geometry::DOMRect::create(window(), paint_box->absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y())); + return Geometry::DOMRect::create(realm(), paint_box->absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y())); } // https://drafts.csswg.org/cssom-view/#dom-element-getclientrects @@ -602,7 +602,7 @@ JS::NonnullGCPtr Element::get_client_rects() const // 1. If the element on which it was invoked does not have an associated layout box return an empty DOMRectList object and stop this algorithm. if (!layout_node() || !layout_node()->is_box()) - return Geometry::DOMRectList::create(window(), move(rects)); + return Geometry::DOMRectList::create(realm(), move(rects)); // FIXME: 2. If the element has an associated SVG layout box return a DOMRectList object containing a single DOMRect object that describes // the bounding box of the element as defined by the SVG specification, applying the transforms that apply to the element and its ancestors. @@ -616,7 +616,7 @@ JS::NonnullGCPtr Element::get_client_rects() const auto bounding_rect = get_bounding_client_rect(); rects.append(*bounding_rect); - return Geometry::DOMRectList::create(window(), move(rects)); + return Geometry::DOMRectList::create(realm(), move(rects)); } int Element::client_top() const diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp index 5b6ee78cd9..57d57cd903 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp @@ -4,20 +4,26 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include namespace Web::Geometry { -JS::NonnullGCPtr DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) +JS::NonnullGCPtr DOMPoint::construct_impl(JS::Realm& realm, double x, double y, double z, double w) { - return *window.heap().allocate(window.realm(), window, x, y, z, w); + return *realm.heap().allocate(realm, realm, x, y, z, w); } -DOMPoint::DOMPoint(HTML::Window& window, double x, double y, double z, double w) - : DOMPointReadOnly(window, x, y, z, w) +JS::NonnullGCPtr DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) { - set_prototype(&window.cached_web_prototype("DOMPoint")); + return construct_impl(window.realm(), x, y, z, w); +} + +DOMPoint::DOMPoint(JS::Realm& realm, double x, double y, double z, double w) + : DOMPointReadOnly(realm, x, y, z, w) +{ + set_prototype(&Bindings::cached_web_prototype(realm, "DOMPoint")); } DOMPoint::~DOMPoint() = default; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h index ef0ce1ba67..b4ade6d2dd 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h @@ -15,6 +15,7 @@ class DOMPoint final : public DOMPointReadOnly { WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly); public: + static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 0); static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0); virtual ~DOMPoint() override; @@ -30,7 +31,7 @@ public: void set_w(double w) { m_w = w; } private: - DOMPoint(HTML::Window&, double x, double y, double z, double w); + DOMPoint(JS::Realm&, double x, double y, double z, double w); }; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp index aefd2d4cdb..7844540012 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp @@ -4,24 +4,24 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::Geometry { -JS::NonnullGCPtr DOMPointReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double z, double w) +JS::NonnullGCPtr DOMPointReadOnly::construct_impl(JS::Realm& realm, double x, double y, double z, double w) { - return *window.heap().allocate(window.realm(), window, x, y, z, w); + return *realm.heap().allocate(realm, realm, x, y, z, w); } -DOMPointReadOnly::DOMPointReadOnly(HTML::Window& window, double x, double y, double z, double w) - : PlatformObject(window.realm()) +DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w) + : PlatformObject(realm) , m_x(x) , m_y(y) , m_z(z) , m_w(w) { - set_prototype(&window.cached_web_prototype("DOMPointReadOnly")); + set_prototype(&Bindings::cached_web_prototype(realm, "DOMPointReadOnly")); } DOMPointReadOnly::~DOMPointReadOnly() = default; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h index f512922cd9..1777bd6e13 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h @@ -17,7 +17,7 @@ class DOMPointReadOnly : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0); + static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 0); virtual ~DOMPointReadOnly() override; @@ -27,7 +27,7 @@ public: double w() const { return m_w; } protected: - DOMPointReadOnly(HTML::Window&, double x, double y, double z, double w); + DOMPointReadOnly(JS::Realm&, double x, double y, double z, double w); double m_x; double m_y; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp index 202c13a9f5..aacadfb06a 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.cpp @@ -4,25 +4,25 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::Geometry { -JS::NonnullGCPtr DOMRect::create_with_global_object(HTML::Window& window, double x, double y, double width, double height) +JS::NonnullGCPtr DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height) { - return *window.heap().allocate(window.realm(), window, x, y, width, height); + return *realm.heap().allocate(realm, realm, x, y, width, height); } -JS::NonnullGCPtr DOMRect::create(HTML::Window& window, Gfx::FloatRect const& rect) +JS::NonnullGCPtr DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect) { - return create_with_global_object(window, rect.x(), rect.y(), rect.width(), rect.height()); + return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height()); } -DOMRect::DOMRect(HTML::Window& window, double x, double y, double width, double height) - : DOMRectReadOnly(window, x, y, width, height) +DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height) + : DOMRectReadOnly(realm, x, y, width, height) { - set_prototype(&window.cached_web_prototype("DOMRect")); + set_prototype(&Bindings::cached_web_prototype(realm, "DOMRect")); } DOMRect::~DOMRect() = default; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRect.h b/Userland/Libraries/LibWeb/Geometry/DOMRect.h index 25523ce6c9..babc4897b3 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRect.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRect.h @@ -15,8 +15,8 @@ class DOMRect final : public DOMRectReadOnly { WEB_PLATFORM_OBJECT(DOMRect, DOMRectReadOnly); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double width = 0, double height = 0); - static JS::NonnullGCPtr create(HTML::Window&, Gfx::FloatRect const&); + static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0); + static JS::NonnullGCPtr create(JS::Realm&, Gfx::FloatRect const&); virtual ~DOMRect() override; @@ -31,7 +31,7 @@ public: void set_height(double height) { m_rect.set_height(height); } private: - DOMRect(HTML::Window&, double x, double y, double width, double height); + DOMRect(JS::Realm&, double x, double y, double width, double height); }; } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp index c0888e5124..0e60ddb281 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp @@ -5,22 +5,22 @@ */ #include +#include #include #include -#include namespace Web::Geometry { -JS::NonnullGCPtr DOMRectList::create(HTML::Window& window, Vector> rect_handles) +JS::NonnullGCPtr DOMRectList::create(JS::Realm& realm, Vector> rect_handles) { Vector> rects; for (auto& rect : rect_handles) rects.append(*rect); - return *window.heap().allocate(window.realm(), window, move(rects)); + return *realm.heap().allocate(realm, realm, move(rects)); } -DOMRectList::DOMRectList(HTML::Window& window, Vector> rects) - : Bindings::LegacyPlatformObject(window.cached_web_prototype("DOMRectList")) +DOMRectList::DOMRectList(JS::Realm& realm, Vector> rects) + : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(realm, "DOMRectList")) , m_rects(move(rects)) { } diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h index c77c3aded9..0eaccfcee9 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h @@ -17,7 +17,7 @@ class DOMRectList final : public Bindings::LegacyPlatformObject { WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, Vector>); + static JS::NonnullGCPtr create(JS::Realm&, Vector>); virtual ~DOMRectList() override; @@ -28,7 +28,7 @@ public: virtual JS::Value item_value(size_t index) const override; private: - DOMRectList(HTML::Window&, Vector>); + DOMRectList(JS::Realm&, Vector>); Vector> m_rects; }; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp index 27d5a09c27..681df18913 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.cpp @@ -4,21 +4,21 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::Geometry { -JS::NonnullGCPtr DOMRectReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double width, double height) +JS::NonnullGCPtr DOMRectReadOnly::construct_impl(JS::Realm& realm, double x, double y, double width, double height) { - return *window.heap().allocate(window.realm(), window, x, y, width, height); + return *realm.heap().allocate(realm, realm, x, y, width, height); } -DOMRectReadOnly::DOMRectReadOnly(HTML::Window& window, double x, double y, double width, double height) - : PlatformObject(window.realm()) +DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height) + : PlatformObject(realm) , m_rect(x, y, width, height) { - set_prototype(&window.cached_web_prototype("DOMRectReadOnly")); + set_prototype(&Bindings::cached_web_prototype(realm, "DOMRectReadOnly")); } DOMRectReadOnly::~DOMRectReadOnly() = default; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h index 595be796e1..e34665faa6 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectReadOnly.h @@ -17,7 +17,7 @@ class DOMRectReadOnly : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, double x = 0, double y = 0, double width = 0, double height = 0); + static JS::NonnullGCPtr construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0); virtual ~DOMRectReadOnly() override; @@ -32,7 +32,7 @@ public: double left() const { return min(x(), x() + width()); } protected: - DOMRectReadOnly(HTML::Window&, double x, double y, double width, double height); + DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height); Gfx::FloatRect m_rect; };