diff --git a/wasm/e2e.go b/wasm/e2e.go index bc9fe4899a07f7dee3c6fca5692fb1acad744654..aa26323c5e2fd89b7b1840f1d81e46ab07953f57 100644 --- a/wasm/e2e.go +++ b/wasm/e2e.go @@ -192,15 +192,15 @@ type authCallbacks struct { func newAuthCallbacks(value js.Value) *authCallbacks { a := &authCallbacks{} - if value.Get("Request").Type() != js.TypeFunction { + if value.Get("Request").Type() == js.TypeFunction { a.request = WrapCB(value, "Request") } - if value.Get("Confirm").Type() != js.TypeFunction { + if value.Get("Confirm").Type() == js.TypeFunction { a.confirm = WrapCB(value, "Confirm") } - if value.Get("Reset").Type() != js.TypeFunction { + if value.Get("Reset").Type() == js.TypeFunction { a.reset = WrapCB(value, "Reset") } diff --git a/wasm/e2eHandler.go b/wasm/e2eHandler.go index f2e018155bdd169bb4d84bc5840a116d782333c0..045b5447953054f1953c0d06ad87b397e87d8a37 100644 --- a/wasm/e2eHandler.go +++ b/wasm/e2eHandler.go @@ -226,7 +226,7 @@ func (e *E2e) AddService(_ js.Value, args []js.Value) interface{} { // - Throws TypeError if registering the service fails func (e *E2e) RegisterListener(_ js.Value, args []js.Value) interface{} { recipientId := CopyBytesToGo(args[0]) - l := &listener{WrapCB(args[1], "Hear"), WrapCB(args[1], "Name")} + l := &listener{WrapCB(args[2], "Hear"), WrapCB(args[2], "Name")} err := e.api.RegisterListener(recipientId, args[1].Int(), l) if err != nil { diff --git a/wasm/utils.go b/wasm/utils.go index 73dbe40b17b36f42dcf0ed6bf9b0c98678c1e274..4b508d8ac890165853a669fa072ad4ef2fc856cb 100644 --- a/wasm/utils.go +++ b/wasm/utils.go @@ -12,6 +12,7 @@ package wasm import ( "encoding/json" "fmt" + "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "syscall/js" ) @@ -37,8 +38,10 @@ func CopyBytesToJS(src []byte) js.Value { // // Panics if m is not a function. func WrapCB(parent js.Value, m string) func(args ...interface{}) js.Value { - if parent.Get("m").Type() != js.TypeFunction { - jww.FATAL.Panicf("Function %q is not of type %s", m, js.TypeFunction) + if parent.Get(m).Type() != js.TypeFunction { + // Create the error separate from the print so stack trace is printed + err := errors.Errorf("Function %q is not of type %s", m, js.TypeFunction) + jww.FATAL.Panicf("%+v", err) } return func(args ...interface{}) js.Value {