LibWeb: Implement HTMLTrackElement.readyState

This commit is contained in:
Jamie Mansfield 2024-08-05 22:28:19 +01:00 committed by Tim Ledbetter
commit 1d12cb69d4
Notes: github-actions[bot] 2024-08-06 06:58:30 +00:00
5 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1 @@
track.readyState == NONE: true

View file

@ -0,0 +1,8 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const track = document.createElement('track');
println(`track.readyState == NONE: ${track.readyState === HTMLTrackElement.NONE}`);
});
</script>

View file

@ -56,4 +56,30 @@ void HTMLTrackElement::attribute_changed(FlyString const& name, Optional<String>
} }
} }
// https://html.spec.whatwg.org/multipage/media.html#dom-track-readystate
WebIDL::UnsignedShort HTMLTrackElement::ready_state()
{
// The readyState attribute must return the numeric value corresponding to the text track readiness state of the track element's text track, as defined by the following list:
switch (m_track->readiness_state()) {
case TextTrack::ReadinessState::NotLoaded:
// NONE (numeric value 0)
// The text track not loaded state.
return 0;
case TextTrack::ReadinessState::Loading:
// LOADING (numeric value 1)
// The text track loading state.
return 1;
case TextTrack::ReadinessState::Loaded:
// LOADED (numeric value 2)
// The text track loaded state.
return 2;
case TextTrack::ReadinessState::FailedToLoad:
// ERROR (numeric value 3)
// The text track failed to load state.
return 3;
}
VERIFY_NOT_REACHED();
}
} }

View file

@ -19,6 +19,8 @@ class HTMLTrackElement final : public HTMLElement {
public: public:
virtual ~HTMLTrackElement() override; virtual ~HTMLTrackElement() override;
WebIDL::UnsignedShort ready_state();
JS::Handle<TextTrack> track() { return m_track; } JS::Handle<TextTrack> track() { return m_track; }
private: private:

View file

@ -26,7 +26,7 @@ interface HTMLTrackElement : HTMLElement {
const unsigned short LOADING = 1; const unsigned short LOADING = 1;
const unsigned short LOADED = 2; const unsigned short LOADED = 2;
const unsigned short ERROR = 3; const unsigned short ERROR = 3;
[FIXME] readonly attribute unsigned short readyState; readonly attribute unsigned short readyState;
readonly attribute TextTrack track; readonly attribute TextTrack track;