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

Panic in JSON.stringify of struct with anonymous pointer field #369

Closed
ale-rinaldi opened this issue Feb 3, 2020 · 1 comment · Fixed by #370
Closed

Panic in JSON.stringify of struct with anonymous pointer field #369

ale-rinaldi opened this issue Feb 3, 2020 · 1 comment · Fixed by #370

Comments

@ale-rinaldi
Copy link
Contributor

If I have a struct with an anonymous pointer field, I pass it to the VM, and try to JSON.stringify it, I get a panic.

An easy way to reproduce is running this code:

package main

import (
	"github.com/robertkrimen/otto"
)

func main() {
	type Test struct {
		Value string
	}

	type PtrTest struct {
		*Test
	}

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

	ptrTestItem := PtrTest{
		Test: &testItem,
	}

	jsCode := `
		console.log(JSON.stringify(testVariable));
	`

	vm := otto.New()
	vm.Set("testVariable", ptrTestItem)
	vm.Run(jsCode)
}
@ale-rinaldi
Copy link
Contributor Author

Pull request #370 seems to solve the issue with no apparent regressions, but since I don't know why the f.Anonymous check was in place, I'm not sure that's the right solution.

sg3des pushed a commit to sg3des/otto that referenced this issue Jul 17, 2023
Fix panic when handling a pointer to a struct.

Fixes robertkrimen#369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant