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

Fix ptr slices assertions in js nk module arguments #1150

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

sesposito
Copy link
Member

Goja introduced the following change:
dop251/goja@7749907 JS arrays backed by a Go slice referenced by a pointer would be returned by .Export() as []S, but now are returned as *[]S which requires changing all the type assertions when dealing with these values.

Goja introduced the following change:
dop251/goja@7749907
JS arrays backed by a Go slice referenced by a pointer would be
returned by .Export() as []S, but now are returned as *[]S which requires
changing all the type assertions when dealing with these values.
panic(r.NewTypeError("Invalid argument - user ids must be an array."))
userIDsIn := f.Argument(2)
if userIDsIn != goja.Undefined() && userIDsIn != goja.Null() {
userIDs, err = exportToSlice[[]string](userIDsIn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a very minor suggestion but it might be worthwhile to panic inside the exportToSlice and avoid error checks in all these multiple places. Providing, of, course it's supposed to panic in every case when invoking this func.

Copy link
Member Author

@sesposito sesposito Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered it but then thought it would be best to keep both the panics more explicit and the custom error messages as they may be more meaningful to the user.

@sesposito
Copy link
Member Author

I added a commit as I had missed a few .Export() calls that needed patching.

@sesposito sesposito merged commit 9c13253 into master Dec 11, 2023
3 checks passed
@sesposito sesposito deleted the spe/js-param-handling-fixes branch December 11, 2023 10:28
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 this pull request may close these issues.

3 participants