Skip to content

Commit 93fde59

Browse files
Zaggy1024gmta
authored andcommitted
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: whatwg/html#11773
1 parent 9e4c87a commit 93fde59

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Libraries/LibWeb/HTML/HTMLMediaElement.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,23 @@ double HTMLMediaElement::current_time() const
267267
}
268268

269269
// https://html.spec.whatwg.org/multipage/media.html#dom-media-currenttime
270-
void HTMLMediaElement::set_current_time(double current_time)
270+
double HTMLMediaElement::set_current_time(double current_time)
271271
{
272272
// On setting, if the media element's readyState is HAVE_NOTHING, then it must set the media element's default playback start
273273
// position to the new value; otherwise, it must set the official playback position to the new value and then seek to the new
274274
// value. The new value must be interpreted as being in seconds.
275275
if (m_ready_state == ReadyState::HaveNothing) {
276276
m_default_playback_start_position = current_time;
277277
} else {
278-
m_official_playback_position = current_time;
278+
// AD-HOC: Don't set the official playback position here, as seek_element() will set it according to the seekable
279+
// ranges. We return the value passed to the setter to ensure that chained assignments like
280+
// videoA.currentTime = videoB.currentTime = Number.MAX_VALUE;
281+
// will seek both videoA and videoB to their corresponding ending positions.
282+
// See https://github.com/whatwg/html/issues/11773
283+
279284
seek_element(current_time);
280285
}
286+
return current_time;
281287
}
282288

283289
// https://html.spec.whatwg.org/multipage/media.html#dom-media-fastseek

Libraries/LibWeb/HTML/HTMLMediaElement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class HTMLMediaElement : public HTMLElement {
9595
WebIDL::ExceptionOr<void> load();
9696

9797
double current_time() const;
98-
void set_current_time(double);
98+
double set_current_time(double);
9999
void fast_seek(double);
100100

101101
double current_playback_position() const { return m_current_playback_position; }

0 commit comments

Comments
 (0)