LibWeb/HTML: Port Window.crypto to IDL

This commit is contained in:
Linus Groh 2023-03-06 19:50:56 +00:00
parent 7de9179a6d
commit 198db2ebd9
Notes: sideshowbarker 2024-07-17 11:29:41 +09:00
3 changed files with 14 additions and 12 deletions

View file

@ -1038,14 +1038,12 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::WindowPrototype>(realm, "Window"));
m_crypto = MUST_OR_THROW_OOM(heap().allocate<Crypto::Crypto>(realm, realm));
m_location = MUST_OR_THROW_OOM(heap().allocate<Location>(realm, realm));
m_navigator = MUST_OR_THROW_OOM(heap().allocate<Navigator>(realm, realm));
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
// FIXME: These should be native accessors, not properties
define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "screen", screen_getter, screen_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_accessor(realm, "innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
@ -1340,6 +1338,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> Window::p
return JS::NonnullGCPtr { *m_performance };
}
// https://w3c.github.io/webcrypto/#dom-windoworworkerglobalscope-crypto
WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> Window::crypto()
{
if (!m_crypto)
m_crypto = MUST_OR_THROW_OOM(heap().allocate<Crypto::Crypto>(realm(), realm()));
return JS::NonnullGCPtr { *m_crypto };
}
static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::VM& vm, JS::Value handler)
{
if (handler.is_function())
@ -1531,12 +1537,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
return JS::js_undefined();
}
JS_DEFINE_NATIVE_FUNCTION(Window::crypto_getter)
{
auto* impl = TRY(impl_from(vm));
return &impl->crypto();
}
JS_DEFINE_NATIVE_FUNCTION(Window::inner_width_getter)
{
auto* impl = TRY(impl_from(vm));

View file

@ -96,8 +96,6 @@ public:
void deallocate_timer_id(Badge<Timer>, i32);
Crypto::Crypto& crypto() { return *m_crypto; }
CSS::Screen& screen();
DOM::Event* current_event() { return m_current_event.ptr(); }
@ -169,6 +167,8 @@ public:
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance();
WebIDL::ExceptionOr<JS::NonnullGCPtr<Crypto::Crypto>> crypto();
private:
explicit Window(JS::Realm&);
@ -274,8 +274,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(request_idle_callback);
JS_DECLARE_NATIVE_FUNCTION(cancel_idle_callback);
JS_DECLARE_NATIVE_FUNCTION(crypto_getter);
HTML::Location* m_location { nullptr };
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap

View file

@ -1,3 +1,4 @@
#import <Crypto/Crypto.idl>
#import <DOM/Document.idl>
#import <DOM/EventHandler.idl>
#import <DOM/EventTarget.idl>
@ -44,6 +45,9 @@ interface Window : EventTarget {
// FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope
// https://w3c.github.io/hr-time/#the-performance-attribute
[Replaceable] readonly attribute Performance performance;
// https://w3c.github.io/webcrypto/#crypto-interface
[SameObject] readonly attribute Crypto crypto;
};
Window includes GlobalEventHandlers;
Window includes WindowEventHandlers;