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

syscall/js: ValueOf should not panic if the underlying type(kind) is supported #42188

Closed
mihaiav opened this issue Oct 24, 2020 · 5 comments
Closed
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

Comments

@mihaiav
Copy link

mihaiav commented Oct 24, 2020

What version of Go are you using (go version)?

$ go version devel +dd150176c3 Fri Jul 3 03:31:29 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
darwin x64

What did you do?

package main
import "syscall/js"

func main(){
type X string
x := X("hello")
v := js.ValueOf(x)
}

What did you expect to see?

x being converted to a js value.

What did you see instead?

panic: ValueOf: invalid value

I believe this is due the fact that the string value passed on is a typed. Therefore this is a feature/improvement request to make ValueOf accept values whose underlying type matches the accepted types.

@mihaiav mihaiav changed the title syscall/js ValueOf should not panic if the underlying type is supported syscall/js ValueOf should not panic if the underlying type(kind) is supported Oct 24, 2020
@dmitshur dmitshur changed the title syscall/js ValueOf should not panic if the underlying type(kind) is supported syscall/js: ValueOf should not panic if the underlying type(kind) is supported Oct 24, 2020
@dmitshur dmitshur added arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 24, 2020
@dmitshur dmitshur added this to the Backlog milestone Oct 24, 2020
@dmitshur
Copy link
Contributor

CC @neelance.

@neelance
Copy link
Member

This would require a dependency from syscall/js to reflect, which is at least something that we definitely want to avoid or maybe even impossible to do.

@dmitshur
Copy link
Contributor

@neelance Have you also considered internal/reflectlite?

@neelance
Copy link
Member

At first glance it seems like it wouldn't be able to turn type X string into a plain string.

@neelance
Copy link
Member

neelance commented Nov 5, 2020

I'll close this issue for now, since it is very unlikely to happen due to the necessary reflect dependency. I also think that since syscall/js is a very low-level package, there need to be intermediate layers that hide it from user code and offer a nicer interface than syscall/js ever could.

@neelance neelance closed this as completed Nov 5, 2020
@golang golang locked and limited conversation to collaborators Nov 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.
Projects
None yet
Development

No branches or pull requests

4 participants