Skip to content
Snippets Groups Projects
Commit 154ae14a authored by Jono Wenger's avatar Jono Wenger
Browse files

Minor bug fixes

parent 86f55658
No related branches found
No related tags found
1 merge request!60Revert "Fail a test to be sure it works"
......@@ -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")
}
......
......@@ -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 {
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment