summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-04 13:15:05 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commitbe9d3860b9f962191f658dd991c80edd2ab50a91 (patch)
tree9c92cd19d657c33828e55ed3512df3e960142217
parent96f6c7fae580b3e5e90775c02494daa4f58650ea (diff)
downloadserenity-be9d3860b9f962191f658dd991c80edd2ab50a91.zip
LibWeb: Make Crypto GC-allocated
-rw-r--r--Userland/Libraries/LibWeb/Crypto/Crypto.cpp18
-rw-r--r--Userland/Libraries/LibWeb/Crypto/Crypto.h25
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.h2
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake2
6 files changed, 28 insertions, 22 deletions
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 <AK/Random.h>
#include <AK/StringBuilder.h>
#include <LibJS/Runtime/TypedArray.h>
-#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
+#include <LibWeb/HTML/Window.h>
namespace Web::Crypto {
+JS::NonnullGCPtr<Crypto> Crypto::create(HTML::Window& window)
+{
+ return *window.heap().allocate<Crypto>(window.realm(), window);
+}
+
Crypto::Crypto(HTML::Window& window)
- : m_subtle(*SubtleCrypto::create(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<SubtleCrypto> 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 <LibJS/Runtime/Value.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/DOM/ExceptionOr.h>
namespace Web::Crypto {
-class Crypto : public Bindings::Wrappable
- , public RefCounted<Crypto>
- , public Weakable<Crypto> {
+class Crypto : public Bindings::PlatformObject {
+ WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject);
+
public:
- using WrapperType = Bindings::CryptoWrapper;
+ static JS::NonnullGCPtr<Crypto> create(HTML::Window&);
- static NonnullRefPtr<Crypto> create(HTML::Window& window)
- {
- return adopt_ref(*new Crypto(window));
- }
+ virtual ~Crypto() override;
JS::NonnullGCPtr<SubtleCrypto> subtle() const;
@@ -31,14 +27,11 @@ public:
private:
explicit Crypto(HTML::Window&);
+ virtual void initialize(JS::Realm&) override;
- JS::Handle<SubtleCrypto> m_subtle;
+ JS::GCPtr<SubtleCrypto> 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 <LibJS/Runtime/Shape.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/CSSNamespace.h>
-#include <LibWeb/Bindings/CryptoWrapper.h>
#include <LibWeb/Bindings/EventTargetConstructor.h>
#include <LibWeb/Bindings/EventTargetPrototype.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
@@ -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<int, JS::NonnullGCPtr<Timer>> m_timers;
JS::GCPtr<HighResolutionTime::Performance> m_performance;
- RefPtr<Crypto::Crypto> m_crypto;
+ JS::GCPtr<Crypto::Crypto> m_crypto;
JS::GCPtr<CSS::Screen> 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)