Skip to content

"JavaScript error: ap.$get is not a function" while parsing JSON #662

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

Open
FlorianUekermann opened this issue Jul 26, 2017 · 7 comments · May be fixed by #718
Open

"JavaScript error: ap.$get is not a function" while parsing JSON #662

FlorianUekermann opened this issue Jul 26, 2017 · 7 comments · May be fixed by #718
Assignees

Comments

@FlorianUekermann
Copy link

FlorianUekermann commented Jul 26, 2017

Code: https://gopherjs.github.io/playground/#/cCUnbhmC8q

func main() {
	var v map[string][2]float64
	var err = json.Unmarshal([]byte(`{"a": [350, 350]}`), &v)
	fmt.Println(err)
}

Browser: Chrome Version 59.0.3071.115 (Official Build) (64-bit) on Linux
Result: JavaScript error: ap.$get is not a function
Expected Result: <nil>
Making the array a slice fixes the problem.

@dmitshur
Copy link
Member

Thanks for reporting, that looks like a bug in the type system. /cc @neelance

@FlorianUekermann
Copy link
Author

Both of these lines fail too:

fmt.Println(map[string][2]float64{"a": {1, 2}})
fmt.Println(map[[2]float64]string{{1, 2}: "a"})

So I guess it is reflection related problem.
I haven't been able to reproduce it without a map or array (using a slice in place of either works fine).

@FlorianUekermann
Copy link
Author

FlorianUekermann commented Jul 27, 2017

This is as far as I get in terms of a minimal reproducer:
reflect.ValueOf(map[string][2]float64{"a": {1, 2}}).MapIndex(reflect.ValueOf("a"))
The result is: panic: an.$set is not a function

If the map does not contain a value for the requested key this does not panic. Which makes me wonder if I missed some way of crashing using reflect only on [2]float64, but I couldn't find one.

@hajimehoshi
Copy link
Member

There is the case that a value's ptr is a JavaScript native array and the kind is $kindArray, and mapassign accepts a native array and fails to call its $get function, which doesn't exist. When is a $kindArray value's ptr is a native array?

@hajimehoshi
Copy link
Member

Perhaps, ptr member in reflect package's Value and ptr variable set at $newType are confused at SetMapIndex and mapassign?

@hajimehoshi
Copy link
Member

hajimehoshi commented Nov 7, 2017

Perhaps, ptr member in reflect package's Value and ptr variable set at $newType are confused at SetMapIndex and mapassign?

The above guess might be wrong. Please ignore...

My understanding is: https://gopherjs.github.io/playground/#/3BcYDllnf7

EDIT: My question: it is assumed that $get can be called from a given unsafe.Pointer value to mapassign. Is this assumption correct?

@nevkontakte
Copy link
Member

It appears that this is no longer reproducible in the current GopherJS 1.16.x versions. Please feel free to reopen if I'm mistaken.

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

Successfully merging a pull request may close this issue.

5 participants