Repository navigation
script: GC media elements after playback ends - #49367
Merged
Merged
Conversation
Signed-off-by: Sabb <[email protected]>
jschwe
added a commit
to openharmony-rs/servo-ohos
that referenced
this pull request
Oct 30, 2026
Upstream servo#48979 keeps a media element alive through its owner document while it plays or is eligible for autoplay, and servo#49367 lets it go after it has ended. An element that delays the load event or seeks is still collected at the next garbage collection once script drops it, which stops it and lets the load event fire early, and the keep-alive is only updated at a few points of the media element's algorithms. Like Gecko, and Blink apart from autoplay, also keep a media element alive while it delays the load event and, with a resource and no error, while it seeks. Don't keep an element without a resource alive, and keep one that is eligible for autoplay only until it has enough data: then it either plays or never will. Update the keep-alive whenever the network state, paused, seeking, the can autoplay flag, the error, the ready state or the delaying-the-load-event flag changes. Fork note: meant for upstream; found with the QuickJS backend, which frees such elements as soon as script drops them, but SpiderMonkey loses them too once a GC runs. Until the 2026-10-29 sync this patch had its own keep-alive set; it now extends upstream's. Besides the upstream change, this drops the QuickJS conditions in the expectations of autoplay-disabled-by-permissions-policy; patch 49 dropped the others. Drop once upstream has it. Testing: Adds a WPT test that unreferenced media elements keep playing across a garbage collection. Validation: Release builds of upstream f040186 with SpiderMonkey, with and without the series, `./mach test-wpt --processes 4` of html/semantics/embedded-content/media-elements, the-video-element, the-audio-element, infrastructure/assumptions/allowed-to-play.html, webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface and 2 _mozilla media tests: the new test passes 7 of 7 (harness timeout without), autoplay-disabled-by-permissions-policy and played-loop as in the updated expectations (autoplay-disabled timed out intermittently before, upstream issues servo#46012 and servo#46804); the remaining differences are track timeouts and track-cues-sorted-before-dispatch failures that both builds show intermittently, and one seek-to-max-value failure in 7 runs with the series (`currentTime` 0 right after setting it), not reproduced in 6 reruns, apart from load-removes-queued-error-event, which now hangs whenever GStreamer 1.24.2's playbin3 stalls on a `<video>` with an audio-only MP3: 4 of 6 runs on this host without the series too; the stalled element delays the load event, and before, only a garbage collection that freed it let the load event fire (upstream's intermittent tracker has 9 unexpected results for that test in total). The three tests that fail on QuickJS CI pass with forced GCs every 20 ms too. With logging of the keep-alive updates, every element in direct checks stopped being kept alive once it had been loaded and never played, played to the end, paused, replayed after the end without a seekable range, or played backwards to the start. An independent agent review found no blockers; its two should-fix findings for this patch (ended but unpaused elements were kept alive; changes of the error went through no hook) are fixed. QuickJS release build of this stack: the new tests and the media tests that had QuickJS expectations (autoplay.html, allowed-to-play.html, resource-selection-candidate-moved.html and the three autoplay permissions policy tests) give SpiderMonkey's results in 2 of 2 runs; without the series they time out as the dropped expectations said. 2026-10-29 sync, reworked onto upstream's keep-alive: release builds of this sync's stack and of plain upstream ed6a924, `./mach test-wpt --release` of the media-elements, the-video-element and the-audio-element directories with fetch, xhr, eventsource, cors, subresource-integrity, resource-timing, canvas image drawing and _mozilla/memory (2,247 tests), then 3 reruns on both of every test whose results differed: the same results on both except for intermittent ones, gc-unreferenced-media-element and upstream's playing_media_no_gc pass; a playing element's back/forward cache restore fails on both (upstream servo#48979 pauses it at unload). DAYU200 (OpenHarmony 7.0), headless release builds with SpiderMonkey and with QuickJS, `./mach test-wpt --ohos --processes 1 --timeout-multiplier 2` of the media series' tests, loading-the-media-resource, error-codes and playing-the-media-resource (75 tests): all as expected but the two autoplay permissions policy tests that pass where a timeout is expected, on both engines; no crash. AI-assisted: Yes (agent session; root-caused, written and tested by the agent) AI-assisted: Yes (agent session; 2026-10-22 sync -- mechanical conflict resolution: the `HTMLMediaElement` import next to upstream's `TracedScriptResult` (servo#48855), and the patch's +8 bytes of `HTMLVideoElement` applied to upstream's new sizes (servo#48082)) AI-assisted: Yes (agent session; 2026-10-29 sync -- upstream servo#48979 and servo#49367 landed a keep-alive set of their own: the patch now extends upstream's `should_keep_alive` with its rules (load event delay, seeking, resource and HAVE_ENOUGH_DATA conditions) and keeps its setter hooks; its own set, flag and duplicate hooks are gone, as is its +8 bytes of `HTMLVideoElement`; subject and message rewritten) Signed-off-by: Jonathan Schwender <[email protected]>
jschwe
added a commit
to openharmony-rs/servo-ohos
that referenced
this pull request
Nov 9, 2026
Upstream servo#48979 keeps a media element alive through its owner document while it plays or is eligible for autoplay, and servo#49367 lets it go after it has ended. An element that delays the load event or seeks is still collected at the next garbage collection once script drops it, which stops it and lets the load event fire early, and the keep-alive is only updated at a few points of the media element's algorithms. Like Gecko, and Blink apart from autoplay, also keep a media element alive while it delays the load event and, with a resource and no error, while it seeks. Don't keep an element without a resource alive, and keep one that is eligible for autoplay only until it has enough data: then it either plays or never will. Update the keep-alive whenever the network state, paused, seeking, the can autoplay flag, the error, the ready state or the delaying-the-load-event flag changes. Fork note: meant for upstream; found with the QuickJS backend, which frees such elements as soon as script drops them, but SpiderMonkey loses them too once a GC runs. Until the 2026-10-29 sync this patch had its own keep-alive set; it now extends upstream's. Besides the upstream change, this drops the QuickJS conditions in the expectations of autoplay-disabled-by-permissions-policy; patch 49 dropped the others. Drop once upstream has it. Testing: Adds a WPT test that unreferenced media elements keep playing across a garbage collection. Validation: Release builds of upstream f040186 with SpiderMonkey, with and without the series, `./mach test-wpt --processes 4` of html/semantics/embedded-content/media-elements, the-video-element, the-audio-element, infrastructure/assumptions/allowed-to-play.html, webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface and 2 _mozilla media tests: the new test passes 7 of 7 (harness timeout without), autoplay-disabled-by-permissions-policy and played-loop as in the updated expectations (autoplay-disabled timed out intermittently before, upstream issues servo#46012 and servo#46804); the remaining differences are track timeouts and track-cues-sorted-before-dispatch failures that both builds show intermittently, and one seek-to-max-value failure in 7 runs with the series (`currentTime` 0 right after setting it), not reproduced in 6 reruns, apart from load-removes-queued-error-event, which now hangs whenever GStreamer 1.24.2's playbin3 stalls on a `<video>` with an audio-only MP3: 4 of 6 runs on this host without the series too; the stalled element delays the load event, and before, only a garbage collection that freed it let the load event fire (upstream's intermittent tracker has 9 unexpected results for that test in total). The three tests that fail on QuickJS CI pass with forced GCs every 20 ms too. With logging of the keep-alive updates, every element in direct checks stopped being kept alive once it had been loaded and never played, played to the end, paused, replayed after the end without a seekable range, or played backwards to the start. An independent agent review found no blockers; its two should-fix findings for this patch (ended but unpaused elements were kept alive; changes of the error went through no hook) are fixed. QuickJS release build of this stack: the new tests and the media tests that had QuickJS expectations (autoplay.html, allowed-to-play.html, resource-selection-candidate-moved.html and the three autoplay permissions policy tests) give SpiderMonkey's results in 2 of 2 runs; without the series they time out as the dropped expectations said. 2026-10-29 sync, reworked onto upstream's keep-alive: release builds of this sync's stack and of plain upstream ed6a924, `./mach test-wpt --release` of the media-elements, the-video-element and the-audio-element directories with fetch, xhr, eventsource, cors, subresource-integrity, resource-timing, canvas image drawing and _mozilla/memory (2,247 tests), then 3 reruns on both of every test whose results differed: the same results on both except for intermittent ones, gc-unreferenced-media-element and upstream's playing_media_no_gc pass; a playing element's back/forward cache restore fails on both (upstream servo#48979 pauses it at unload). DAYU200 (OpenHarmony 7.0), headless release builds with SpiderMonkey and with QuickJS, `./mach test-wpt --ohos --processes 1 --timeout-multiplier 2` of the media series' tests, loading-the-media-resource, error-codes and playing-the-media-resource (75 tests): all as expected but the two autoplay permissions policy tests that pass where a timeout is expected, on both engines; no crash. AI-assisted: Yes (agent session; root-caused, written and tested by the agent) AI-assisted: Yes (agent session; 2026-10-22 sync -- mechanical conflict resolution: the `HTMLMediaElement` import next to upstream's `TracedScriptResult` (servo#48855), and the patch's +8 bytes of `HTMLVideoElement` applied to upstream's new sizes (servo#48082)) AI-assisted: Yes (agent session; 2026-10-29 sync -- upstream servo#48979 and servo#49367 landed a keep-alive set of their own: the patch now extends upstream's `should_keep_alive` with its rules (load event delay, seeking, resource and HAVE_ENOUGH_DATA conditions) and keeps its setter hooks; its own set, flag and duplicate hooks are gone, as is its +8 bytes of `HTMLVideoElement`; subject and message rewritten) AI-assisted: Yes (agent session; 2026-11-09 sync -- upstream's WPT sync (servo#49485) now expects what this patch made autoplay-disabled-by-permissions-policy.https.sub.html do (FAIL instead of TIMEOUT), so of this patch's hunk only the removal of the QuickJS conditions remains) Signed-off-by: Jonathan Schwender <[email protected]>
jschwe
added a commit
to openharmony-rs/servo-ohos
that referenced
this pull request
Nov 10, 2026
Upstream servo#48979 keeps a media element alive through its owner document while it plays or is eligible for autoplay, and servo#49367 lets it go after it has ended. An element that delays the load event or seeks is still collected at the next garbage collection once script drops it, which stops it and lets the load event fire early, and the keep-alive is only updated at a few points of the media element's algorithms. Like Gecko, and Blink apart from autoplay, also keep a media element alive while it delays the load event and, with a resource and no error, while it seeks. Don't keep an element without a resource alive, and keep one that is eligible for autoplay only until it has enough data: then it either plays or never will. Update the keep-alive whenever the network state, paused, seeking, the can autoplay flag, the error, the ready state or the delaying-the-load-event flag changes. Fork note: meant for upstream; found with the QuickJS backend, which frees such elements as soon as script drops them, but SpiderMonkey loses them too once a GC runs. Until the 2026-10-29 sync this patch had its own keep-alive set; it now extends upstream's. Besides the upstream change, this drops the QuickJS conditions in the expectations of autoplay-disabled-by-permissions-policy; patch 49 dropped the others. Drop once upstream has it. Testing: Adds a WPT test that unreferenced media elements keep playing across a garbage collection. Validation: Release builds of upstream f040186 with SpiderMonkey, with and without the series, `./mach test-wpt --processes 4` of html/semantics/embedded-content/media-elements, the-video-element, the-audio-element, infrastructure/assumptions/allowed-to-play.html, webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface and 2 _mozilla media tests: the new test passes 7 of 7 (harness timeout without), autoplay-disabled-by-permissions-policy and played-loop as in the updated expectations (autoplay-disabled timed out intermittently before, upstream issues servo#46012 and servo#46804); the remaining differences are track timeouts and track-cues-sorted-before-dispatch failures that both builds show intermittently, and one seek-to-max-value failure in 7 runs with the series (`currentTime` 0 right after setting it), not reproduced in 6 reruns, apart from load-removes-queued-error-event, which now hangs whenever GStreamer 1.24.2's playbin3 stalls on a `<video>` with an audio-only MP3: 4 of 6 runs on this host without the series too; the stalled element delays the load event, and before, only a garbage collection that freed it let the load event fire (upstream's intermittent tracker has 9 unexpected results for that test in total). The three tests that fail on QuickJS CI pass with forced GCs every 20 ms too. With logging of the keep-alive updates, every element in direct checks stopped being kept alive once it had been loaded and never played, played to the end, paused, replayed after the end without a seekable range, or played backwards to the start. An independent agent review found no blockers; its two should-fix findings for this patch (ended but unpaused elements were kept alive; changes of the error went through no hook) are fixed. QuickJS release build of this stack: the new tests and the media tests that had QuickJS expectations (autoplay.html, allowed-to-play.html, resource-selection-candidate-moved.html and the three autoplay permissions policy tests) give SpiderMonkey's results in 2 of 2 runs; without the series they time out as the dropped expectations said. 2026-10-29 sync, reworked onto upstream's keep-alive: release builds of this sync's stack and of plain upstream ed6a924, `./mach test-wpt --release` of the media-elements, the-video-element and the-audio-element directories with fetch, xhr, eventsource, cors, subresource-integrity, resource-timing, canvas image drawing and _mozilla/memory (2,247 tests), then 3 reruns on both of every test whose results differed: the same results on both except for intermittent ones, gc-unreferenced-media-element and upstream's playing_media_no_gc pass; a playing element's back/forward cache restore fails on both (upstream servo#48979 pauses it at unload). DAYU200 (OpenHarmony 7.0), headless release builds with SpiderMonkey and with QuickJS, `./mach test-wpt --ohos --processes 1 --timeout-multiplier 2` of the media series' tests, loading-the-media-resource, error-codes and playing-the-media-resource (75 tests): all as expected but the two autoplay permissions policy tests that pass where a timeout is expected, on both engines; no crash. AI-assisted: Yes (agent session; root-caused, written and tested by the agent) AI-assisted: Yes (agent session; 2026-10-22 sync -- mechanical conflict resolution: the `HTMLMediaElement` import next to upstream's `TracedScriptResult` (servo#48855), and the patch's +8 bytes of `HTMLVideoElement` applied to upstream's new sizes (servo#48082)) AI-assisted: Yes (agent session; 2026-10-29 sync -- upstream servo#48979 and servo#49367 landed a keep-alive set of their own: the patch now extends upstream's `should_keep_alive` with its rules (load event delay, seeking, resource and HAVE_ENOUGH_DATA conditions) and keeps its setter hooks; its own set, flag and duplicate hooks are gone, as is its +8 bytes of `HTMLVideoElement`; subject and message rewritten) AI-assisted: Yes (agent session; 2026-11-09 sync -- upstream's WPT sync (servo#49485) now expects what this patch made autoplay-disabled-by-permissions-policy.https.sub.html do (FAIL instead of TIMEOUT), so of this patch's hunk only the removal of the QuickJS conditions remains) Signed-off-by: Jonathan Schwender <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allowed the GC to collect unreferenced elements by calling
update_keep_alive()after firing the 'ended' event inreaches_the_end_steps. Movedtests/wpt/mozilla/tests/mozilla/playing_media_no_gc.htmlintotests/wpt/mozilla/tests/memorydirectory.Testing:
./mach test-wpt tests/wpt/mozilla/tests/memory/playing_media_no_gc.htmlpassed cleanly w/o errors;Fixes: #49351