1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

LibWeb: Make Crypto GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 13:15:05 +02:00
parent 96f6c7fae5
commit be9d3860b9
6 changed files with 30 additions and 24 deletions

View file

@ -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 {
Crypto::Crypto(HTML::Window& window)
: m_subtle(*SubtleCrypto::create(window))
JS::NonnullGCPtr<Crypto> Crypto::create(HTML::Window& window)
{
return *window.heap().allocate<Crypto>(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<SubtleCrypto> Crypto::subtle() const

View file

@ -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> {
public:
using WrapperType = Bindings::CryptoWrapper;
class Crypto : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject);
static NonnullRefPtr<Crypto> create(HTML::Window& window)
{
return adopt_ref(*new Crypto(window));
}
public:
static JS::NonnullGCPtr<Crypto> create(HTML::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)