wasm: No support for converting JS arrays into Go equivalent (inverse of TypedArrayOf()) #31335
Labels
arch-wasm
WebAssembly issues
FeatureRequest
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
This isn't a bug, but rather a WASM
syscall/js
feature suggestion. Whilesyscall/js
offers extremely helpful functionality for converting Go slices into JS arrays (specifically, funcTypedArrayOf()
), support for the inverse doesn't exist. This means that, to read a JS array passed into a Go function as ajs.Value
, one has the following options:unsafe
package to directly access theref
field injs.Value
and use thejs.Value
's length to directly access the bytes starting atref
. Not ideal--requires usingreflect
to accessref
, which is a private field.As a result, passing JS arrays into Go functions in WASM requires extra lift and could benefit from an efficient JS array-to-Go slice conversion.
Check out the example code in
https://github.com/gabbifish/go-wasm-example/blob/master/main.go#L41-L53
What did you expect to see?
Support for converting JS arrays into Go arrays, given that the inverse logic already exists.
What did you see instead?
^ A hope that this functionality can be offered in Go WASM support in the future :) If there is interest, I'd be happy to work on a PR implementing functionality along these lines.
The text was updated successfully, but these errors were encountered: