We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FinalizationRegistry.register() call missing in exported rust types that define a constructor, preventing cleanup.
FinalizationRegistry.register()
test/api.rs
#[wasm_bindgen] pub struct ObjectWithConstructor {} #[wasm_bindgen] impl ObjectWithConstructor { #[wasm_bindgen(constructor)] pub fn new() -> Self { Self {} } }
Run tests to generate JS code
View generated JS code:
const ObjectWithConstructorFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_objectwithconstructor_free(ptr >>> 0)); /** */ class ObjectWithConstructor { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ObjectWithConstructorFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_objectwithconstructor_free(ptr); } /** */ constructor() { const ret = wasm.objectwithconstructor_new(); this.__wbg_ptr = ret >>> 0; return this; } } module.exports.ObjectWithConstructor = ObjectWithConstructor;
I expect there to be a line in the constructor to register, e.g. ObjectWithConstructorFinalization.register(this, this.__wbg_ptr, this);
ObjectWithConstructorFinalization.register(this, this.__wbg_ptr, this);
In the ObjectWithConstructor code, there is never a call to register the object destruction callback.
ObjectWithConstructor
If we compare to this object, which does not define a constructor:
#[wasm_bindgen] pub struct ObjectNoConstructor {} #[wasm_bindgen] impl ObjectNoConstructor { pub fn new() -> Self { Self {} } }
It has a register call in the __wrap function:
register
__wrap
const ObjectNoConstructorFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_objectnoconstructor_free(ptr >>> 0)); /** */ class ObjectNoConstructor { constructor() { throw new Error('cannot invoke `new` directly'); } static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(ObjectNoConstructor.prototype); obj.__wbg_ptr = ptr; ObjectNoConstructorFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ObjectNoConstructorFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_objectnoconstructor_free(ptr); } /** * @returns {ObjectNoConstructor} */ static new() { const ret = wasm.objectnoconstructor_new(); return ObjectNoConstructor.__wrap(ret); } } module.exports.ObjectNoConstructor = ObjectNoConstructor;
Should the register call be generated here?
The text was updated successfully, but these errors were encountered:
I'm not familiar with this part of the code, but whats missing is a call to Context::require_class_wrap().
Context::require_class_wrap()
Happy to dig into it if a PR is provided.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Describe the Bug
FinalizationRegistry.register()
call missing in exported rust types that define a constructor, preventing cleanup.Steps to Reproduce
test/api.rs
:Run tests to generate JS code
View generated JS code:
Expected Behavior
I expect there to be a line in the constructor to register, e.g.
ObjectWithConstructorFinalization.register(this, this.__wbg_ptr, this);
Actual Behavior
In the
ObjectWithConstructor
code, there is never a call to register the object destruction callback.If we compare to this object, which does not define a constructor:
It has a
register
call in the__wrap
function:Additional Context
Should the register call be generated here?
The text was updated successfully, but these errors were encountered: