New issue
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
wasm: global functions from wasm not working from node #29845
Comments
@neelance you might know if that's a user error, a missing feature or a bug. Any feedback or pointer to solve the challenge for would be greatly appreciated. |
I believe this is something that you are trying to do ?
Now from JS, call myFunc(). |
@agnivade that's exact what I do, but |
Ah yes, that just might be the case. In the browser, we have |
In Node.js the global object is called |
So then shouldn't |
It might be better to have a look at https://github.com/tc39/proposal-global. |
Yes. |
But that's not what's happening
That is why I thought setting an object in the But if that's supposed to work, then I am not sure why |
It should definitely be possible to call |
I was traveling with very limited internet and could not upload a repro case. I did test calling |
@neelance here is the repro example: https://github.com/mattetti/go-node-wasm The main Go file is here: https://github.com/mattetti/go-node-wasm/blob/master/src/wasm/main.go To run the code I use the following command: GOOS=js GOARCH=wasm go run -exec=./src/node/go_js_wasm_exec ./src/wasm/main.go Error:
|
The
then you get:
Instead, have your Go code call some JS global after it is done with setup. |
@neelance thanks for looking into my issue. Moving the js global declaration into init() did indeed solve the declaration problem. Is that the expected behavior tho? I'm going to eventually update the wiki and I'm curious to know if that's a side effect of the implementation, that might be revisited or if that pattern is the definite medium term answer. |
Using In general you are not supposed to modify |
@neelance I still don't quite understand the issue and agree that it would be best to not have to modify |
Essentially your JS code has to wait until your Go code is done with preparations. Btw: Have you joined the #webassembly channel on the Gophers Slack? You can also get advice there. |
Went there and got great feedback, what I was missing was how to let the js code know that the go code is ready. This comment is meant to help anyone finding this issue: Agniva De Sarker shared the following solution: So currently, your JS code starts after In your main.go, do this -
And have this at the start of wasm_exec.js
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
I am trying to call registered functions (aka callbacks) defined in the WebAssembly file from node js. I use the provided wasm_exec.js which does call into the main function without any issues. From what I could gather, we are missing a way to expose the registered functions in JS. But unfortunately I am not familiar enough with the implementation details nor did I find a lot of information online on the matter.
What did you expect to see?
I expected to be able to call my exposed functions from js outside of the browser.
What did you see instead?
A js exception
The text was updated successfully, but these errors were encountered: