Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support per-operation [WbgGeneric] in WebIDL codegen#5026

Merged
guybedford merged 1 commit into
mainfrom
fix-wbg-generic-mixin
Mar 10, 2026
Merged

Support per-operation [WbgGeneric] in WebIDL codegen#5026
guybedford merged 1 commit into
mainfrom
fix-wbg-generic-mixin

Conversation

@guybedford

@guybedford guybedford commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add support for [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.
  • 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, restoring Promise<ImageBitmap> return types on Window and WorkerGlobalScope.

Motivation

When VideoFrame was stabilized in ce535e1, the createImageBitmap overloads accepting VideoFrame on Window/WorkerGlobalScope lost their typed generic return type (Promise<ImageBitmap> became bare Promise). Previously these methods were unstable (gated behind web_sys_unstable_apis) which automatically gave them generics. After stabilization, the parent WindowOrWorkerGlobalScope mixin has no [WbgGeneric], so generics were lost.

Adding [WbgGeneric] to the entire mixin was too broad — it changed setTimeout, setInterval, fetch, etc. Per-operation support allows targeting only the affected methods.

Changes

crates/webidl/src/util.rs:

  • Check Signature.attrs for [WbgGeneric] and OR it with the parent definition's wbg_generic flag in two places: when setting next_unstable for argument type expansion, and when passing wbg_generic to create_method.
  • In create_method, temporarily set next_unstable around the return type to_wbg_type call when wbg_generic or unstable_flag is true, so that callback-like return types also get typed expansion.

crates/web-sys/webidls/enabled/WindowOrWorkerGlobalScope.webidl: Add WbgGeneric to the two createImageBitmap operation attributes.

crates/web-sys/src/features/gen_Window.rs, gen_WorkerGlobalScope.rs: Regenerated — createImageBitmap overloads now return Promise<ImageBitmap>.

@guybedford

Copy link
Copy Markdown
Contributor Author

//cc @evilpie added a correction to the generation here

@guybedford guybedford force-pushed the fix-wbg-generic-mixin branch from a42880f to fe8d9b6 Compare March 7, 2026 02:47
@guybedford guybedford changed the title Propagate [WbgGeneric] from mixins to interface members Support per-operation [WbgGeneric] in WebIDL codegen Mar 7, 2026

@drewcrawford drewcrawford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC,

Comment thread crates/webidl/src/lib.rs Outdated
Comment thread crates/webidl/src/util.rs
@guybedford guybedford force-pushed the fix-wbg-generic-mixin branch from fe8d9b6 to 3e4b61f Compare March 7, 2026 04:41
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.
@guybedford guybedford force-pushed the fix-wbg-generic-mixin branch from 3e4b61f to a58615c Compare March 7, 2026 04:52
@guybedford

Copy link
Copy Markdown
Contributor Author

Ping @drewcrawford @RReverser for reviews here.

@drewcrawford drewcrawford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@guybedford guybedford merged commit df2bda0 into main Mar 10, 2026
62 checks passed
@guybedford guybedford deleted the fix-wbg-generic-mixin branch March 10, 2026 19:42
@guybedford guybedford mentioned this pull request Mar 26, 2026
@guybedford guybedford mentioned this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants