go-wasm/go-converts/wasm.go

21 lines
314 B
Go
Raw Normal View History

2019-08-23 20:19:32 +03:00
// +build js,wasm
package converts
import "syscall/js"
func ToBytes(v js.Value) []byte {
buf := make([]byte, v.Length(), v.Length())
for i := 0; i < v.Length(); i++ {
2019-09-24 00:23:27 +03:00
sv := v.Index(i)
buf[i] = byte(sv.Int())
2019-08-23 20:19:32 +03:00
}
return buf
}
2019-09-24 00:23:27 +03:00
// Free frees the value for GC
func free(v js.Value) {
v.Call("_release_")
}