Skip to content

[MediaCapabilities] Protect MediaCapabilities JS wrapper from GC#1678

Open
asurdej-comcast wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
asurdej-comcast:media_caps
Open

[MediaCapabilities] Protect MediaCapabilities JS wrapper from GC#1678
asurdej-comcast wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
asurdej-comcast:media_caps

Conversation

@asurdej-comcast

@asurdej-comcast asurdej-comcast commented May 21, 2026

Copy link
Copy Markdown

Add GenerateIsReachable=ReachableFromNavigator to prevent wrapper GC. The MediaCapabilities interface is annotated [SameObject] in the spec, meaning navigator.mediaCapabilities must return the same object on every access. Without GC protection, the JS wrapper can be collected when no JS reference holds it, causing a new wrapper to be created on next access. This breaks object identity and loses any user-set properties.

This fixes an issue with ShakaPlayer that sets its own, custom navigator.mediaCapabilities.decodingInfo wrapper JS function that provides DRM data in addition to native decodingInfo impl.
See https://github.com/shaka-project/shaka-player/blob/ce7ee4b76f1fd6104519fe6f20fe7dda9d759eaf/lib/polyfill/mcap_encryption_scheme.js#L131

53edfff

Build-Tests Layout-Tests
✅ 🛠 wpe-246-amd64-build ✅ 🧪 wpe-246-amd64-layout
✅ 🛠 wpe-246-arm32-build ✅ 🧪 wpe-246-arm32-layout

Add GenerateIsReachable=ReachableFromNavigator to prevent wrapper GC.
The MediaCapabilities interface is annotated [SameObject] in the spec,
meaning navigator.mediaCapabilities must return the same object on every
access. Without GC protection, the JS wrapper can be collected when no
JS reference holds it, causing a new wrapper to be created on next access.
This breaks object identity and loses any user-set properties.
@pgorszkowski-igalia

Copy link
Copy Markdown

This seems to be a good candidate for upstreaming first. I am working on it.

@pgorszkowski-igalia

Copy link
Copy Markdown

PR in upstream: WebKit/WebKit#65807

webkit-commit-queue pushed a commit to pgorszkowski-igalia/WebKit that referenced this pull request Jun 12, 2026
…before its navigator object

https://bugs.webkit.org/show_bug.cgi?id=315684

Reviewed by Ryosuke Niwa.

navigator.mediaCapabilities wrapper should not become GC-collectable before its navigator object.
The MediaCapabilities interface is annotated [SameObject] in the spec:
https://www.w3.org/TR/media-capabilities/#idl-index
It means that navigator.mediaCapabilities must return the same object on every access.

See: WebPlatformForEmbedded/WPEWebKit#1678

Original author: Andrzej Surdej (https://github.com/asurdej-comcast)

Updated existing LayoutTest with mediaCapabilities case.

* LayoutTests/fast/dom/navigator-property-gc-after-frame-detach-expected.txt:
* LayoutTests/fast/dom/navigator-property-gc-after-frame-detach.html:
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:
(WebCore::MediaCapabilities::MediaCapabilities):
(WebCore::MediaCapabilities::navigator):
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.h:
(WebCore::MediaCapabilities::create):
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.idl:
* Source/WebCore/Modules/mediacapabilities/NavigatorMediaCapabilities.cpp:
(WebCore::NavigatorMediaCapabilities::NavigatorMediaCapabilities):
(WebCore::NavigatorMediaCapabilities::from):
* Source/WebCore/Modules/mediacapabilities/NavigatorMediaCapabilities.h:
* Source/WebCore/Modules/mediacapabilities/WorkerNavigatorMediaCapabilities.cpp:
(WebCore::WorkerNavigatorMediaCapabilities::WorkerNavigatorMediaCapabilities):
(WebCore::WorkerNavigatorMediaCapabilities::from):
* Source/WebCore/Modules/mediacapabilities/WorkerNavigatorMediaCapabilities.h:

Canonical link: https://commits.webkit.org/315088@main
@pgorszkowski-igalia

Copy link
Copy Markdown

The backport of this change from upstream is here: #1687. I close this.

pgorszkowski-igalia added a commit that referenced this pull request Jun 12, 2026
…before its navigator object

https://bugs.webkit.org/show_bug.cgi?id=315684

Reviewed by Ryosuke Niwa.

navigator.mediaCapabilities wrapper should not become GC-collectable before its navigator object.
The MediaCapabilities interface is annotated [SameObject] in the spec:
https://www.w3.org/TR/media-capabilities/#idl-index
It means that navigator.mediaCapabilities must return the same object on every access.

See: #1678

Original author: Andrzej Surdej (https://github.com/asurdej-comcast)

Updated existing LayoutTest with mediaCapabilities case.

* LayoutTests/fast/dom/navigator-property-gc-after-frame-detach-expected.txt:
* LayoutTests/fast/dom/navigator-property-gc-after-frame-detach.html:
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:
(WebCore::MediaCapabilities::MediaCapabilities):
(WebCore::MediaCapabilities::navigator):
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.h:
(WebCore::MediaCapabilities::create):
* Source/WebCore/Modules/mediacapabilities/MediaCapabilities.idl:
* Source/WebCore/Modules/mediacapabilities/NavigatorMediaCapabilities.cpp:
(WebCore::NavigatorMediaCapabilities::NavigatorMediaCapabilities):
(WebCore::NavigatorMediaCapabilities::from):
* Source/WebCore/Modules/mediacapabilities/NavigatorMediaCapabilities.h:
* Source/WebCore/Modules/mediacapabilities/WorkerNavigatorMediaCapabilities.cpp:
(WebCore::WorkerNavigatorMediaCapabilities::WorkerNavigatorMediaCapabilities):
(WebCore::WorkerNavigatorMediaCapabilities::from):
* Source/WebCore/Modules/mediacapabilities/WorkerNavigatorMediaCapabilities.h:

Canonical link: https://commits.webkit.org/315088@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants