You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining methods on a rust struct that you want to be exported with wasm-bindgen, if you define the arguments as self: &Self then when called from JS, the JS pointer gets nulled out after calling that method instead of the expected behaviour of the pointer staying valid. If you intead define the arguments as &self then it works as expected.
Steps to Reproduce
Here is a minimal example of the code not working.
When this is run, the JS code errors at test.method_2() "Error importing index.js: Error: null pointer passed to". We can see from the log that the internal wasm pointer goes from a valid number to 0 after the test.method() call.
Describe the Bug
When defining methods on a rust struct that you want to be exported with wasm-bindgen, if you define the arguments as
self: &Self
then when called from JS, the JS pointer gets nulled out after calling that method instead of the expected behaviour of the pointer staying valid. If you intead define the arguments as&self
then it works as expected.Steps to Reproduce
Here is a minimal example of the code not working.
The rust code:
JS Code:
When this is run, the JS code errors at
test.method_2()
"Error importingindex.js
: Error: null pointer passed to". We can see from the log that the internal wasm pointer goes from a valid number to 0 after thetest.method()
call.If we change the rust code to:
(Just replacing
self: &Self
with&self
)Then both methods pass and no pointers are nulled out.
Expected Behavior
I would expect both pieces of rust code to behave the same, and the first definition shouldn't null pointers after calling each method.
Actual Behavior
The first method nulls the pointer after each method called on the struct.
Additional Context
This was run with wasm-bindgen version of "0.2.84" on Linux Ubuntu. I started with the hello wasm-pack template
The text was updated successfully, but these errors were encountered: