Skip to content

Commit

Permalink
fix: support struct pointers (#370)
Browse files Browse the repository at this point in the history
Fix panic when handling a pointer to a struct.

Fixes #369
  • Loading branch information
ale-rinaldi authored Nov 25, 2022
1 parent 4c46316 commit 37f2928
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,31 @@ func Test_issue266(t *testing.T) {

})
}

func Test_issue369 (t *testing.T) {
tt(t, func() {
test, tester := test()

type Test struct {
Value string
}

type PtrTest struct {
*Test
}

testItem := Test{
Value: "A test value",
}

ptrTestItem := PtrTest{
Test: &testItem,
}

tester.Set("testVariable", ptrTestItem)

test(`
JSON.stringify(testVariable);
`, `{"Test":{"Value":"A test value"}}`)
})
}
3 changes: 3 additions & 0 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func (self *_runtime) convertNumeric(v Value, t reflect.Type) reflect.Value {
}

func fieldIndexByName(t reflect.Type, name string) []int {
for t.Kind() == reflect.Ptr {
t = reflect.ValueOf(t).Elem().Type()
}
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)

Expand Down

0 comments on commit 37f2928

Please sign in to comment.