go: wasm: global functions from wasm not working from node

What version of Go are you using (go version)?

$ go version
go version go1.12beta2 Darwin/amd64

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

The go.run(result.instance); is returning earlier than you expect. If you do this:

	fmt.Println("loading")
	fmt.Println("loading 2")
	js.Global().Set("add", js.FuncOf(add))

then you get:

loading
(node:85999) UnhandledPromiseRejectionWarning: TypeError: global.add is not a function
    at WebAssembly.instantiate.then (/Users/richard/Repos/go-node-wasm/src/node/wasm_exec.js:506:28)
loading 2

Instead, have your Go code call some JS global after it is done with setup.