diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 08c4c5b1c0..452632a234 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -155,6 +155,8 @@ static bool impl_is_wrapper(Type const& type) return true; if (type.name == "WebGLRenderingContext"sv) return true; + if (type.name == "Path2D"sv) + return true; return false; } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6243b521c2..49e4ac68c3 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -463,7 +463,6 @@ class IdleDeadlineWrapper; class IntersectionObserverWrapper; class LocationObject; class OptionConstructor; -class Path2DWrapper; class RangePrototype; class ResizeObserverWrapper; class SelectionWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.cpp b/Userland/Libraries/LibWeb/HTML/Path2D.cpp index 5d28efdb88..165d04f7a9 100644 --- a/Userland/Libraries/LibWeb/HTML/Path2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/Path2D.cpp @@ -4,13 +4,23 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include +#include namespace Web::HTML { -// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d -Path2D::Path2D(Optional, String>> const& path) +JS::NonnullGCPtr Path2D::create_with_global_object(HTML::Window& window, Optional, String>> const& path) { + return *window.heap().allocate(window.realm(), window, path); +} + +// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d +Path2D::Path2D(HTML::Window& window, Optional, String>> const& path) + : PlatformObject(window.realm()) +{ + set_prototype(&window.ensure_web_prototype("Path2D")); + // 1. Let output be a new Path2D object. // 2. If path is not given, then return output. if (!path.has_value()) @@ -18,8 +28,8 @@ Path2D::Path2D(Optional, String>> const& path) // 3. If path is a Path2D object, then add all subpaths of path to output and return output. // (In other words, it returns a copy of the argument.) - if (path->has>()) { - this->path() = path->get>()->path(); + if (path->has>()) { + this->path() = path->get>()->path(); return; } @@ -32,4 +42,6 @@ Path2D::Path2D(Optional, String>> const& path) // FIXME: 8. Return output. } +Path2D::~Path2D() = default; + } diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.h b/Userland/Libraries/LibWeb/HTML/Path2D.h index 92d7a4a3c6..fd847d8de6 100644 --- a/Userland/Libraries/LibWeb/HTML/Path2D.h +++ b/Userland/Libraries/LibWeb/HTML/Path2D.h @@ -8,29 +8,27 @@ #include #include -#include +#include #include namespace Web::HTML { // https://html.spec.whatwg.org/multipage/canvas.html#path2d -class Path2D - : public RefCounted - , public Bindings::Wrappable +class Path2D final + : public Bindings::PlatformObject , public CanvasPath { - AK_MAKE_NONCOPYABLE(Path2D); - AK_MAKE_NONMOVABLE(Path2D); + WEB_PLATFORM_OBJECT(Path2D, Bindings::PlatformObject); public: - using WrapperType = Bindings::Path2DWrapper; + static JS::NonnullGCPtr create_with_global_object(HTML::Window&, Optional, String>> const& path); - static NonnullRefPtr create_with_global_object(HTML::Window&, Optional, String>> const& path) { return adopt_ref(*new Path2D(path)); } - static NonnullRefPtr create(Optional, String>> const& path) { return adopt_ref(*new Path2D(path)); } - ~Path2D() = default; + virtual ~Path2D() override; private: - Path2D(Optional, String>> const&); + Path2D(HTML::Window&, Optional, String>> const&); }; } + +WRAPPER_HACK(Path2D, Web::HTML) diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 02af86c302..915c240e6e 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -145,7 +145,7 @@ libweb_js_wrapper(HTML/MessageChannel NO_INSTANCE) libweb_js_wrapper(HTML/MessageEvent NO_INSTANCE) libweb_js_wrapper(HTML/MessagePort NO_INSTANCE) libweb_js_wrapper(HTML/PageTransitionEvent NO_INSTANCE) -libweb_js_wrapper(HTML/Path2D) +libweb_js_wrapper(HTML/Path2D NO_INSTANCE) libweb_js_wrapper(HTML/PromiseRejectionEvent NO_INSTANCE) libweb_js_wrapper(HTML/Storage) libweb_js_wrapper(HTML/SubmitEvent NO_INSTANCE)