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

syscall/js: panic: not a number #26170

Closed
agnivade opened this issue Jul 1, 2018 · 6 comments
Closed

syscall/js: panic: not a number #26170

agnivade opened this issue Jul 1, 2018 · 6 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@agnivade
Copy link
Contributor

agnivade commented Jul 1, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +6780042 Sun Jul 1 08:07:47 2018 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/agniva/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/agniva/play/go"
GOPROXY=""
GORACE=""
GOROOT="/home/agniva/play/gosource/go"
GOTMPDIR=""
GOTOOLDIR="/home/agniva/play/gosource/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build501975403=/tmp/go-build -gno-record-gcc-switches"
VGOMODROOT=""

What did you do?

I tried to rebuild my app after all the new changes in master. The app responds to events from input[type=range] and acts accordingly.

When I try to take the .Float() of the js.Value, I get the above-mentioned panic. The value is a perfectly fine float. And it even works fine if I take .String() and do a strconv.ParseFloat of it.

The problem goes away if I go back to the commit before 8997ec1 (syscall/js: use stable references to JavaScript values)

I believe this is an inadvertent mistake, please let me know if I am wrong.

What did you expect to see?

The app to run successfully after moving to new API.

What did you see instead?

panic: syscall/js: not a number
wasm_loader.js:39 
wasm_loader.js:39 goroutine 5 [running]:
wasm_loader.js:39 syscall/js.Value.Float(...)
wasm_loader.js:39 	/home/agniva/play/gosource/go/src/syscall/js/js.go:234
wasm_loader.js:39 main.main.func1(0x7ff8000000000020)
wasm_loader.js:39 	/home/agniva/play/go/src/github.com/agnivade/shimmer/repro.go:12 +0x11
wasm_loader.js:39 syscall/js.NewEventCallback.func1(0xc01e048, 0x1, 0x1)

Very minimal repro, without releasing callbacks -

<label for="contrast">Contrast</label>
<input type="range" min="-1" max="1" value="0" step="0.1" id="contrast">
// +build js,wasm

package main

import (
	"fmt"
	"syscall/js"
)

func main() {
	cb := js.NewEventCallback(js.PreventDefault, func(ev js.Value) {
		// This panics
		delta := ev.Get("target").Get("value").Float()
		fmt.Println(delta)

		// This works
		// deltaStr := ev.Get("target").Get("value").String()
		// delta, err := strconv.ParseFloat(deltaStr, 64)
		// if err != nil {
		// 	fmt.Println(err)
		// 	return
		// }
		// fmt.Println(delta)
	})
	js.Global().Get("document").
		Call("getElementById", "contrast").
		Call("addEventListener", "change", cb)

	select {}
}
@agnivade agnivade added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker arch-wasm WebAssembly issues labels Jul 1, 2018
@agnivade agnivade added this to the Go1.11 milestone Jul 1, 2018
@agnivade
Copy link
Contributor Author

agnivade commented Jul 1, 2018

/cc @neelance

@neelance
Copy link
Member

neelance commented Jul 1, 2018

The value of an <input type="range"> is a string, not a number, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range.

@myitcv
Copy link
Member

myitcv commented Jul 1, 2018 via email

@agnivade
Copy link
Contributor Author

agnivade commented Jul 1, 2018

I see. So it was a mistake earlier ? And strconv.ParseFloat() is the way to go ?

@neelance
Copy link
Member

neelance commented Jul 1, 2018

@agnivade The earlier version did implicit type conversions, which got removed. You can try the valueAsNumber mentioned on the MDN page or strconv.ParseFloat().

@myitcv Yes, that's on my todo list.

@agnivade
Copy link
Contributor Author

agnivade commented Jul 1, 2018

Thanks. Closing.

@agnivade agnivade closed this as completed Jul 1, 2018
@golang golang locked and limited conversation to collaborators Jul 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants