fix: use aliased class identifier for FinalizationRegistry in constructors#4932
Merged
logan-gatlin merged 2 commits intomainfrom Feb 4, 2026
Merged
fix: use aliased class identifier for FinalizationRegistry in constructors#4932logan-gatlin merged 2 commits intomainfrom
logan-gatlin merged 2 commits intomainfrom
Conversation
…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
6cddfa8 to
9683446
Compare
Contributor
|
LGTM |
logan-gatlin
approved these changes
Feb 4, 2026
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
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 (ArrayFinalizationinstead ofArray2Finalization), causing aReferenceErrorat runtime.Changes
require_class_identifier()helper method inmod.rsto get the (potentially aliased) JS identifier for a classbinding.rsto use the aliased identifier when generating theFinalizationRegistry.register()call in constructorsreserved-class-name.rsthat reproduces the issue by importing JS'sArrayand defining a Rust struct also namedArraydefault-class.bg.jsreference (this was also affected -_defaultclass was usingdefaultFinalizationinstead of_defaultFinalization)Testing