Skip to content

fix: use aliased class identifier for FinalizationRegistry in constructors#4932

Merged
logan-gatlin merged 2 commits intomainfrom
fix-finalization-registry-alias
Feb 4, 2026
Merged

fix: use aliased class identifier for FinalizationRegistry in constructors#4932
logan-gatlin merged 2 commits intomainfrom
fix-finalization-registry-alias

Conversation

@guybedford
Copy link
Contributor

Summary

Fixes #4885

When a Rust struct has a name that conflicts with a JS builtin (e.g., Array), wasm-bindgen aliases the class name (e.g., Array2). However, the constructor was incorrectly referencing the unaliased FinalizationRegistry name (ArrayFinalization instead of Array2Finalization), causing a ReferenceError at runtime.

Changes

  • Added require_class_identifier() helper method in mod.rs to get the (potentially aliased) JS identifier for a class
  • Modified binding.rs to use the aliased identifier when generating the FinalizationRegistry.register() call in constructors
  • Added test case reserved-class-name.rs that reproduces the issue by importing JS's Array and defining a Rust struct also named Array
  • Updated default-class.bg.js reference (this was also affected - _default class was using defaultFinalization instead of _defaultFinalization)

Testing

  • All 43 reference tests pass
  • All 31 cli-support tests pass

…ctors

When a Rust struct has a name that conflicts with a JS builtin (e.g.,
`Array`), wasm-bindgen aliases the class name (e.g., `Array2`). However,
the constructor was incorrectly referencing the unaliased FinalizationRegistry
name (`ArrayFinalization` instead of `Array2Finalization`), causing a
ReferenceError at runtime.

This fix ensures the constructor uses the same aliased identifier for the
FinalizationRegistry as the rest of the generated class code.

Fixes #4885
@guybedford guybedford force-pushed the fix-finalization-registry-alias branch from 6cddfa8 to 9683446 Compare February 3, 2026 22:16
@logan-gatlin
Copy link
Contributor

LGTM

@logan-gatlin logan-gatlin merged commit c70d300 into main Feb 4, 2026
59 checks passed
@logan-gatlin logan-gatlin deleted the fix-finalization-registry-alias branch February 4, 2026 17:48
@guybedford guybedford mentioned this pull request Feb 20, 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.

ReferenceError: ArrayFinalization is not defined

2 participants