浏览代码

LibWeb: Make Crypto GC-allocated

Andreas Kling 2 年之前
父节点
当前提交
be9d3860b9

+ 16 - 2
Userland/Libraries/LibWeb/Crypto/Crypto.cpp

@@ -8,15 +8,29 @@
 #include <AK/Random.h>
 #include <AK/Random.h>
 #include <AK/StringBuilder.h>
 #include <AK/StringBuilder.h>
 #include <LibJS/Runtime/TypedArray.h>
 #include <LibJS/Runtime/TypedArray.h>
-#include <LibWeb/Bindings/Wrapper.h>
 #include <LibWeb/Crypto/Crypto.h>
 #include <LibWeb/Crypto/Crypto.h>
 #include <LibWeb/Crypto/SubtleCrypto.h>
 #include <LibWeb/Crypto/SubtleCrypto.h>
+#include <LibWeb/HTML/Window.h>
 
 
 namespace Web::Crypto {
 namespace Web::Crypto {
 
 
+JS::NonnullGCPtr<Crypto> Crypto::create(HTML::Window& window)
+{
+    return *window.heap().allocate<Crypto>(window.realm(), window);
+}
+
 Crypto::Crypto(HTML::Window& 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
 JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const

+ 9 - 16
Userland/Libraries/LibWeb/Crypto/Crypto.h

@@ -6,23 +6,19 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <LibJS/Runtime/Value.h>
-#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Bindings/PlatformObject.h>
 #include <LibWeb/Crypto/SubtleCrypto.h>
 #include <LibWeb/Crypto/SubtleCrypto.h>
 #include <LibWeb/DOM/ExceptionOr.h>
 #include <LibWeb/DOM/ExceptionOr.h>
 
 
 namespace Web::Crypto {
 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:
 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;
     JS::NonnullGCPtr<SubtleCrypto> subtle() const;
 
 
@@ -31,14 +27,11 @@ public:
 
 
 private:
 private:
     explicit Crypto(HTML::Window&);
     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)

+ 0 - 1
Userland/Libraries/LibWeb/Forward.h

@@ -448,7 +448,6 @@ class URLSearchParamsIterator;
 }
 }
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
-class CryptoWrapper;
 class DOMExceptionWrapper;
 class DOMExceptionWrapper;
 class IdleDeadlineWrapper;
 class IdleDeadlineWrapper;
 class IntersectionObserverWrapper;
 class IntersectionObserverWrapper;

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -15,7 +15,6 @@
 #include <LibJS/Runtime/Shape.h>
 #include <LibJS/Runtime/Shape.h>
 #include <LibTextCodec/Decoder.h>
 #include <LibTextCodec/Decoder.h>
 #include <LibWeb/Bindings/CSSNamespace.h>
 #include <LibWeb/Bindings/CSSNamespace.h>
-#include <LibWeb/Bindings/CryptoWrapper.h>
 #include <LibWeb/Bindings/EventTargetConstructor.h>
 #include <LibWeb/Bindings/EventTargetConstructor.h>
 #include <LibWeb/Bindings/EventTargetPrototype.h>
 #include <LibWeb/Bindings/EventTargetPrototype.h>
 #include <LibWeb/Bindings/ExceptionOrUtils.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_performance.ptr());
     visitor.visit(m_screen.ptr());
     visitor.visit(m_screen.ptr());
     visitor.visit(m_location_object);
     visitor.visit(m_location_object);
+    visitor.visit(m_crypto);
     for (auto& it : m_prototypes)
     for (auto& it : m_prototypes)
         visitor.visit(it.value);
         visitor.visit(it.value);
     for (auto& it : m_constructors)
     for (auto& it : m_constructors)

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Window.h

@@ -145,7 +145,7 @@ private:
     HashMap<int, JS::NonnullGCPtr<Timer>> m_timers;
     HashMap<int, JS::NonnullGCPtr<Timer>> m_timers;
 
 
     JS::GCPtr<HighResolutionTime::Performance> m_performance;
     JS::GCPtr<HighResolutionTime::Performance> m_performance;
-    RefPtr<Crypto::Crypto> m_crypto;
+    JS::GCPtr<Crypto::Crypto> m_crypto;
     JS::GCPtr<CSS::Screen> m_screen;
     JS::GCPtr<CSS::Screen> m_screen;
 
 
     AnimationFrameCallbackDriver m_animation_frame_callback_driver;
     AnimationFrameCallbackDriver m_animation_frame_callback_driver;

+ 1 - 1
Userland/Libraries/LibWeb/idl_files.cmake

@@ -1,7 +1,7 @@
 # This file is included from "Meta/CMake/libweb_data.cmake"
 # 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
 # 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(Crypto/SubtleCrypto NO_INSTANCE)
 libweb_js_wrapper(CSS/CSSConditionRule NO_INSTANCE)
 libweb_js_wrapper(CSS/CSSConditionRule NO_INSTANCE)
 libweb_js_wrapper(CSS/CSSFontFaceRule NO_INSTANCE)
 libweb_js_wrapper(CSS/CSSFontFaceRule NO_INSTANCE)