Open
Description
The current syscall/js
package allow to interact with the global object (globalThis
) only.
This has been reported as a problem in multiple instances, e.g. - #25612. Solutions to the problem have been so far in the “big stones” range (e.g. adopting ABI, …).
This proposal, instead, is squarely in the “small stone” category, but has worked well for us (using Go + WASM as a Web UI component), making sure that we are able to export functions in a limited scope only.
The proposal is two-and-an-optional fold:
- Passing an optional
scope
argument to theGo
constructor, which can be an arbitrary object. This object is then exposed to the js / Go interface. - This
scope
object is made available as aScope()
top-level function in thesyscall/js
package - Since we are opening up that hatch, we also allow an optional array to contain environment variables, that allow caller to explicitly pass some extra arguments to the WASM code.
PR attach demonstrate the solution, that (seems to be) fully functional.
I’d like to the gauge the maintainers interest for a solution like this?
Many thank.
Metadata
Metadata
Assignees
Type
Projects
Status
Accepted