diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
7 files changed, 34 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.h b/Userland/Libraries/LibWeb/HTML/MessagePort.h index 6bd9c46d88..c04504728a 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.h +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.h @@ -17,6 +17,11 @@ namespace Web::HTML { E(onmessage, HTML::EventNames::message) \ E(onmessageerror, HTML::EventNames::messageerror) +// https://html.spec.whatwg.org/multipage/web-messaging.html#structuredserializeoptions +struct StructuredSerializeOptions { + Vector<JS::Handle<JS::Object>> transfer; +}; + // https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports class MessagePort final : public DOM::EventTarget { WEB_PLATFORM_OBJECT(MessagePort, DOM::EventTarget); diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.idl b/Userland/Libraries/LibWeb/HTML/MessagePort.idl index 38b436c2da..c453bb46ac 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.idl +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.idl @@ -4,12 +4,15 @@ // https://html.spec.whatwg.org/multipage/web-messaging.html#messageport [Exposed=(Window,Worker,AudioWorklet), Transferable] interface MessagePort : EventTarget { - undefined postMessage(any message); undefined start(); undefined close(); + // event handlers attribute EventHandler onmessage; attribute EventHandler onmessageerror; +}; +dictionary StructuredSerializeOptions { + sequence<object> transfer = []; }; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index cedc08f3fa..5e5e31bece 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -46,7 +46,6 @@ #include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/ExceptionReporter.h> #include <LibWeb/HTML/Storage.h> -#include <LibWeb/HTML/StructuredSerialize.h> #include <LibWeb/HTML/Timer.h> #include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/WindowProxy.h> @@ -742,13 +741,6 @@ JS::NonnullGCPtr<HTML::Storage> Window::session_storage() return *storage; } -// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone -WebIDL::ExceptionOr<JS::Value> Window::structured_clone_impl(JS::VM& vm, JS::Value message) -{ - auto serialized = TRY(structured_serialize(vm, message)); - return MUST(structured_deserialize(vm, serialized, *vm.current_realm(), {})); -} - // https://html.spec.whatwg.org/multipage/interaction.html#transient-activation bool Window::has_transient_activation() const { @@ -893,8 +885,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm define_native_function(realm, "queueMicrotask", queue_microtask, 1, attr); - define_native_function(realm, "structuredClone", structured_clone, 1, attr); - define_direct_property("CSS", MUST_OR_THROW_OOM(heap().allocate<Bindings::CSSNamespace>(realm, realm)), 0); // FIXME: Implement codegen for readonly properties with [PutForwards] @@ -1608,12 +1598,4 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter) return JS::js_undefined(); } -JS_DEFINE_NATIVE_FUNCTION(Window::structured_clone) -{ - auto* impl = TRY(impl_from(vm)); - return TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { - return impl->structured_clone_impl(vm, vm.argument(0)); - })); -} - } diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 4cbc962f6d..704b998e39 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -61,6 +61,7 @@ public: using WindowOrWorkerGlobalScopeMixin::atob; using WindowOrWorkerGlobalScopeMixin::btoa; using WindowOrWorkerGlobalScopeMixin::fetch; + using WindowOrWorkerGlobalScopeMixin::structured_clone; // ^DOM::EventTarget virtual bool dispatch_event(DOM::Event&) override; @@ -115,8 +116,6 @@ public: JS::NonnullGCPtr<HTML::Storage> local_storage(); JS::NonnullGCPtr<HTML::Storage> session_storage(); - WebIDL::ExceptionOr<JS::Value> structured_clone_impl(JS::VM& vm, JS::Value); - void start_an_idle_period(); AnimationFrameCallbackDriver& animation_frame_callback_driver() { return m_animation_frame_callback_driver; } @@ -251,8 +250,6 @@ public: private: JS_DECLARE_NATIVE_FUNCTION(location_setter); - JS_DECLARE_NATIVE_FUNCTION(structured_clone); - JS_DECLARE_NATIVE_FUNCTION(set_interval); JS_DECLARE_NATIVE_FUNCTION(set_timeout); JS_DECLARE_NATIVE_FUNCTION(clear_interval); diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp index 82eadeed5b..119d3cd980 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp @@ -12,6 +12,8 @@ #include <LibTextCodec/Decoder.h> #include <LibWeb/Fetch/FetchMethod.h> #include <LibWeb/Forward.h> +#include <LibWeb/HTML/Scripting/Environments.h> +#include <LibWeb/HTML/StructuredSerialize.h> #include <LibWeb/HTML/WindowOrWorkerGlobalScope.h> #include <LibWeb/Infra/Base64.h> #include <LibWeb/WebIDL/DOMException.h> @@ -84,6 +86,24 @@ WebIDL::ExceptionOr<String> WindowOrWorkerGlobalScopeMixin::atob(String const& d return TRY_OR_THROW_OOM(vm, decoder->to_utf8(decoded_data.value())); } +// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone +WebIDL::ExceptionOr<JS::Value> WindowOrWorkerGlobalScopeMixin::structured_clone(JS::Value value, StructuredSerializeOptions const& options) const +{ + auto& vm = this_impl().vm(); + (void)options; + + // 1. Let serialized be ? StructuredSerializeWithTransfer(value, options["transfer"]). + // FIXME: Use WithTransfer variant of the AO + auto serialized = TRY(structured_serialize(vm, value)); + + // 2. Let deserializeRecord be ? StructuredDeserializeWithTransfer(serialized, this's relevant realm). + // FIXME: Use WithTransfer variant of the AO + auto deserialized = TRY(structured_deserialize(vm, serialized, relevant_realm(this_impl()), {})); + + // 3. Return deserializeRecord.[[Deserialized]]. + return deserialized; +} + JS::NonnullGCPtr<JS::Promise> WindowOrWorkerGlobalScopeMixin::fetch(Fetch::RequestInfo const& input, Fetch::RequestInit const& init) const { auto& vm = this_impl().vm(); diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h index c99e9e3229..c01021c4c6 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h @@ -10,6 +10,7 @@ #include <LibWeb/Bindings/PlatformObject.h> #include <LibWeb/Fetch/Request.h> #include <LibWeb/Forward.h> +#include <LibWeb/HTML/MessagePort.h> namespace Web::HTML { @@ -27,6 +28,7 @@ public: bool cross_origin_isolated() const; WebIDL::ExceptionOr<String> btoa(String const& data) const; WebIDL::ExceptionOr<String> atob(String const& data) const; + WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Value, StructuredSerializeOptions const&) const; JS::NonnullGCPtr<JS::Promise> fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const; }; diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl index d7541952e1..23443c8f5a 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.idl @@ -1,5 +1,6 @@ #import <Fetch/Request.idl> #import <Fetch/Response.idl> +#import <HTML/MessagePort.idl> // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope interface mixin WindowOrWorkerGlobalScope { @@ -27,7 +28,7 @@ interface mixin WindowOrWorkerGlobalScope { // FIXME: Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options = {}); // structured cloning - // FIXME: any structuredClone(any value, optional StructuredSerializeOptions options = {}); + any structuredClone(any value, optional StructuredSerializeOptions options = {}); // https://fetch.spec.whatwg.org/#fetch-method [NewObject] Promise<Response> fetch(RequestInfo input, optional RequestInit init = {}); |