Skip to content
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

proposal: syscall/js: allow []float32 or other typed arrays to pass to js.ValueOf #25532

Closed
hajimehoshi opened this issue May 24, 2018 · 8 comments
Milestone

Comments

@hajimehoshi
Copy link
Member

This would be useful for WebGL functions: for example, uniformMatrix4fv accepts Float32Array at the third argument.

(This issue is copied from https://github.com/neelance/go/issues/19)

@gopherbot gopherbot added this to the Proposal milestone May 24, 2018
@bradfitz bradfitz added the arch-wasm WebAssembly issues label May 24, 2018
@neelance
Copy link
Member

@bradfitz and the Go team: How do you generally approach the question of whether to add some new API or not? What are the characteristics of idiomatic Go APIs?

@bradfitz
Copy link
Contributor

Well, if syscall/js has no API compatibility promises, it's less of an issue.

I can't possibly list all the characteristics of idiomatic Go APIs briefly here in a comment. Basically it needs to look & feel like everything else in the standard library. But I see no reason we shouldn't be able to pass a []float32 to JavaScript. reflect.ValueOf supports it, of course.

@rsc
Copy link
Contributor

rsc commented Jun 4, 2018

/cc @cherrymui

@hajimehoshi
Copy link
Member Author

What's going on this?

@ianlancetaylor
Copy link
Contributor

It seems fine to add other types as long as they are unambiguous and useful. Should we extend the set of supported types to include slices of all supported types? Will passing a slice always imply copying all the elements?

@hajimehoshi
Copy link
Member Author

hajimehoshi commented Jun 19, 2018

Should we extend the set of supported types to include slices of all supported types?

I think supporting TypedArray (e.g. Float32Array for []float32) is enough.

Will passing a slice always imply copying all the elements?

What about []byte? Is it copied?

@neelance
Copy link
Member

There is no copying from []byte to Uint8Array. The Uint8Array is backed by the section of the WebAssembly linear memory which holds the data of the []byte.

I agree that we should add the other typed arrays (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).

@gopherbot
Copy link

Change https://golang.org/cl/121215 mentions this issue: syscall/js: add support for all typed arrays

@golang golang locked and limited conversation to collaborators Jun 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants