/src/serenity/Userland/Libraries/LibWeb/HTML/TrackEvent.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/Intrinsics.h> |
8 | | #include <LibWeb/Bindings/TrackEventPrototype.h> |
9 | | #include <LibWeb/HTML/TrackEvent.h> |
10 | | |
11 | | namespace Web::HTML { |
12 | | |
13 | | JS_DEFINE_ALLOCATOR(TrackEvent); |
14 | | |
15 | | JS::NonnullGCPtr<TrackEvent> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) |
16 | 0 | { |
17 | 0 | return realm.heap().allocate<TrackEvent>(realm, realm, event_name, move(event_init)); |
18 | 0 | } |
19 | | |
20 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) |
21 | 0 | { |
22 | 0 | return create(realm, event_name, move(event_init)); |
23 | 0 | } |
24 | | |
25 | | TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init) |
26 | 0 | : DOM::Event(realm, event_name, event_init) |
27 | 0 | , m_track(move(event_init.track)) |
28 | 0 | { |
29 | 0 | } |
30 | | |
31 | | void TrackEvent::initialize(JS::Realm& realm) |
32 | 0 | { |
33 | 0 | Base::initialize(realm); |
34 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(TrackEvent); |
35 | 0 | } |
36 | | |
37 | | Variant<Empty, JS::Handle<VideoTrack>, JS::Handle<AudioTrack>, JS::Handle<TextTrack>> TrackEvent::track() const |
38 | 0 | { |
39 | | // FIXME: This is a bit awkward. When creating a nullable union, our IDL generator creates a type of |
40 | | // Optional<Variant<...>>, using an empty Optional to represent null. But when retrieving the |
41 | | // attribute, it expects a type of Variant<Empty, ...>, using Empty to represent null. |
42 | 0 | if (!m_track.has_value()) |
43 | 0 | return Empty {}; |
44 | | |
45 | 0 | return *m_track; |
46 | 0 | } |
47 | | |
48 | | } |