Skip to content

syscall/js: add Scope function #56084

Open
@romaindoumenc

Description

@romaindoumenc

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:

  1. Passing an optional scope argument to the Go constructor, which can be an arbitrary object. This object is then exposed to the js / Go interface.
  2. This scope object is made available as a Scope() top-level function in the syscall/js package
  3. 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

No one assigned

    Type

    No type

    Projects

    Status

    Accepted

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions