Support per-operation [WbgGeneric] in WebIDL codegen#5026
Merged
Conversation
Contributor
Author
|
//cc @evilpie added a correction to the generation here |
a42880f to
fe8d9b6
Compare
drewcrawford
reviewed
Mar 7, 2026
fe8d9b6 to
3e4b61f
Compare
The [WbgGeneric] extended attribute was only supported on interface, dictionary, and namespace definitions. When VideoFrame was stabilized, the createImageBitmap overloads on Window and WorkerGlobalScope lost their typed generic return type (Promise<ImageBitmap> became bare Promise) because the parent mixin/interface did not have [WbgGeneric]. Add support for [WbgGeneric] on individual WebIDL operations. The operation's extended attributes (stored in Signature.attrs) are now checked and OR'd with the parent definition's wbg_generic flag during code generation. Also fix return type WbgType expansion to respect wbg_generic for callback-like return types. Previously next_unstable was only set temporarily during argument expansion but not when computing the return type in create_method. Add [WbgGeneric] to the two createImageBitmap operations in WindowOrWorkerGlobalScope to restore Promise<ImageBitmap> return types.
3e4b61f to
a58615c
Compare
Contributor
Author
|
Ping @drewcrawford @RReverser for reviews here. |
Merged
This was referenced Mar 31, 2026
guybedford
added a commit
that referenced
this pull request
Mar 31, 2026
Merged
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.
Summary
[WbgGeneric]on individual WebIDL operations (not just interface/dictionary/namespace definitions), so that specific methods can opt into typed generics without affecting all sibling methods.WbgTypeexpansion to respectwbg_genericfor callback-like return types. Previouslynext_unstablewas only set temporarily during argument expansion but not when computing the return type increate_method.[WbgGeneric]to the twocreateImageBitmapoperations inWindowOrWorkerGlobalScope, restoringPromise<ImageBitmap>return types onWindowandWorkerGlobalScope.Motivation
When
VideoFramewas stabilized in ce535e1, thecreateImageBitmapoverloads acceptingVideoFrameonWindow/WorkerGlobalScopelost their typed generic return type (Promise<ImageBitmap>became barePromise). Previously these methods were unstable (gated behindweb_sys_unstable_apis) which automatically gave them generics. After stabilization, the parentWindowOrWorkerGlobalScopemixin has no[WbgGeneric], so generics were lost.Adding
[WbgGeneric]to the entire mixin was too broad — it changedsetTimeout,setInterval,fetch, etc. Per-operation support allows targeting only the affected methods.Changes
crates/webidl/src/util.rs:Signature.attrsfor[WbgGeneric]and OR it with the parent definition'swbg_genericflag in two places: when settingnext_unstablefor argument type expansion, and when passingwbg_generictocreate_method.create_method, temporarily setnext_unstablearound the return typeto_wbg_typecall whenwbg_genericorunstable_flagis true, so that callback-like return types also get typed expansion.crates/web-sys/webidls/enabled/WindowOrWorkerGlobalScope.webidl: AddWbgGenericto the twocreateImageBitmapoperation attributes.crates/web-sys/src/features/gen_Window.rs,gen_WorkerGlobalScope.rs: Regenerated —createImageBitmapoverloads now returnPromise<ImageBitmap>.