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: ValueOf
should accept []js.Value
and map[string]js.Value
as analogs of []any
and map[string]any
#60335
Comments
Change https://go.dev/cl/496816 mentions this issue: |
I wonder if the rules could be extended to work with any slice or map where the element type is supported, like |
@mvdan I think it would make sense from a UX with dealing with a dynamically typed language point of view, however this adds lots of various implications (I can think about: I don't actually think this would be good, it would be surprising to have widely different performance depending on codepath taken. |
Looking at how this is currently implemented, I guess this would be a pair of new case []Value:
a := arrayConstructor.New(len(x))
for i, s := range x {
a.SetIndex(i, s)
}
return a
case map[string]Value:
o := objectConstructor.New()
for k, v := range x {
o.Set(k, v)
}
return o This relies on the fact that It could potentially be optimized to directly call the internal Seems like a nice combination of more convenient usage and an opportunity for a potential optimization! (I've not measured whether the optimization is significant, though.) |
@apparentlymart Accounting for inlining I implemented all of the optimisations you layed out: https://go.dev/cl/496816. |
ValueOf
right now convertsjs.Value
as[its value]
.So I naively assumed I could write this code:
However it doesn't, I have to write this instead:
This just looks silly, I guess it also have a performance impact but it's not like
syscall/js.ValueOf
is particularly fast anyway.I propose this change to it's behaviour:
The text was updated successfully, but these errors were encountered: