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 (
)
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
main.js:2622 result is not nil
If I do a s/*js.Error/*js.Object/ in main.go, I get the expected result:
null
main.js:2622result 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?