Go version

latest

Output of go env in your module/workspace:

not necessary

What did you do?

I tried building a wasm executable for go GOOS=js GOARCH=wasm GOHOSTOS=darwin GOHOSTARCH=arm64 GO_BUILDER_NAME=js_wasm ./bootstrap.bash

What did you see happen?

When _makeFuncWrapper is called, the this field in the event is taken within the anonymous function context, which sets it to undefined.

What did you expect to see?

Since there is already const go = this outside of this lambda, then I guess that is what needs to be used.

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: dmitshur

Thanks for reporting. What is the ./bootstrap.bash script? Does this also happen if you build a wasm binary with GOOS=js GOARCH=wasm go build?

CC @golang/js, @golang/wasm.

Comment From: Zxilly

I think it's bootstrap.bash and the user wants to compile the go compiler itself to wasm. I will look into this issue later.

Comment From: Zxilly

I don't think it's an issue, and the patch doesn't look right either. As syscall/js/func.go described, fn is called with the value of JavaScript's "this" keyword.

For example, in a DOM event handler like button.onclick = myGoFunc;, the Go code correctly expects this to be the button, but this change would incorrectly provide the Go helper object instead.

Are there any other issues preventing you from compiling the Go compiler itself to WASM? This fix seems unrelated to the initial issue.