diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index b5a4753dec5..d7f2166b39f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -27,6 +27,7 @@ static bool is_platform_object(Type const& type) static constexpr Array types = { "AbortSignal"sv, "Attr"sv, + "AudioTrack"sv, "Blob"sv, "CanvasGradient"sv, "CanvasPattern"sv, diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index ff863fa1b0c..b132e15330a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -1020,9 +1020,9 @@ WebIDL::ExceptionOr HTMLMediaElement::process_media_data(Functiondispatch_event(event); } diff --git a/Userland/Libraries/LibWeb/HTML/TrackEvent.cpp b/Userland/Libraries/LibWeb/HTML/TrackEvent.cpp index 22a3a188377..4402fe12491 100644 --- a/Userland/Libraries/LibWeb/HTML/TrackEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/TrackEvent.cpp @@ -10,19 +10,19 @@ namespace Web::HTML { -WebIDL::ExceptionOr> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init) +WebIDL::ExceptionOr> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) { - return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, event_name, event_init)); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, event_name, move(event_init))); } -WebIDL::ExceptionOr> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init) +WebIDL::ExceptionOr> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) { - return create(realm, event_name, event_init); + return create(realm, event_name, move(event_init)); } -TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init) +TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) : DOM::Event(realm, event_name, event_init) - , m_track(event_init.track) + , m_track(move(event_init.track)) { } @@ -34,4 +34,15 @@ JS::ThrowCompletionOr TrackEvent::initialize(JS::Realm& realm) return {}; } +Variant, JS::Handle> TrackEvent::track() const +{ + // FIXME: This is a bit awkward. When creating a nullable union, our IDL generator creates a type of + // Optional>, using an empty Optional to represent null. But when retrieving the + // attribute, it expects a type of Variant, using Empty to represent null. + if (!m_track.has_value()) + return Empty {}; + + return *m_track; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/TrackEvent.h b/Userland/Libraries/LibWeb/HTML/TrackEvent.h index b0c0a858646..16ae83a5db9 100644 --- a/Userland/Libraries/LibWeb/HTML/TrackEvent.h +++ b/Userland/Libraries/LibWeb/HTML/TrackEvent.h @@ -7,30 +7,34 @@ #pragma once #include +#include +#include +#include #include namespace Web::HTML { struct TrackEventInit : public DOM::EventInit { - JS::GCPtr track; + using TrackType = Optional, JS::Handle>>; + TrackType track; }; class TrackEvent : public DOM::Event { WEB_PLATFORM_OBJECT(TrackEvent, DOM::Event); public: - static WebIDL::ExceptionOr> create(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init = {}); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init); + static WebIDL::ExceptionOr> create(JS::Realm&, FlyString const& event_name, TrackEventInit event_init = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, TrackEventInit event_init); // https://html.spec.whatwg.org/multipage/media.html#dom-trackevent-track - JS::GCPtr track() const { return m_track; } + Variant, JS::Handle> track() const; private: - TrackEvent(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init); + TrackEvent(JS::Realm&, FlyString const& event_name, TrackEventInit event_init); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; - JS::GCPtr m_track; + TrackEventInit::TrackType m_track; }; } diff --git a/Userland/Libraries/LibWeb/HTML/TrackEvent.idl b/Userland/Libraries/LibWeb/HTML/TrackEvent.idl index 3696e6a0de5..41d45b26282 100644 --- a/Userland/Libraries/LibWeb/HTML/TrackEvent.idl +++ b/Userland/Libraries/LibWeb/HTML/TrackEvent.idl @@ -1,4 +1,5 @@ #import +#import #import // https://html.spec.whatwg.org/multipage/media.html#trackevent @@ -7,10 +8,10 @@ interface TrackEvent : Event { constructor(DOMString type, optional TrackEventInit eventInitDict = {}); // FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)? - readonly attribute VideoTrack? track; + readonly attribute (VideoTrack or AudioTrack)? track; }; dictionary TrackEventInit : EventInit { // FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)? - VideoTrack? track = null; + (VideoTrack or AudioTrack)? track = null; };