LibWeb: Make the value of assignment to media currentTime the rhs value

In cases where a script assigns `x = video.currentTime = y`, we are
expected to have a result of `x === y`, even if the video's duration
is less than y.

According to the spec, this happens because the official playback
position is set to `y` in this case, but since we are following
implementations in making `currentTime` immediately return the position
on the valid media timeline, we have to specifically return the
unchanged value from the setter.

See: https://github.com/whatwg/html/issues/11773
This commit is contained in:
Zaggy1024 2025-10-14 18:28:32 -05:00 committed by Jelle Raaijmakers
parent 9e4c87ab85
commit 93fde59892
Notes: github-actions[bot] 2025-10-28 00:30:45 +00:00
2 changed files with 9 additions and 3 deletions

View file

@ -267,7 +267,7 @@ double HTMLMediaElement::current_time() const
}
// https://html.spec.whatwg.org/multipage/media.html#dom-media-currenttime
void HTMLMediaElement::set_current_time(double current_time)
double HTMLMediaElement::set_current_time(double current_time)
{
// On setting, if the media element's readyState is HAVE_NOTHING, then it must set the media element's default playback start
// position to the new value; otherwise, it must set the official playback position to the new value and then seek to the new
@ -275,9 +275,15 @@ void HTMLMediaElement::set_current_time(double current_time)
if (m_ready_state == ReadyState::HaveNothing) {
m_default_playback_start_position = current_time;
} else {
m_official_playback_position = current_time;
// AD-HOC: Don't set the official playback position here, as seek_element() will set it according to the seekable
// ranges. We return the value passed to the setter to ensure that chained assignments like
// videoA.currentTime = videoB.currentTime = Number.MAX_VALUE;
// will seek both videoA and videoB to their corresponding ending positions.
// See https://github.com/whatwg/html/issues/11773
seek_element(current_time);
}
return current_time;
}
// https://html.spec.whatwg.org/multipage/media.html#dom-media-fastseek