Open
Description
I originally asked about this on the Google Group, but GH seems to be more active, so I'm re-posting here (plus markdown!!)
I'm not sure if I've run into a bug, or if I'm misusing GopherJS, but I've run into a problem with the way my Go code receives errors passed by Javascript Callbacks. To demonstrate the problem, I've built this code:
My main.js:
window.foo = {
nothing: function(cb) {
return cb(null);
}
}
require('main');
And main.go:
package main
import (
"github.com/gopherjs/gopherjs/js"
"honnef.co/go/js/console"
)
func main() {
result := nothing()
console.Log(result)
if result == nil {
console.Log("result is nil")
}
if result != nil {
console.Log("result is not nil")
}
}
func nothing() *js.Error {
c := make(chan *js.Error)
go func() {
js.Global.Get("foo").Call("nothing",func(err *js.Error) {
c <- err
})
}()
return <-c
}
The output on my javascript console (in Chrome 43, FWIW) is:
null
result is not nil
If I do a s/*js.Error/*js.Object/
in main.go, I get the expected result:
null
result is nil
So it seems that somehow the Error struct around *js.Object is obfuscating the nullness of the javascript object? Am I doing this wrong?
Metadata
Metadata
Assignees
Labels
No labels