mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +00:00
LibWeb: Make SubtleCrypto GC-allocated
This commit is contained in:
parent
2ac8e3db3a
commit
7a9b8ced38
8 changed files with 38 additions and 29 deletions
|
@ -14,11 +14,16 @@
|
||||||
|
|
||||||
namespace Web::Crypto {
|
namespace Web::Crypto {
|
||||||
|
|
||||||
Crypto::Crypto()
|
Crypto::Crypto(HTML::Window& window)
|
||||||
: m_subtle(SubtleCrypto::create())
|
: m_subtle(*SubtleCrypto::create(window))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const
|
||||||
|
{
|
||||||
|
return *m_subtle;
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webcrypto/#dfn-Crypto-method-getRandomValues
|
// https://w3c.github.io/webcrypto/#dfn-Crypto-method-getRandomValues
|
||||||
DOM::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
|
DOM::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,20 +19,20 @@ class Crypto : public Bindings::Wrappable
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::CryptoWrapper;
|
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;
|
DOM::ExceptionOr<JS::Value> get_random_values(JS::Value array) const;
|
||||||
String random_uuid() const;
|
String random_uuid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Crypto();
|
explicit Crypto(HTML::Window&);
|
||||||
|
|
||||||
NonnullRefPtr<SubtleCrypto> m_subtle;
|
JS::Handle<SubtleCrypto> m_subtle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,24 @@
|
||||||
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
|
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
|
||||||
#include <LibWeb/Bindings/IDLAbstractOperations.h>
|
#include <LibWeb/Bindings/IDLAbstractOperations.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
#include <LibWeb/Bindings/Wrapper.h>
|
|
||||||
#include <LibWeb/Crypto/SubtleCrypto.h>
|
#include <LibWeb/Crypto/SubtleCrypto.h>
|
||||||
#include <LibWeb/DOM/DOMException.h>
|
#include <LibWeb/DOM/DOMException.h>
|
||||||
|
|
||||||
namespace Web::Crypto {
|
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)
|
JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data)
|
||||||
{
|
{
|
||||||
auto& vm = Bindings::main_thread_vm();
|
auto& vm = Bindings::main_thread_vm();
|
||||||
|
|
|
@ -7,31 +7,24 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
|
||||||
namespace Web::Crypto {
|
namespace Web::Crypto {
|
||||||
|
|
||||||
class SubtleCrypto
|
class SubtleCrypto final : public Bindings::PlatformObject {
|
||||||
: public Bindings::Wrappable
|
WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject);
|
||||||
, public RefCounted<SubtleCrypto> {
|
|
||||||
public:
|
|
||||||
using WrapperType = Bindings::SubtleCryptoWrapper;
|
|
||||||
|
|
||||||
static NonnullRefPtr<SubtleCrypto> create()
|
public:
|
||||||
{
|
static JS::NonnullGCPtr<SubtleCrypto> create(HTML::Window&);
|
||||||
return adopt_ref(*new SubtleCrypto());
|
|
||||||
}
|
virtual ~SubtleCrypto() override;
|
||||||
|
|
||||||
JS::Promise* digest(String const& algorithm, JS::Handle<JS::Object> const& data);
|
JS::Promise* digest(String const& algorithm, JS::Handle<JS::Object> const& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SubtleCrypto() = default;
|
explicit SubtleCrypto(HTML::Window&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Web::Bindings {
|
WRAPPER_HACK(SubtleCrypto, Web::Crypto)
|
||||||
|
|
||||||
SubtleCryptoWrapper* wrap(JS::Realm&, Crypto::SubtleCrypto&);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -466,7 +466,6 @@ class OptionConstructor;
|
||||||
class RangePrototype;
|
class RangePrototype;
|
||||||
class ResizeObserverWrapper;
|
class ResizeObserverWrapper;
|
||||||
class SelectionWrapper;
|
class SelectionWrapper;
|
||||||
class SubtleCryptoWrapper;
|
|
||||||
class TextDecoderWrapper;
|
class TextDecoderWrapper;
|
||||||
class TextEncoderWrapper;
|
class TextEncoderWrapper;
|
||||||
class URLSearchParamsIteratorWrapper;
|
class URLSearchParamsIteratorWrapper;
|
||||||
|
|
|
@ -92,7 +92,6 @@ JS::NonnullGCPtr<Window> Window::create_with_document(DOM::Document& document)
|
||||||
|
|
||||||
Window::Window(JS::Realm& realm)
|
Window::Window(JS::Realm& realm)
|
||||||
: DOM::EventTarget(realm)
|
: DOM::EventTarget(realm)
|
||||||
, m_crypto(Crypto::Crypto::create())
|
|
||||||
{
|
{
|
||||||
// FIXME: Should this be WindowPrototype?
|
// FIXME: Should this be WindowPrototype?
|
||||||
}
|
}
|
||||||
|
@ -100,7 +99,6 @@ Window::Window(JS::Realm& realm)
|
||||||
Window::Window(DOM::Document& document)
|
Window::Window(DOM::Document& document)
|
||||||
: DOM::EventTarget(document.shape().realm())
|
: DOM::EventTarget(document.shape().realm())
|
||||||
, m_associated_document(document)
|
, m_associated_document(document)
|
||||||
, m_crypto(Crypto::Crypto::create())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,6 +764,8 @@ void Window::initialize(JS::Realm& realm)
|
||||||
|
|
||||||
Object::set_prototype(&ensure_web_prototype<Bindings::WindowPrototype>("Window"));
|
Object::set_prototype(&ensure_web_prototype<Bindings::WindowPrototype>("Window"));
|
||||||
|
|
||||||
|
m_crypto = Crypto::Crypto::create(*this);
|
||||||
|
|
||||||
// FIXME: These should be native accessors, not properties
|
// FIXME: These should be native accessors, not properties
|
||||||
define_direct_property("window", this, JS::Attribute::Enumerable);
|
define_direct_property("window", this, JS::Attribute::Enumerable);
|
||||||
define_direct_property("frames", this, JS::Attribute::Enumerable);
|
define_direct_property("frames", this, JS::Attribute::Enumerable);
|
||||||
|
|
|
@ -147,7 +147,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;
|
||||||
NonnullRefPtr<Crypto::Crypto> m_crypto;
|
RefPtr<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;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# 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)
|
||||||
libweb_js_wrapper(Crypto/SubtleCrypto)
|
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)
|
||||||
libweb_js_wrapper(CSS/CSSGroupingRule NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSGroupingRule NO_INSTANCE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue