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

LibWeb: Make SubtleCrypto GC-allocated

This commit is contained in:
Andreas Kling 2022-09-03 19:59:53 +02:00
parent 2ac8e3db3a
commit 7a9b8ced38
8 changed files with 38 additions and 29 deletions

View file

@ -14,11 +14,16 @@
namespace Web::Crypto {
Crypto::Crypto()
: m_subtle(SubtleCrypto::create())
Crypto::Crypto(HTML::Window& window)
: m_subtle(*SubtleCrypto::create(window))
{
}
JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const
{
return *m_subtle;
}
// https://w3c.github.io/webcrypto/#dfn-Crypto-method-getRandomValues
DOM::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
{

View file

@ -19,20 +19,20 @@ class Crypto : public Bindings::Wrappable
public:
using WrapperType = Bindings::CryptoWrapper;
static NonnullRefPtr<Crypto> create()
static NonnullRefPtr<Crypto> create(HTML::Window& window)
{
return adopt_ref(*new Crypto());
return adopt_ref(*new Crypto(window));
}
NonnullRefPtr<SubtleCrypto> subtle() const { return m_subtle; }
JS::NonnullGCPtr<SubtleCrypto> subtle() const;
DOM::ExceptionOr<JS::Value> get_random_values(JS::Value array) const;
String random_uuid() const;
private:
Crypto();
explicit Crypto(HTML::Window&);
NonnullRefPtr<SubtleCrypto> m_subtle;
JS::Handle<SubtleCrypto> m_subtle;
};
}

View file

@ -10,12 +10,24 @@
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/DOM/DOMException.h>
namespace Web::Crypto {
JS::NonnullGCPtr<SubtleCrypto> SubtleCrypto::create(HTML::Window& window)
{
return *window.heap().allocate<SubtleCrypto>(window.realm(), window);
}
SubtleCrypto::SubtleCrypto(HTML::Window& window)
: PlatformObject(window.realm())
{
set_prototype(&window.cached_web_prototype("SubtleCrypto"));
}
SubtleCrypto::~SubtleCrypto() = default;
JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data)
{
auto& vm = Bindings::main_thread_vm();

View file

@ -7,31 +7,24 @@
#pragma once
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::Crypto {
class SubtleCrypto
: public Bindings::Wrappable
, public RefCounted<SubtleCrypto> {
public:
using WrapperType = Bindings::SubtleCryptoWrapper;
class SubtleCrypto final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject);
static NonnullRefPtr<SubtleCrypto> create()
{
return adopt_ref(*new SubtleCrypto());
}
public:
static JS::NonnullGCPtr<SubtleCrypto> create(HTML::Window&);
virtual ~SubtleCrypto() override;
JS::Promise* digest(String const& algorithm, JS::Handle<JS::Object> const& data);
private:
SubtleCrypto() = default;
explicit SubtleCrypto(HTML::Window&);
};
}
namespace Web::Bindings {
SubtleCryptoWrapper* wrap(JS::Realm&, Crypto::SubtleCrypto&);
}
WRAPPER_HACK(SubtleCrypto, Web::Crypto)