Skip to content

Commit

Permalink
Always use container's address, if we can. Fixes #620.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Oct 9, 2024
1 parent 241b342 commit 21e3355
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions object_goreflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func (o *objectGoReflect) _getMethod(jsName string) reflect.Value {

func (o *objectGoReflect) elemToValue(ev reflect.Value) (Value, reflectValueWrapper) {
if isContainer(ev.Kind()) {
if ev.CanAddr() {
ev = ev.Addr()
}
ret := o.val.runtime.toValue(ev.Interface(), ev)
if obj, ok := ret.(*Object); ok {
if w, ok := obj.self.(reflectValueWrapper); ok {
Expand Down
20 changes: 20 additions & 0 deletions object_goreflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,3 +1665,23 @@ func TestGoReflectUnexportedEmbedStruct(t *testing.T) {
})
}
}

func TestNestedSliceAddr(t *testing.T) {
type document struct {
Items []any
}

var d document
runtime := New()
runtime.Set("d", &d)

_, err := runtime.RunString(`
d.Items.push("Hello");
`)
if err != nil {
t.Fatal(err)
}
if len(d.Items) != 1 || d.Items[0] != "Hello" {
t.Fatal(d.Items)
}
}

0 comments on commit 21e3355

Please sign in to comment.