-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
syscall/js: add Scope function #56084
Comments
CC @neelance |
This proposal has been added to the active column of the proposals project |
In general, adding I would prefer to not add arguments to the constructor, but set it as a field before calling go.scope = ...; similar to go/misc/wasm/wasm_exec_node.js Lines 33 to 36 in 5b606a9
|
Sure, either interface is fine (and, the JS side is not the most complicated to change anyway). Based on the expressed interest, I’m happy to try to move this proposal forward, and commit it upstream. |
It sounds like the proposal is that on the JS side the go object gets a new field 'scope' that is checked, and on the Go side, in package syscall/js, Are there any changes to what js.Global returns? The attached PR changes the comments but does not seem to update the behavior to match. |
My bad, this is a leftover from a first stab at it (where we tried re-using the global object and overriding it with a scope). Turns out, even with a scope, you still need the global object: e.g. in the browser, some events are only relevant on the Which is a long-winded answer to say: sorry, ignore the comment, it went in by mistake. |
OK, so the proposal is:
Does anyone object to this proposal? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/452356 mentions this issue: |
@neelance : do you think we could get the review unlock for the 1.21 window? Thanks! |
Fixes golang#56084 This changes allow to pass an arbitrary object from the JS world to the WASM program. - if no object is provided, globalThis is returned instead. - the scope object is derive from internal jsGo object, avoiding a possible ID clash when the scope is unset (so left as globalThis) - test uses a dummy object to perform a simple get/set action. Change-Id: I71afd43f6b32d04b76c3760ac5b2cb6c0c9dbd73 GitHub-Last-Rev: 44a0f15 GitHub-Pull-Request: golang#56867
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:
scope
argument to theGo
constructor, which can be an arbitrary object. This object is then exposed to the js / Go interface.scope
object is made available as aScope()
top-level function in thesyscall/js
packagePR 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.
The text was updated successfully, but these errors were encountered: