summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Geometry
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-03 21:32:14 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit44415af428ba5f33aae6e1cfb2cecb28e5683864 (patch)
treeec5311e3a439a470c753b7d118f6465f9a9c8de1 /Userland/Libraries/LibWeb/Geometry
parenta9cae56f8e5235798bd5d85eaf5e3df417380592 (diff)
downloadserenity-44415af428ba5f33aae6e1cfb2cecb28e5683864.zip
LibWeb: Make DOMPoint and DOMPointReadOnly GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb/Geometry')
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp25
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPoint.h22
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp29
-rw-r--r--Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h31
4 files changed, 71 insertions, 36 deletions
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp
new file mode 100644
index 0000000000..5b6ee78cd9
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Geometry/DOMPoint.h>
+#include <LibWeb/HTML/Window.h>
+
+namespace Web::Geometry {
+
+JS::NonnullGCPtr<DOMPoint> DOMPoint::create_with_global_object(HTML::Window& window, double x, double y, double z, double w)
+{
+ return *window.heap().allocate<DOMPoint>(window.realm(), window, x, y, z, w);
+}
+
+DOMPoint::DOMPoint(HTML::Window& window, double x, double y, double z, double w)
+ : DOMPointReadOnly(window, x, y, z, w)
+{
+ set_prototype(&window.cached_web_prototype("DOMPoint"));
+}
+
+DOMPoint::~DOMPoint() = default;
+
+}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
index ccea076ebb..cf0b8e3956 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPoint.h
@@ -12,18 +12,12 @@ namespace Web::Geometry {
// https://drafts.fxtf.org/geometry/#DOMPoint
class DOMPoint final : public DOMPointReadOnly {
-public:
- using WrapperType = Bindings::DOMPointWrapper;
+ WEB_PLATFORM_OBJECT(DOMPoint, DOMPointReadOnly);
- static NonnullRefPtr<DOMPoint> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0)
- {
- return DOMPoint::create(x, y, z, w);
- }
+public:
+ static JS::NonnullGCPtr<DOMPoint> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0);
- static NonnullRefPtr<DOMPoint> create(double x = 0, double y = 0, double z = 0, double w = 0)
- {
- return adopt_ref(*new DOMPoint(x, y, z, w));
- }
+ virtual ~DOMPoint() override;
double x() const { return m_x; }
double y() const { return m_y; }
@@ -36,9 +30,9 @@ public:
void set_w(double w) { m_w = w; }
private:
- DOMPoint(float x, float y, float z, float w)
- : DOMPointReadOnly(x, y, z, w)
- {
- }
+ DOMPoint(HTML::Window&, double x, double y, double z, double w);
};
+
}
+
+WRAPPER_HACK(DOMPoint, Web::Geometry)
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
new file mode 100644
index 0000000000..aefd2d4cdb
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Geometry/DOMPointReadOnly.h>
+#include <LibWeb/HTML/Window.h>
+
+namespace Web::Geometry {
+
+JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::create_with_global_object(HTML::Window& window, double x, double y, double z, double w)
+{
+ return *window.heap().allocate<DOMPointReadOnly>(window.realm(), window, x, y, z, w);
+}
+
+DOMPointReadOnly::DOMPointReadOnly(HTML::Window& window, double x, double y, double z, double w)
+ : PlatformObject(window.realm())
+ , m_x(x)
+ , m_y(y)
+ , m_z(z)
+ , m_w(w)
+{
+ set_prototype(&window.cached_web_prototype("DOMPointReadOnly"));
+}
+
+DOMPointReadOnly::~DOMPointReadOnly() = default;
+
+}
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
index b9587058ae..47b5aba7f8 100644
--- a/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
+++ b/Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
@@ -6,29 +6,20 @@
#pragma once
-#include <AK/RefCounted.h>
#include <LibGfx/Point.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
namespace Web::Geometry {
// https://drafts.fxtf.org/geometry/#dompointreadonly
-class DOMPointReadOnly
- : public RefCounted<DOMPointReadOnly>
- , public Bindings::Wrappable {
-public:
- using WrapperType = Bindings::DOMPointReadOnlyWrapper;
+class DOMPointReadOnly : public Bindings::PlatformObject {
+ WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
- static NonnullRefPtr<DOMPointReadOnly> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0)
- {
- return DOMPointReadOnly::create(x, y, z, w);
- }
+public:
+ static JS::NonnullGCPtr<DOMPointReadOnly> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double z = 0, double w = 0);
- static NonnullRefPtr<DOMPointReadOnly> create(double x = 0, double y = 0, double z = 0, double w = 0)
- {
- return adopt_ref(*new DOMPointReadOnly(x, y, z, w));
- }
+ virtual ~DOMPointReadOnly() override;
double x() const { return m_x; }
double y() const { return m_y; }
@@ -36,13 +27,7 @@ public:
double w() const { return m_w; }
protected:
- DOMPointReadOnly(double x, double y, double z, double w)
- : m_x(x)
- , m_y(y)
- , m_z(z)
- , m_w(w)
- {
- }
+ DOMPointReadOnly(HTML::Window&, double x, double y, double z, double w);
double m_x;
double m_y;
@@ -51,3 +36,5 @@ protected:
};
}
+
+WRAPPER_HACK(DOMPointReadOnly, Web::Geometry)