diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index fd6ffc274b..414b92a5f9 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -8,15 +8,29 @@ #include #include #include -#include #include #include +#include namespace Web::Crypto { -Crypto::Crypto(HTML::Window& window) - : m_subtle(*SubtleCrypto::create(window)) +JS::NonnullGCPtr Crypto::create(HTML::Window& window) { + return *window.heap().allocate(window.realm(), window); +} + +Crypto::Crypto(HTML::Window& window) + : PlatformObject(window.realm()) +{ + set_prototype(&window.cached_web_prototype("Crypto")); +} + +Crypto::~Crypto() = default; + +void Crypto::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + m_subtle = SubtleCrypto::create(global_object()); } JS::NonnullGCPtr Crypto::subtle() const diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.h b/Userland/Libraries/LibWeb/Crypto/Crypto.h index 04d8ef40fd..8d0a782a2a 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.h +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.h @@ -6,23 +6,19 @@ #pragma once -#include -#include +#include #include #include namespace Web::Crypto { -class Crypto : public Bindings::Wrappable - , public RefCounted - , public Weakable { -public: - using WrapperType = Bindings::CryptoWrapper; +class Crypto : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject); - static NonnullRefPtr create(HTML::Window& window) - { - return adopt_ref(*new Crypto(window)); - } +public: + static JS::NonnullGCPtr create(HTML::Window&); + + virtual ~Crypto() override; JS::NonnullGCPtr subtle() const; @@ -31,14 +27,11 @@ public: private: explicit Crypto(HTML::Window&); + virtual void initialize(JS::Realm&) override; - JS::Handle m_subtle; + JS::GCPtr m_subtle; }; } -namespace Web::Bindings { - -CryptoWrapper* wrap(JS::Realm&, Crypto::Crypto&); - -} +WRAPPER_HACK(Crypto, Web::Crypto) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index f27edd3746..e18837077b 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -448,7 +448,6 @@ class URLSearchParamsIterator; } namespace Web::Bindings { -class CryptoWrapper; class DOMExceptionWrapper; class IdleDeadlineWrapper; class IntersectionObserverWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index fb8c074137..db10fb6816 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -98,6 +97,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(m_performance.ptr()); visitor.visit(m_screen.ptr()); visitor.visit(m_location_object); + visitor.visit(m_crypto); for (auto& it : m_prototypes) visitor.visit(it.value); for (auto& it : m_constructors) diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index bc93acbdf8..e1ce9e953b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -145,7 +145,7 @@ private: HashMap> m_timers; JS::GCPtr m_performance; - RefPtr m_crypto; + JS::GCPtr m_crypto; JS::GCPtr m_screen; AnimationFrameCallbackDriver m_animation_frame_callback_driver; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 6083e113d8..a216c9a56d 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -1,7 +1,7 @@ # This file is included from "Meta/CMake/libweb_data.cmake" # It is defined here so that there is no need to go to the Meta directory when adding new idl files -libweb_js_wrapper(Crypto/Crypto) +libweb_js_wrapper(Crypto/Crypto NO_INSTANCE) libweb_js_wrapper(Crypto/SubtleCrypto NO_INSTANCE) libweb_js_wrapper(CSS/CSSConditionRule NO_INSTANCE) libweb_js_wrapper(CSS/CSSFontFaceRule NO_INSTANCE)